MFC se basa en cuadros de diálogo. ¿Cómo hacer que se ejecute minimizado en la bandeja del sistema y muestre la pantalla principal cuando se hace clic en el icono?
NOTIFYICONDATA nid;
Agregue una declaración de función de mensaje, simplemente júntela con muchas otras funciones de la serie afx_msg:
p >
afx_msg void OnNotifyIcon(WPARAM, LPARAM);
2: Modifique el siguiente contenido en cpp:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
Agregue el siguiente yo debajo del párrafo de contenido anterior Definir definición de mensaje
#undefine WM_NOTIFY_ICON WM_USER 101
BEGIN_MESSAGE_MAP(CNotifyIconDlg, CDialog)
//{{AFX_MSG_MAP(CNotifyIconDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_ NOTIFY_ICON, agrega este mapa de mensajes en esta función
/ /}}AFX_MSG_MAP
END_MESSAGE_MAP()
Busque esta función y cámbiela a esta función
void CNotifyIconDlg::OnSysCommand(UINT nID, LPARAM lParam )
{
if ((nID amp; 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
if (nID == SC_MINIMIZE)
{
ShowWindow(SW_HIDE);
ZeroMemory(amp;nid, sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hIcon = AfxGetApp()-gt; LoadIcon(IDR_MAINFRAME);
nid.hWnd = m_hWnd
strcpy(nid.szTip, "Sugerencia; Mensaje");
nid.uCallbackMessage = WM_NOTIFY_ICON;
nid.uCallbackMessage = WM_NOTIFY_ICON;
nid.uCallbackMessage = WM_NOTIFY_ICON.
uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
Shell_NotifyIcon(NIM_ADD, amp;nid);
}
else
{< / p>
CDialog::OnSysCommand(nID, lParam);
}
}
}
En el archivo cpp Agregar la siguiente función al final:
void CNotifyIconDlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
if (lParam == WM_ LBUTTONDOWN || lParam = = WM_RBUTTONDOWN)
{
ShowWindow(SW_SHOW);
}
}
Esta función es compilado por el asistente Builder, genera el marco y agrega Shell_NotifyIcon
BOOL CNotifyIconDlg::DestroyWindow()
{
// TODO: agregue su código dedicado aquí y /o llamar a la clase base
Shell_NotifyIcon(NIM_NotifyIcon(NIM_NIM_NIM_NIM_NIM_NIM_NotifyIcon) NotifyIcon(NIM_DELETE, amp;nid);
return CDialog::DestroyWindow();
}
Lo anterior es la implementación de VC 6.0