Displaying Graphics Example

//Displaying Graphicsb Example//
#include <windows.h>
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("Displaying Graphics"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 700, 300, 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;
const POINT polygon[10] = { 80, 185, 145, 185, 155, 130, 115, 145, 80, 135 };
const POINT bezier[4] = {320, 180, 370, 180, 375, 130, 400, 130};
HBRUSH hbrush=NULL;
HPEN hpen;
switch(msg)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc,50,10,NULL);
SelectObject(hdc,hbrush);
//draws line around window
LineTo(hdc,620,10);
LineTo(hdc,620,240);
LineTo(hdc,50,240);
LineTo(hdc,50,10);
//draws ellipse with default pen and brush
Ellipse(hdc, 80, 30, 170, 90);
SelectObject(hdc, hbrush);
TextOut(hdc,100,95,TEXT("Ellipse"),7);
//creates hbrush with colour green and draws roundrect
hbrush=CreateSolidBrush(RGB(0,255,0));
SelectObject(hdc, hbrush);
RoundRect(hdc, 200, 30, 290, 90, 15, 20);
TextOut(hdc,180,95,TEXT("Rounded rectangle"),17);
//creates hbrush with yellow cross hatch and draws chord
hbrush=CreateHatchBrush(HS_CROSS ,RGB(255,255,0));
SelectObject(hdc, hbrush);
Chord(hdc, 320, 30, 410, 90, 320, 45, 410, 45);
TextOut(hdc,350,95,TEXT("Chord"),5);
//creates hbrush white and draws pie
hbrush=CreateSolidBrush(RGB(255,255,255));
SelectObject(hdc, hbrush);
Pie(hdc, 450,30, 540,90, 320,45,410,45);
TextOut(hdc,485,95,TEXT("Pie"),3);
//creates hbrush with red cross hatch and draws polygon
hbrush=CreateHatchBrush(HS_VERTICAL ,RGB(255,0,0));
SelectObject(hdc, hbrush);
Polygon(hdc, polygon, 5);
TextOut(hdc,100,195,TEXT("Polygon"),7);
//creates hbrush black and draws rectangle
hbrush=CreateSolidBrush(RGB(0,0,0));
SelectObject(hdc, hbrush);
Rectangle(hdc, 200, 130, 280, 180);
TextOut(hdc,210,195,TEXT("Rectangle"),9);
//draws Bezier curve
PolyBezier(hdc, bezier, 4);
TextOut(hdc,340,195,TEXT("Bezier"),6);
//draws 3 lines with 3 different style in 3 different colours
MoveToEx(hdc,450,130,NULL);
hpen=CreatePen(PS_DASH,1,RGB(0, 0, 255));
SelectObject(hdc,hpen);
LineTo(hdc,540,130);
MoveToEx(hdc,450,155,NULL);
hpen=CreatePen(PS_DOT,1,RGB(255, 0, 255));
SelectObject(hdc,hpen);
LineTo(hdc,540,155);
MoveToEx(hdc,450,180,NULL);
hpen=CreatePen(PS_DASHDOTDOT,1,RGB(255, 0, 0));
SelectObject(hdc,hpen);
LineTo(hdc,540,180);
TextOut(hdc,480,195,TEXT("Lines"),5);
EndPaint(hwnd, &ps);
DeleteObject(hbrush);
DeleteObject(hpen);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}