Mega Code Archive

 
Categories / Delphi / Games
 

Buttons in win95 taskbar

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;