VC TRAY ICON

xiaoxiao2021-03-06  41

Added member variables for CMAINFRAME:

Notifyicondata M_Trayicon;

CMenu m_menutray;

Add: in the end of the CMAINFRAME on the end:

m_trayicon.cbsize = sizeof (notifyicondata);

m_trayicon.hicon = (hicon) loadimage (AFXGetApp () -> M_HINSTANCE,

MakeintResource (IDI_TRAYICON), Image_ICON, 16, 16, 0);

m_trayicon.hwnd = m_hwnd;

m_trayicon.uid = maintrayicon;

M_trayicon.uflags = nif_message | NIF_ICON | NIF_TIP;

m_trayicon.ucallbackMessage = WM_TRYICI

Strcpy (m_trayicon.sztip, loadresstring (ids_tooltip);

Shell_Notifyicon (Nim_ADD, & M_TRAYICON);

Add message WM_TRAYICON response function:

ON_MESSAGE (WM_TRAYICON, ONTRAYNOTIFY)

INT CMAINFRAME :: Ontraynotify (WPARAM WPARAM, LPARAM LPARAM)

{

IF (WPARAM! = Maintrayicon)

Return 0L;

IF (m_menutray.m_hmenu == null &&! m_menutray.loadmenu (idR_mainframe))

Return 0;

CMenu * psubmenu = m_menutray.getsubmenu (0);

IF (! psubmenu)

Return 0;

IF (lparam == wm_rbuttonup)

{

:: setmenudefaultItem (psubmenu-> m_hmenu, 0, true);

Cpoint Pos;

GetCursorpos (& POS);

SetForegroundWindow ();

Psubmenu-> TRACKPOPUPMENU (TPM_RightAlign | TPM_LEFTBUTTON

| TPM_RightButton, Pos.x, Pos.y, this, null;

}

ELSE IF (lparam == wm_lbuttondown)

{

ShowWindow;

SetForegroundWindow ();

}

Else IF (lparam == wm_lbuttondblclk)

{

SendMessage (wm_command, psubmenu-> getmenuitemid (0), 0);

}

Return 1L;

}

If you need to shield the window to close the button, you need to add message processing function:

ON_WM_SYSCOMMAND ()

Void CMAINFRAME :: OnSysCommand (uint nid, lparam lparam)

{

IF (NID == SC_CLOSE)

{

ShowWindow (SW_HIDE);

Return;

}

CframeWnd :: OnSysCommand (NID, LPARAM);

}

Call at the window of the window:

Shell_Notifyicon (Nim_Delete, & M_Trayicon);

转载请注明原文地址:https://www.9cbs.com/read-56577.html

New Post(0)