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 125 126 127 128 129 130 131 132
| #include <windows.h>
#define IDM_QUIT 3
#define ID_MONBUTTON 100
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hinst;
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wc;
HMENU hMenu, hSousMenu;
hinst = hinstance;
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(14 + COLOR_BTNFACE);
wc.lpszMenuName = NULL;
wc.lpszClassName = "MaWinClass";
if(!RegisterClass(&wc)) return FALSE;
hSousMenu = CreateMenu();
AppendMenu(hSousMenu, MF_STRING, IDM_QUIT, "Quitter");
hMenu = CreateMenu();
AppendMenu(hMenu,MF_POPUP,(UINT)hSousMenu,"Fichier");
hwnd = CreateWindow("MaWinClass", "Supernet Solutions", WS_OVERLAPPEDWINDOW,
3,3, 900, 500,
NULL, NULL, hinstance, NULL);
if (!hwnd) return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/******************************************************************************/
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hEdit;
static BOOL EditNotChg = TRUE;
static HWND hbtn1;
static HWND hbtn2;
static HWND hbtn3;
static HWND hbtn4;
static HWND hbtn5;
static HWND hbtn6;
static HWND hbtn7;
static HWND hbtn8;
static HWND hbtn9;
static HWND hbtn10;
static HWND hbtn11;
static HWND hbtn12;
static HWND hbtn13;
switch (uMsg)
{
case WM_CREATE:
HFONT hFont;
hEdit = CreateWindow("edit", "Texte",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
40,40, 0, 0, hwnd, NULL, hinst, NULL);
hFont = (HFONT)GetStockObject;/*permet de récupérer des objets initialisés au démarrage de Windows, tel des pinceaux, crayons..*/(ANSI_FIXED_FONT);//changer le police de caractère
SendMessage(hEdit,WM_SETFONT,(UINT)hFont,TRUE);//mêmes paramètres que PostMessage et dans le même ordre//envoie le message directement à la procédure de fenêtre sans passer par la file d'attente
SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN,
MAKELONG(5, 5));//pour mettre ses marges interieures droite et gauche à 5 pixels
hbtn1 = CreateWindow("button", "Nouveau", WS_CHILD | WS_VISIBLE ,
175,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn2 = CreateWindow("button", "Editer", WS_CHILD | WS_VISIBLE ,
275,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn3 = CreateWindow("button", "Enregister", WS_CHILD | WS_VISIBLE ,
375,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn4 = CreateWindow("button", "Supprimer", WS_CHILD | WS_VISIBLE ,
475,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn5 = CreateWindow("button", "Historique", WS_CHILD | WS_VISIBLE ,
575,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn6 = CreateWindow("button", "Quitter", WS_CHILD | WS_VISIBLE ,
675,15, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn7 = CreateWindow("button", "Login", WS_CHILD | WS_VISIBLE ,
75,110, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn8 = CreateWindow("button", "Editer", WS_CHILD | WS_VISIBLE ,
15,210, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn9 = CreateWindow("button", "Rapport", WS_CHILD | WS_VISIBLE ,
15,245, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn10 = CreateWindow("button", "Pointage", WS_CHILD | WS_VISIBLE ,
15,280, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn11 = CreateWindow("button", "Employé", WS_CHILD | WS_VISIBLE ,
15,315, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn12 = CreateWindow("button", "Historique", WS_CHILD | WS_VISIBLE ,
15,350, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
hbtn13 = CreateWindow("button", "Quitter", WS_CHILD | WS_VISIBLE ,
15,385, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
return 0;
case WM_CLOSE:
if(EditNotChg ||
MessageBox(hwnd,"Le texte a été modifié.\r\nEtes vous sûr de \
vouloir fermer l'application ?"
,"Question ?",MB_YESNO | MB_ICONQUESTION ) == IDYES)
DestroyWindow(hwnd);
return 0;
case WM_COMMAND:
if(LOWORD(wParam)== IDM_QUIT) PostMessage(hwnd, WM_CLOSE,0,0);
if(HIWORD(wParam) == EN_CHANGE) EditNotChg = FALSE;
return 0;
case WM_SIZE:
MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
} |
Partager