////checkbox demo
#include <windows.h>
#define ID_BLUE 1
#define ID_GREEN 2
#define ID_RED 3
int red, green,blue;
COLORREF bk_color;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("myWindowClass");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("Check Box Demo"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 700, 350, NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hBrush;
switch(msg) {
case WM_CREATE:
red=0, green=0,blue=0;
int checked;
CreateWindow(TEXT("button"), TEXT("Blue"),WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,200, 60, 70, 30, hwnd, (HMENU) ID_BLUE , NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Green"),WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,270, 60, 70, 30, hwnd, (HMENU) ID_GREEN ,NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Red"),WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,340, 60, 70, 30, hwnd, (HMENU) ID_RED , NULL, NULL);
break;
case WM_COMMAND:
/*responds to button click by setting variable bk_color to value of colour associated with radio button */
if (HIWORD(wParam) == BN_CLICKED) {
switch (LOWORD(wParam)) {
case ID_BLUE:
checked = IsDlgButtonChecked(hwnd,ID_BLUE);
blue=checked*255;
break;
case ID_GREEN:
checked = IsDlgButtonChecked(hwnd,ID_GREEN);
green=checked*255;
break;
case ID_RED:
checked = IsDlgButtonChecked(hwnd,ID_RED);
red=checked*255;
break;
}
InvalidateRect(hwnd, NULL, TRUE);
}
break;
//changes colour of Window background
case WM_PAINT:
RECT theRect;
hdc = BeginPaint(hwnd, &ps);
bk_color=RGB(red,green,blue);
hBrush = CreateSolidBrush(bk_color);
GetClientRect(hwnd, &theRect);
FillRect(hdc, &theRect, hBrush);
EndPaint(hwnd, &ps);
DeleteObject(hBrush);
ReleaseDC(hwnd,hdc);
DeleteDC(hdc);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}