Search code examples
cwindowswinapisystem-tray

what message has been sent after left click the tray icon contextmenu ?(windows api )


i am having a program written using DialogBox to initialize main window.

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow )
{
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN),hWnd, (DLGPROC)**DlgProc**);
    return 0;
}

and in DlgProc

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch (LOWORD(Msg))
    {
        //some code............
        case WM_CLOSE:
            nid.uCallbackMessage=WM_MY_NOTIFY;//自定义的消息名称
        //some code.........
        case WM_MY_NOTIFY:
            //some code here.......
            return TRUE;
        case WM_COMMAND:
            //Cannot receive the tray context menu left click message
            switch (LOWORD (wParam))
            {
            case IDM_TRAY_EXIT:
                SendMessage(hWndDlg,WM_CLOSE,0,0); 
                return TRUE;
            }
            return TRUE;
    }
    return FALSE;
}

Click these menus,nothing happens.

i wanted to click on a menu item and trigger something , as the image above , after I click Item 1 , there's a messagebox poped out.

So,my question is what message can receive left clicking tray icon contextmenu ?


Solution

  • The message should be in the callback of the context menu shown