1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <windows.h>
#define MY_WM_NOTIFYICON WM_USER+1
LRESULT CALLBACK procMainWindow( HWND , UINT, WPARAM, LPARAM );
NOTIFYICONDATA TrayIcon;
int WINAPI WinMain(
HINSTANCE now,
HINSTANCE prev,
LPSTR ligne,
int modeAff
)
{
HWND mainWindow;
MSG message;
WNDCLASS classWindow;
classWindow.style = 0;
classWindow.lpfnWndProc = procMainWindow;
classWindow.cbClsExtra = 0;
classWindow.cbWndExtra = 0;
classWindow.hInstance = now;
classWindow.hIcon = LoadIcon( NULL , IDI_APPLICATION );
classWindow.hCursor = LoadCursor( NULL , IDC_ARROW );
classWindow.hbrBackground = (HBRUSH)(1+ COLOR_BTNFACE );
classWindow.lpszMenuName = NULL;
classWindow.lpszClassName = "classF";
if( !RegisterClass( &classWindow ) )return FALSE;
mainWindow = CreateWindow( "classF" , "ma fenetre" , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT , 400, 300, NULL , NULL , now , NULL);
//mainWindow = CreateDialog( now , NULL , NULL , (DLGPROC) procMainWindow );
ZeroMemory( &TrayIcon , sizeof( NOTIFYICONDATA ) );
TrayIcon.cbSize = sizeof( NOTIFYICONDATA );
TrayIcon.hWnd = mainWindow;
TrayIcon.uID = 0;
TrayIcon.hIcon = LoadIcon( NULL , IDI_WINLOGO );
TrayIcon.uCallbackMessage =MY_WM_NOTIFYICON;
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
strcpy( TrayIcon.szTip , "test tray\0" );
Shell_NotifyIcon( NIM_ADD , &TrayIcon );
ShowWindow( mainWindow , SW_SHOW );
UpdateWindow( mainWindow );
while( GetMessage( &message, NULL, 0,0) )
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
//LRESULT CALLBACK procMainWindow( HWND mainWindow , UINT message , WPARAM wParam , LPARAM lParam )
LRESULT CALLBACK procMainWindow( HWND mainWindow , UINT message , WPARAM wParam , LPARAM lParam )
{
switch( message )
{
case WM_CREATE:
return 0;
case WM_DESTROY:
Shell_NotifyIcon( NIM_DELETE , &TrayIcon );
MessageBox( NULL, TEXT("arret prgm") , TEXT("éà") , MB_OK );
PostQuitMessage(0);
return 0;
// case WM_CLOSE:
// //MessageBox( NULL, TEXT("fermeture fenetre") , TEXT("éà") , MB_OK );
// return 0;
case MY_WM_NOTIFYICON:
if( lParam == WM_LBUTTONDBLCLK )
{
MessageBox( NULL, TEXT("icone") , TEXT("éà") , MB_OK );
}
return 0;
case WM_QUERYENDSESSION:
MessageBox( NULL, TEXT("fin session") , TEXT("éà") , MB_OK );
return FALSE;
default:
return DefWindowProc( mainWindow , message , wParam , lParam );
}
} |
Partager