Posts

Showing posts from 2012

Creating tray application and popup context menu in Windows

If you want to add your application in system tray and popup a context menu #include<windows.h> #include "resource.h" HINSTANCE g_hInstance; const int WM_EX_MESSAGE = (WM_APP + 1); BOOL TrayIcon(HWND hWnd, HICON hIcon, DWORD msg) { NOTIFYICONDATA nid; ZeroMemory(&nid,sizeof(NOTIFYICONDATA)); nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = hWnd; nid.uID = IDI_ICON2; nid.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE; nid.uCallbackMessage = WM_EX_MESSAGE; nid.hIcon = hIcon; lstrcpyn(nid.szTip, __TEXT("This is my tray app!"), 64); return Shell_NotifyIcon(msg,&nid); } void ContextMenu(HWND hwnd) { HMENU hmenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU2)); HMENU hmnuPopup = GetSubMenu(hmenu,0); SetMenuDefaultItem(hmnuPopup,IDOK,FALSE); POINT pt; GetCursorPos(&pt); TrackPopupMenu(hmnuPopup,TPM_LEFTALIGN,pt.x,pt.y,0,hwnd,NULL); DestroyMenu(hmnuPopup); DestroyMenu(hmenu); } BOOL CALLBACK APP_DlgProc(HWND hDlg, UINT uiMsg,