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 "stdafx.h"
#include <shlwapi.h>
#include <windows.h>
#include <shlobj.h>
HWND hwnd;
HWND boutonQuitter;
HINSTANCE hinst;
PWINDOWINFO pwi;
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wc;
hinst = hinstance;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(RGB(240,240,240));//reinterpret_cast<HBRUSH>(GRAY_BRUSH-1);
wc.lpszMenuName = "Menu";
wc.lpszClassName = "MaWinClass";
if(!RegisterClass(&wc)) return FALSE;
pwi = (PWINDOWINFO)malloc(sizeof(WINDOWINFO));
pwi->cbSize = sizeof(WINDOWINFO);
hwnd = CreateWindow("MaWinClass", "essai", WS_OVERLAPPEDWINDOW,
0, 0, 200, 200, NULL, NULL, hinstance, NULL);
if (!hwnd) return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int quit = 0;
PAINTSTRUCT ps;
HDC hdc;
switch (uMsg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd,&ps);
return 0;
case WM_COMMAND:
if( (HWND)lParam == boutonQuitter)
{
quit = MessageBox(hwnd,"Vous voulez réellement Quitter",
"Message",MB_YESNO|MB_ICONQUESTION);
if (quit == IDNO) {return 0; break;}
SendMessage( hwnd, WM_CLOSE, 0, 0L);
return 0;
}
return 0;
case WM_CREATE:
boutonQuitter = CreateWindow("BUTTON","Quitter",WS_CHILD| WS_VISIBLE | BS_DEFPUSHBUTTON | BS_CENTER
, 20, 20
, 70, 90
, hwnd,0,hinst,0);
case WM_CTLCOLORBTN :
if((HWND)lParam == boutonQuitter)
{
HBRUSH brush = CreateSolidBrush(RGB(20,0,0));
return (LRESULT)brush;//(LRESULT);
}
else
return 0;
case WM_DESTROY:
DestroyWindow(hwnd);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
} |