Minimize the window to the lower right corner

             Tray icon drawing functions:

-------------------------------------------------

WINSHELLAPI BOOL WINAPI Shell_NotifyIcon(

DWORD dwMessage,

PNOTIFYICONDATA pnid

);

The first parameter is responsible for delivering messages to the system

  NIM_ADD

  Add an icon to the tray area. At this time, the second parameter lpdata pointed NOTIFYICONDATA structural body hWnd uID members and used to indicate the icon, the icon for later use Shell_NotifyIcon this operation again.

  NIM_DELETE

  To delete an icon tray area. At this second argument NOTIFYICONDATA structure lpdata points in the hWnd member and uID used to mark this icon to be deleted.

  NIM_MODIFY

  Modify a tray icon area. At this time, the second parameter NOTIFYICONDATA lpdata structure pointed to by hWnd and uID members need to be modified for a designated icon.

 

 

The second parameter is a NOTIFYIONDATA structure!

  typedef struct _NOTIFYICONDATA {

  DWORD cbSize; // Size structure

  HWND hWnd; // Handle

  UINT uID;

  UINT uFlags; // This member indicate exactly which other members of the legal data (that is, which members of the work).

  UINT uCallbackMessage; // application-defined message label.

  HICON hIcon;

  TCHAR szTip [64];

  DWORD dwState;

  DWORD dwStateMask;

  TCHAR szInfo [256];

  union {

  UINT uTimeout;

  UINT uVersion;

  };

================================================

          Specific usage

================================================

1. define (at the beginning of the file can be defined in the header) a message marked

#define MYWM_NOTIFYICON WM_USER+5

 

2. button response message

void CMyPlayerDlg::CreateNotifyIcon()

{

 NOTIFYICONDATA nd;

// assignment -----

 nd.cbSize = sizeof(NOTIFYICONDATA);

 nd.hWnd = m_hWnd;

 nd.uID = IDI_ICON;

 nd.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;

 nd.uCallbackMessage = MYWM_NOTIFYICON; // Message Flag

 nd.hIcon = m_hIcon;

 strcpy (nd.szTip, "Star melody");

 Shell_NotifyIcon(NIM_ADD, &nd);

}

 

3.OnInitDialog () function call CreateNotifyIcon ()

BOOL CMyPlayerDlg::OnInitDialog()

{

     ....

 

  CreateNotifyIcon()

    ....

}

 

 

4. Add button in response to a hidden window message

void CMyPlayerDlg::OnBtnHide()

{

 // TODO: Add your control notification handler code here

 ShowWindow(SW_HIDE);

}

 

==============================================================

                 Respond to mouse clicks tray icon message

==============================================================

5. Add message functions in the header files

//{{AFX_MSG(CMyPlayerDlg)

 afx_msg void OnNotifyIcon(WPARAM wParam, LPARAM lParam);

//}}AFX_MSG

 

6. Add the message map in the source file

BEGIN_MESSAGE_MAP(CMyPlayerDlg, CDialog)

 //{{AFX_MSG_MAP(CMyPlayerDlg)

 ON_MESSAGE(MYWM_NOTIFYICON,OnNotifyIcon)

 //}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

7. Add the contents of specific message response function

void CMyPlayerDlg::OnNotifyIcon(WPARAM wParam, LPARAM lParam)

{

 if (lParam == WM_LBUTTONDBLCLK)

 {

  UINT MODE;

  ? MODE = IsWindowVisible () SW_HIDE: SW_SHOW; // determine whether the window display

  ShowWindow(MODE);

 }

 

}

 

Guess you like

Origin www.cnblogs.com/blogpro/p/11426923.html