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
| #include <windows.h>
#include <stdio.h>
#define IDM_NOUVELLEFENETRE 101
HINSTANCE hinst;
LRESULT CALLBACK ProcedureFenetre2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
break;
case WM_COMMAND:
break;
case WM_DESTROY:
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI Fenetre2(HWND hwnd_parent)
{
HWND hwnd;
MSG messages;
static WNDCLASSEX wincl;
static unsigned int classe_deja_enregistree=0; /* 'static' pour ne pas enregistrer la classe plusieurs fois en cas d'ouvertures successives de la fenêtre */
if (!classe_deja_enregistree)
{
classe_deja_enregistree=1;
wincl.hInstance = hinst;
wincl.lpszClassName = "ClasseFenetre2";
wincl.lpfnWndProc = ProcedureFenetre2;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl)) return 0;
}
hwnd = CreateWindowEx (0,"ClasseFenetre2","Fenetre 2",WS_BORDER | WS_CAPTION | WS_SYSMENU,150,150,900,500,hwnd_parent,NULL,hinst,NULL);
ShowWindow (hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK ProcedureFenetrePrincipale(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_NOUVELLEFENETRE:
(void)Fenetre2(hwnd); /* Passage en paramètre du HWND de la fenêtre parent */
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument,int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
HMENU hMenu;
hinst=hThisInstance;
hMenu = CreateMenu();
AppendMenu(hMenu, MF_STRING, IDM_NOUVELLEFENETRE, "Ouverture fenetre 2");
wincl.hInstance = hinst;
wincl.lpszClassName = "ClassFenetrePrincipale";
wincl.lpfnWndProc = ProcedureFenetrePrincipale;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl)) return 0;
hwnd = CreateWindowEx (0,"ClassFenetrePrincipale","Fenetre principale",WS_OVERLAPPEDWINDOW,50,50,900,500,HWND_DESKTOP,hMenu,hinst,NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
} |
Partager