Code:
#include <windows.h>
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT Ps;
HPEN hPen1;
//HBRUSH hBrush;
//HFONT hFont;
long lfHeight=30;
RECT rect;
static bool isEllipse = true;
static int thickness = 10;
static int red=200;
static int green=40;
static int blue=60;
static int die_num1 = 1;
static int die_num2 = 1;
switch(msg)
{
case WM_PAINT:
hDC=BeginPaint(hwnd,&Ps);
// pens are needed to draw things made with lines
hPen1 =CreatePen(PS_SOLID, thickness, RGB(red,green,blue));
//hBrush = CreateSolidBrush(RGB(255,0,0));
//hFont = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
SelectObject(hDC, hPen1);
//SelectObject(hDC, hBrush);
//SelectObject(hDC, hFont);
rect.top=520;
rect.bottom=665;
rect.left=125;
rect.right=1025;
//DrawText(hDC,L"Art by Dr. Thomas Fernandez", -1,&rect, DT_WORDBREAK);
/*for(int i=0;i<500;i=i+10)
{
DrawTwoColoredLine(hDC,0,i,500,500,RGB(0,255,i/2),RGB(255,0,i/2));
}
//SelectObject(hDC, hPen);
if(isEllipse)
{
Ellipse(hDC, 520, 22, 750, 125);
}
else
{
Rectangle(hDC, 520, 22, 750, 125);
}
//rCircle(hDC,233,230,210,25,25,250);
//rCircle(hDC,233,230,140,250,25,250);
//DeleteObject(hFont);
//DeleteObject(hBrush);
DeleteObject(hPen1);
EndPaint(hwnd,&Ps);
break;*/
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_CHAR:
if(wParam=='r')
{
red=rand()%256;
green=rand()%256;
blue=rand()%256;
InvalidateRect(hwnd,NULL,true);
}
else if(wParam==' ')
{
die_num1=rand()%6+1;
die_num2=rand()%6+1;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
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 = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}