Code:
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
g_hwnd = FindWindow(szClassName,szTitleName);
MSG messages;
WNDCLASSEX wincl;
_hInstance = hThisInstance;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.style = CS_DBLCLKS;
wincl.lpfnWndProc = WindowProcedure;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hInstance = hThisInstance;
wincl.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_MYICON));
wincl.hIconSm = LoadImage(NULL, MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.hbrBackground = (HBRUSH)16;
wincl.lpszMenuName = NULL;
wincl.lpszClassName = szClassName;
g_hwnd = CreateWindowEx (
0,
szClassName,
szTitleName,
WS_DLGFRAME,
160,
120,
310,
250,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
NOTIFYICONDATA nid;
switch (message) /* handle the messages */
{
case WM_CREATE:
{
ZeroMemory(&nid,sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd;
nid.uID = 0;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;
nid.uCallbackMessage = WM_USER;
nid.hIcon = LoadIcon(_hInstance,MAKEINTRESOURCE(IDI_MYICON));
if (g_hwnd)
{
_CopyOfapp++;
sprintf(nid.szTip, "%s%d", "app (copy ", _CopyOfapp,);
}
else
{
lstrcpy(nid.szTip,"app");
}
Shell_NotifyIcon(NIM_ADD,&nid);
}
break;
case WM_DESTROY:
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;
}