Link to home
Start Free TrialLog in
Avatar of lifeson
lifeson

asked on

icon communicating with application

How do i make an icon at the taskbar communicate with my applicantion. For example: when i right click on the icon i want to make a popup menu appears.
Avatar of ronit051397
ronit051397

You mean in the system tray:
Place 3 buttons for Add, Delete and modify the Icon in the TaskBar.
        Place a Popup menu with some items and write the following code:

        uses ShellAPI;
        .
        var IconData :TNotifyIconData;
        ..
        procedure TForm1.bbAddClick(Sender: TObject);
        begin
          with IconData DO
          begin
            cbSize := SizeOf(IconData);
            uFlags := NIF_ICON OR NIF_TIP OR NIF_MESSAGE;
            uID := 0;
            Wnd := Handle;
            szTip := 'This is my Application'+#0;
            hIcon := Application.Icon.Handle;
            uCallBackMessage := WM_USER+$10;
          end;
          if Shell_NotifyIcon(NIM_ADD,@IconData) then MessageBeep(0);
        end;

        procedure TForm1.bbModifyClick(Sender: TObject);
        begin
          with IconData do
          begin
            szTip := 'app is modified'+#0;
            hIcon := LoadIcon(0,IDI_ASTERISK);
          end;
          if Shell_NotifyIcon(NIM_MODIFY,@IconData) then MessageBeep(0);
        end;

        procedure TForm1.bbDeleteClick(Sender: TObject);
        begin
          if Shell_NotifyIcon(NIM_DELETE,@IconData) then MessageBeep(0);
        end;

        procedure TForm1.WndProc(var MyMessage: TMessage);
        var CursorPos: TPoint;
        begin
          IF MyMessage.Msg = WM_USER+$10 THEN
          CASE MyMessage.LParam OF
          WM_RBUTTONUP :
          BEGIN
            GetCursorPos(CursorPos);
            PopupMenu1.Popup(CursorPos.X, CursorPos.Y);
          END;
          WM_LBUTTONDBLCLK :
          ShowMessage('This is my application');
          END;
          INHERITED WndProc(MyMessage);
        end;
Avatar of lifeson

ASKER

This answer appears in other qustion already. i made this but when i click at the icon, nothing heappens. Please, i want more dettails about it.
make sure to write

TForm1= ....
   PROCEDURE WndProc(var MyMessage: TMessage); OVERRIDE; //IMPORTANT... if you don't override, nothing will happen...

Did that solve the problem?
ASKER CERTIFIED SOLUTION
Avatar of Matvey
Matvey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As Holger says, Did you write override?