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
| HWND OpenWindow(LPSTR Titre)
{
HWND HwndFenetre;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInst;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpszClassName = "Fenetre";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) CallBackWindows;
RegisterClass(&wc);
HwndFenetre = CreateWindow("Fenetre", Titre, WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, g_hInst, 0);
ShowWindow(HwndFenetre, SW_SHOW);
UpdateWindow(HwndFenetre);
return HwndFenetre;
}
// using _stdcall the winmain entry
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR line, int CmdShow)
{
g_hInst = hInst;
MSG msg;
FenetrePrincipale = OpenWindow("Coucou");
FenetreSecondaire = OpenWindow("Coucou2");
while(GetMessage(&msg, 0, 0, 0))
{
if(msg.message == WM_CLOSE || msg.wParam == WM_CLOSE || msg.lParam == WM_CLOSE)
{
MessageBox(0, "Coucou", "Je me ferme",1);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
// function def's?
LRESULT APIENTRY CallBackWindows(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
MessageBox(0, "Hello", "Welcome Message",1);
SendMessage(hwnd, WM_DESTROY, 0, 0);
break;
case WM_DESTROY:
DestroyWindow(hwnd);
if(hwnd == FenetrePrincipale)
{
PostQuitMessage(0);// destroy code out of memory
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
} |