DelphiFAQ Home Search:

Buttons in Win95 taskbar

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The ShellAPI provides the function Shell_NotifyIcon to add or remove a button.
You can pass a user defined message (called WM_TBBUTTON in the sample code) which will be sent to your form each time your new button in the task bar gets a mouse event.

Here are the code snippets to do just that!

uses
  ShellAPI;

const
  WM_TBBUTTON = WM_USER + 100;

// .. form definition..
procedure TForm1.IconCallBackMessage( var Mess : TMessage );
  message WM_TBBUTTON;

// .. implementation part..
procedure TForm1.FormCreate(Sender: TObject);
var
  NotifyID : TNotifyIconData;
begin
  with NotifyID do
  begin
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    uCallbackMessage := WM_TBBUTTON;
    hIcon := Application.Icon.Handle;
    szTip := 'This is the hint!';
  end;
  Shell_NotifyIcon(NIM_ADD, @NotifyID);
end;

procedure TForm1.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  NotifyID : TNotifyIconData;
begin
  with NotifyID do
  begin
    // setting the record is probably
    // not needed for deleting
    cbSize := SizeOf(TNotifyIconData);
    Wnd := Form1.Handle;
    uID := 1;
    uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
    uCallbackMessage := WM_TBBUTTON;
    hIcon := Application.Icon.Handle;
    szTip := 'This is the hint!';
  end;
  Shell_NotifyIcon(NIM_DELETE, @NotifyID);
end;

procedure TForm1.IconCallBackMessage(var Mess : TMessage);
begin
  // do whatever you wish here.
  // for example popup up a menu on a right click.
  case Mess.lParam of
    WM_LBUTTONDBLCLK  : ShowMessage('Left Double Click');
    WM_LBUTTONDOWN    : ShowMessage('Left Down');
    WM_LBUTTONUP      : ShowMessage('Left Up');
    WM_MBUTTONDBLCLK  : ShowMessage('M Dbl');
    WM_MBUTTONDOWN    : ShowMessage('M D');
    WM_MBUTTONUP      : ShowMessage('M U');
    WM_MOUSEMOVE      : ShowMessage('Mouse movement');
    WM_MOUSEWHEEL     : ShowMessage('Mouse wheel');
    WM_RBUTTONDBLCLK  : ShowMessage('r dbl');
    WM_RBUTTONDOWN    : ShowMessage('r down');
    WM_RBUTTONUP      : ShowMessage('r up');
  end;
end;

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: