Magia!
codice:
#include <windows.h>
#include "resource.h"
HMENU Menu;
INT_PTR CALLBACK dgproc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == WM_USER + 1100)
{
if (lParam == WM_RBUTTONDOWN)
{
POINT Position;
SetForegroundWindow(hWnd);
GetCursorPos(&Position);
TrackPopupMenuEx(Menu,GetSystemMetrics(SM_MENUDROPALIGNMENT),Position.x,Position.y,hWnd,NULL);
}
}
return 0;
}
int __stdcall WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
HWND hWnd = CreateDialog(hInstance,MAKEINTRESOURCE(ID_DIALOG),GetDesktopWindow(),dgproc);
Menu = GetSubMenu(LoadMenu(hInstance,MAKEINTRESOURCE(ID_MENU)),0);
NOTIFYICONDATA ref;
memset(&ref,0,sizeof(ref));
ref.cbSize = sizeof(NOTIFYICONDATA);
ref.uID = 10182;
ref.uFlags = NIF_INFO|NIF_ICON|NIF_MESSAGE;
ref.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDC_ARROW));
ref.dwInfoFlags = NIIF_ERROR;
ref.hWnd = hWnd;
ref.uVersion = NOTIFYICON_VERSION;
ref.uCallbackMessage = WM_USER + 1100;
strcpy_s(ref.szInfo,"Prova messaggio");
strcpy_s(ref.szInfoTitle,"Prova messaggio");
strcpy_s(ref.szTip,"Prova messaggio!");
Shell_NotifyIcon(NIM_ADD,&ref);
BOOL bRet;
MSG msg;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
return 1;
}
else if (!IsWindow(hWnd) || !IsDialogMessage(hWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
ma soprattutto nel file .rc
codice:
ID_MENU MENU
BEGIN
POPUP "Test"
BEGIN
MENUITEM "Test1", ID_TEST_TEST1
MENUITEM "Test2", ID_TEST_TEST2
MENUITEM "Test3", ID_TEST_TEST3
END
END
per rendere meglio l'idea agevolo screenshot.