#include //déclarations de variables LPSTR lpszAppName="Ma première fenêtre Windows avec son icône"; HINSTANCE hInst; HWND hWnd; //Prototypes de fonctions LONG WINAPI WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); //Fonctions int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASS cls; // Enregistrer la classe fenêtre de l'application principale. cls.hInstance = hInstance; cls.lpszMenuName = lpszAppName; cls.lpszClassName = lpszAppName; cls.hIcon = LoadIcon(hInstance,"MAINICON"); cls.hCursor = LoadCursor(NULL,IDC_ARROW); cls.hbrBackground =(HBRUSH)(COLOR_WINDOW+1); cls.style = CS_VREDRAW | CS_HREDRAW; cls.lpfnWndProc = (WNDPROC)WndProc; cls.cbWndExtra = 0; cls.cbClsExtra = 0; if ( !RegisterClass( &cls ) ) return( FALSE ); hInst = hInstance; // créer l'application principale hWnd = CreateWindow (lpszAppName, lpszAppName, WS_OVERLAPPEDWINDOW, 50, 50, 640, 470, NULL, NULL, hInst, NULL ); if ( !hWnd ) return( FALSE ); ShowWindow( hWnd, nCmdShow ); UpdateWindow( hWnd ); while( GetMessage( &msg, NULL, 0, 0) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return( msg.wParam ); } LONG WINAPI WndProc( HWND hWnd, UINT uMsg, WPARAM wParam , LPARAM lParam ) { switch(uMsg) { case WM_CLOSE : { DestroyWindow( hWnd ); }; break; case WM_DESTROY : { PostQuitMessage(0); }; break; case WM_QUERYENDSESSION : { DestroyWindow( hWnd ); }; break; default : return DefWindowProc( hWnd, uMsg, wParam, lParam ); }; return 0; }