Download: [link]
Size: 10KB

Project Start: 2007

Language(s):

Union Jack

In Windows Programming, we were to create a Three Man's Morris game over the course of the class with goals to complete each day. Being chronicly ahead of schedule, I was given a few extra assignments to keep me busy. One of them was to make a flag using pens, brushes and circles. The Union Jack was an easy choice and a quick code.

Provided Code:

void OnPaint(HWND hWnd)
{

PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hWnd, &ps);

// background yaaaaaaay
RECT rClient;
GetClientRect(hWnd, &rClient);
HBRUSH fill = CreateSolidBrush(RGB(50, 50, 200));
FillRect(hdc, &rClient, fill );
DeleteObject(fill);

HPEN whitelines = CreatePen(1, 35, RGB(255, 255, 255));
HPEN oldpen = (HPEN)SelectObject(hdc, whitelines);

MoveToEx(hdc, 0, 0, NULL);
LineTo(hdc, 450, 300);
MoveToEx(hdc, 450, 0, NULL);
LineTo(hdc, 0, 300);
MoveToEx(hdc, 0, 150, NULL);
LineTo(hdc, 450, 150);
MoveToEx(hdc, 225, 0, NULL);
LineTo(hdc, 225, 350);

SelectObject(hdc, oldpen);
DeleteObject(whitelines);

HPEN redlines = CreatePen(1, 20, RGB(255, 0, 0));
oldpen = (HPEN)SelectObject(hdc, redlines);

MoveToEx(hdc, 0, 0, NULL);
LineTo(hdc, 450, 300);
MoveToEx(hdc, 450, 0, NULL);
LineTo(hdc, 0, 300);
MoveToEx(hdc, 0, 150, NULL);
LineTo(hdc, 450, 150);
MoveToEx(hdc, 225, 0, NULL);
LineTo(hdc, 225, 350); SelectObject(hdc, oldpen);
DeleteObject(redlines);

EndPaint(hWnd, &ps);
}