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
| #include <windows.h>
LPSTR winNom = "programme test";
HWND hand;
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
void Menu (char * lpszCaption);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
MSG uMsg;
WNDCLASS cls; // definition de la classe de ma fenetre
cls.hInstance = hInstance; // handler de l'instance qui appel la fenetre
cls.lpszMenuName = "test"; // nom du menu de la fenetre
cls.lpszClassName = winNom ; // nom de la classe fenetre
cls.hIcon = LoadIcon(hInstance,"smiley"); // handler sur un icon
cls.hCursor = LoadCursor(NULL,IDC_ARROW); // handler sur un curseur
cls.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
cls.style = CS_VREDRAW|CS_HREDRAW;
cls.lpfnWndProc=(WNDPROC)WndProc; // pointeur sur la fonction de gestion des messages
if (!RegisterClass(&cls))
return (FALSE);
hand = CreateWindow(winNom,winNom,WS_OVERLAPPEDWINDOW,50,50,200,200,NULL,NULL,hInstance,NULL);
ShowWindow(hand,SW_SHOW);
UpdateWindow (hand);
while (GetMessage(&uMsg,NULL,0,0)){
TranslateMessage(&uMsg);
DispatchMessage (&uMsg);
}
return (uMsg.wParam);
}
void Menu (char * lpszCaption){
MessageBox(hand,lpszCaption,"message box",MB_OK);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
switch (uMsg) {
case WM_COMMAND :
if (LOWORD (wParam) == 100)
Menu ("hello world");
else
DefWindowProc(hWnd, uMsg, wParam, lParam);
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default : DefWindowProc(hWnd, uMsg,wParam, lParam);
}
return 0;
} |
Partager