정보 보관 ver1.0

TrayIcon(트레이 아이콘) & 사용자 정의 메세지 핸들러

James Wetzel 2011. 11. 17. 13:58

NOTIFYICONDATA


typedef struct _NOTIFYICONDATA { 
    DWORD cbSize; 
    HWND hWnd; 
    UINT uID; 
    UINT uFlags; 
    UINT uCallbackMessage; 
    HICON hIcon; 
    char szTip[64]; 
} NOTIFYICONDATA, *PNOTIFYICONDATA; 
 

Contains information that the system needs to process taskbar status area messages.

cbSize
Size of this structure, in bytes.
hWnd
Handle to the window that will receive notification messages associated with an icon in the taskbar status area.
uID
Application-defined identifier of the taskbar icon.
uFlags
Array of flags that indicate which of the other members contain valid data. This member can be a combination of the following:
NIF_ICON The hIcon member is valid.
NIF_MESSAGE The uCallbackMessage member is valid.
NIF_TIP The szTip member is valid.
uCallbackMessage
Application-defined message identifier. The system uses this identifier for notification messages that it sends to the window identified in hWnd. These notifications are sent when a mouse event occurs in the bounding rectangle of the icon.
hIcon
Handle to the icon to add, modify, or delete.
szTip
Tooltip text to display for the icon. 

Shell_NotifyIcon


WINSHELLAPI BOOL WINAPI Shell_NotifyIcon(
    DWORD dwMessage, 
    PNOTIFYICONDATA pnid
);	

Sends a message to the system to add, modify, or delete an icon from the taskbar status area.

  • Returns nonzero if successful, or zero otherwise.
dwMessage
Message value to send. This parameter can be one of these values:
NIM_ADD Adds an icon to the status area.
NIM_DELETE Deletes an icon from the status area.
NIM_MODIFY Modifies an icon in the status area.
pnid
Address of a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage.


사용자 정의 메세지&핸들러

상황에 따라서는 시스템에서 제공하는 메세지가 아닌 사용자 정의 메세지가 필요한 경우가 있다.
사용자 정의 메세지 구현 절차는 다음과 같다.
1.  사용자 메세지 정의(사용자가 이런 메세지를 사용하겠다고 시스템에게 알려주는 것이다.)
    #define WM_MYMESSAGE (WM_USER + 100)

2. 사용자 정의 메세지 맵 생성
BEGIN_MESSAGE_MAP(CMyWnd, CMyParentWndClass)
ON_MESSAGE(WM_MYMESSAGE, OnMyMessage)
END_MESSAGE_MAP()

3. 사용자 정의 메세지 구현
 
LRESULT CMyWnd::OnMyMessage(WPARAM WParam, LPARAM LParam)
{
 
return (LRESULT)0;
 
}

보다 자세한 내용은 샘플 파일을 참고 하기 바란다.

728x90
반응형