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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
//***********************déclaration des bibliothèques**************//
#include <math.h>
#include <stdio.h>
#include<windows.h>
#define premier_menu 9001 //*******chaque élément du menu doit correspondre à un define*****//
#define second_menu 9002
#define troisieme_menu 9003
//************************définition de variable********************//
LPSTR lpszAppName="programme hexa";
HINSTANCE hInst;
HWND fenetre,f_menu;
HMENU menu;
//******************************prototypes des fonctions*************//
LONG WINAPI WndProc(HWND fenetre,UINT uMsg,WPARAM wParam,LPARAM lParam);
//**************************ouverture du programme principale********//
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
MSG msg;
WNDCLASS cls;
//********enregistrer la classe fenetre de l'application principale****//
cls.hInstance=hInstance;
cls.lpszMenuName=lpszAppName;
cls.lpszClassName=lpszAppName;
cls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
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 la fenetre principale + bouton *********************//
fenetre=CreateWindow(lpszAppName,lpszAppName,WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInst,NULL);
//****controle sur la création des fenetres + boucle des messages******//
if(!fenetre)
return(FALSE);
ShowWindow(fenetre,nCmdShow);
UpdateWindow(fenetre);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
//**********fonction WndProc (coeur du programme)*********************//
LONG WINAPI WndProc(HWND fenetre,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case premier_menu:
PostMessage(fenetre, WM_CLOSE, 0, 0);
break;
case second_menu:
{
f_menu=CreateWindow("EDIT","Nbre de filaments :",WS_VISIBLE|WS_OVERLAPPEDWINDOW,100,100,150,50,fenetre, NULL,GetModuleHandle(NULL), NULL);
SetWindowText(f_menu,"toto");
};break;
};
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu,MF_STRING,premier_menu, "&quitter"); //crée un menu fichier avec une rubrique quitter//
AppendMenu(hSubMenu, MF_STRING, troisieme_menu, "&pouet");
AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,"&fichier");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, second_menu, "&Go");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&divers");
SetMenu(fenetre, hMenu);
}; break;
case WM_CLOSE:
{
DestroyWindow(fenetre);
};
break;
case WM_DESTROY:
{
PostQuitMessage(0);
};
break;
case WM_QUERYENDSESSION:
{
DestroyWindow(fenetre);
};
break;
default:
return DefWindowProc(fenetre,uMsg,wParam,lParam);
};
return 0;
} |
Partager