Code:
#include <windows.h>
#include "main.h"
/* Make the class name into a global variable */
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
MinimizeToTray();
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static NOTIFYICONDATA NData;
/*POINT pt;
HMENU hPopupMenu = CreatePopupMenu();
AppendMenu(hPopupMenu, MF_STRING, 1000, "Restore");
AppendMenu(hPopupMenu, MF_STRING, 1001, "Minimize");
AppendMenu(hPopupMenu, MF_STRING, 1002, "Close Program");*/
switch (message) /* handle the messages */
{
case WM_CREATE:
break;
case WM_SIZE:{
switch (LOWORD(wParam)){
case SIZE_MINIMIZED:{
ShowWindow(hwnd,SW_HIDE);
break;
}
default:
break;
}
break;
}
case WM_USER_SHELLNOTIFY:{
if (wParam == ID_TRAYICON){
UINT uMouseMsg = (UINT) lParam;
switch (uMouseMsg){
case WM_LBUTTONDBLCLK:
RestoreFromTray();
EditBalloonText(hwnd,ID_TRAYICON,"Fofa","Cofa",10000,NIIF_INFO);
break;
/*case WM_MBUTTONDOWN:
GetCursorPos(&pt);
TrackPopupMenu(hPopupMenu, TPM_RIGHTALIGN, pt.x, pt.y, 0, hwnd, NULL);
break;*/
default:
break;
}
}
return 0;}
case WM_DESTROY:
DeleteTrayIcon();
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void MinimizeToTray(void){
NOTIFYICONDATA nid;
TCHAR tooltip[] = TEXT("Tray Icon");
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = ID_TRAYICON;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_USER_SHELLNOTIFY;
nid.szInfo;
nid.hIcon = LoadIcon(GetModuleHandle(NULL), (const char*)IDI_ICON1);
lstrcpyn(nid.szTip, tooltip, sizeof(tooltip));
Shell_NotifyIcon(NIM_ADD, &nid); // add our icon to the system tray
}
void DeleteTrayIcon(void){
NOTIFYICONDATA nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = ID_TRAYICON;
Shell_NotifyIcon(NIM_DELETE, &nid); // remove tray icon when restored
}
void RestoreFromTray(void){
ShowWindow(hwnd, SW_RESTORE); // unhide main window
SetForegroundWindow(hwnd); // bring main window to foreground
}
BOOL EditBalloonText(HWND hwnd,UINT uID,PTSTR szBalloonTitle,PTSTR szBalloonMsg,UINT nTimeOut,DWORD messageType){
NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = hwnd;
tnid.uID = uID;
tnid.uFlags = NIF_INFO;
if (szBalloonMsg){
strncpy(tnid.szInfo, szBalloonMsg, sizeof(tnid.szInfo));
}
else{
tnid.szInfo[0] = 0;
}
tnid.uTimeout=nTimeOut;
strcpy(tnid.szInfoTitle,szBalloonTitle);
tnid.dwInfoFlags=messageType;
return Shell_NotifyIcon(NIM_MODIFY, &tnid);
}
And I would like to add a checkbox to my tray icon menu.