c ++ under win32 window is minimized and the reduction to the tray

  Win32 console framework is a template created with visual studio, then add their own and to minimize the reduction of the code.

  The need for additional header files included:

#include <shellapi.h>
#include <WinUser.h>

  It is to create an icon in the tray, hide the main window.

  Creating tray icon:

void ToTray(HWND hWnd)
{
    NOTIFYICONDATA nid;
    nid.cbSize = (DWORD)sizeof(NOTIFYICONDATA);
    nid.hWnd = hWnd;
    nid.uID = IDR_MAINFRAME;
    nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    nid.uCallbackMessage = WM_TO_TRAY; // custom message processing tray icon events 
    nid.hIcon = LoadIcon (GetModuleHandle ( 0 ), the MAKEINTRESOURCE (IDI_SMALL));
    wcscpy_s (nid.szTip, _T ( "custom program name " )); // text that is displayed when the mouse on the tray icon 
    Shell_NotifyIcon (NIM_ADD, & NID); // add an icon in the tray area 
}

  To destroy tray icon when you close the software, or the mouse over will disappear:

void DeleteTray(HWND hWnd)
{
    NOTIFYICONDATA nid;
    nid.cbSize = (DWORD)sizeof(NOTIFYICONDATA);
    nid.hWnd = hWnd;
    nid.uID = IDR_MAINFRAME;
    nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    nid.uCallbackMessage = WM_TO_TRAY; // message name of the custom processing tray icon events 
    nid.hIcon = LoadIcon (GetModuleHandle ( 0 ), the MAKEINTRESOURCE (IDI_SMALL));
    wcscpy_s (nid.szTip, _T ( "custom program name " )); text that is displayed when the mouse on the tray icon // 
    Shell_NotifyIcon (NIM_DELETE, & NID); // delete icon in the tray 
}

  Minimize the time to hide window minimize the need to capture the news, the news in dealing with WM_SIZE, wParam parameter is SIZE_MINIMIZED.

  Destruction tray when the window is closed:

 

 

   Double-click the tray icon to restore the window:

 

 

 SetForegroundWindow (hWnd); This function is to allow the window to the front.

Guess you like

Origin www.cnblogs.com/yzhuang/p/11806823.html