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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#include <windows.h>
#define ID_B_SECOND 101
#define ID_B_SOMMAIRE 102
#define ID_B_QUITTER 103
HINSTANCE instance;
HWND fenetrePrincipale, fenetreSecondaire;
LRESULT CALLBACK procedureFenetrePrincipale(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK procedureFenetreSecondaire(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance,
LPSTR lignesDeCommande, int modeDAffichage)
{
// Page Principale
MSG message;
WNDCLASS classeFenetre;
classeFenetre.style = 0;
classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
classeFenetre.cbClsExtra = 0;
classeFenetre.cbWndExtra = 0;
classeFenetre.hInstance = NULL;
classeFenetre.hIcon = LoadIcon(NULL, IDI_APPLICATION);
classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
classeFenetre.lpszMenuName = NULL;
classeFenetre.lpszClassName = "PagePrincipale";
// Addition
WNDCLASS classeFenetreSecondaire;
classeFenetreSecondaire.style = 0;
classeFenetreSecondaire.lpfnWndProc = procedureFenetreSecondaire;
classeFenetreSecondaire.cbClsExtra = 0;
classeFenetreSecondaire.cbWndExtra = 0;
classeFenetreSecondaire.hInstance = NULL;
classeFenetreSecondaire.hIcon = LoadIcon(NULL, IDI_APPLICATION);
classeFenetreSecondaire.hCursor = LoadCursor(NULL, IDC_ARROW);
classeFenetreSecondaire.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
classeFenetreSecondaire.lpszMenuName = NULL;
classeFenetreSecondaire.lpszClassName = "PageSecondaire";
if(!RegisterClass(&classeFenetreSecondaire)) return FALSE;
fenetreSecondaire = CreateWindow("PageSecondaire", "Page Secondaire !", WS_OVERLAPPEDWINDOW || WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 115,
fenetrePrincipale, NULL, cetteInstance, NULL);
if(!RegisterClass(&classeFenetre)) return FALSE;
fenetrePrincipale = CreateWindow("PagePrincipale", "Page Principale !", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 115,
NULL, NULL, cetteInstance, NULL);
if (!fenetrePrincipale) return FALSE;
ShowWindow(fenetrePrincipale, modeDAffichage);
UpdateWindow(fenetrePrincipale);
while (GetMessage(&message, NULL, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK procedureFenetrePrincipale(HWND fenetrePrincipale, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND boutons[2] = {NULL};
switch (message)
{
case WM_CREATE:
boutons[0] = CreateWindow("BUTTON", "Secondaire", WS_CHILD | WS_VISIBLE,
5, 5, 383, 30, fenetrePrincipale, (HMENU)ID_B_SECOND, instance, NULL);
boutons[1] = CreateWindow("BUTTON", "Quitter", WS_CHILD | WS_VISIBLE,
5, 45, 383, 30, fenetrePrincipale, (HMENU)ID_B_QUITTER, instance, NULL);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_B_SECOND:
ShowWindow(fenetreSecondaire, SW_SHOW);
UpdateWindow(fenetreSecondaire);
break;
case ID_B_QUITTER:
SendMessage(fenetrePrincipale, WM_DESTROY, 0, 0);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(fenetrePrincipale, message, wParam, lParam);
}
}
// Addition
LRESULT CALLBACK procedureFenetreSecondaire(HWND fenetreSecondaire, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND boutons[2] = {NULL};
switch (message)
{
case WM_CREATE:
switch(LOWORD(wParam))
{
boutons[0] = CreateWindow("BUTTON", "Sommaire", WS_CHILD | WS_VISIBLE,
5, 5, 383, 30, fenetreSecondaire, (HMENU)ID_B_SOMMAIRE, instance, NULL);
boutons[1] = CreateWindow("BUTTON", "Quitter", WS_CHILD | WS_VISIBLE,
5, 45, 383, 30, fenetreSecondaire, (HMENU)ID_B_QUITTER, instance, NULL);
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_B_SOMMAIRE:
ShowWindow(fenetrePrincipale, SW_SHOW);
UpdateWindow(fenetrePrincipale);
ShowWindow(fenetreSecondaire, SW_HIDE);
UpdateWindow(fenetreSecondaire);
break;
case ID_B_QUITTER:
PostQuitMessage(0);
break;
}
return 0;
default:
return DefWindowProc(fenetreSecondaire, message, wParam, lParam);
}
} |
Partager