• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 #ifndef WIN32_LEAN_AND_MEAN
7 #define WIN32_LEAN_AND_MEAN
8 #endif
9 #include <windows.h>
10 
11 #define TITLE "WinMain"
12 #define WIDTH 250
13 #define HEIGHT 250
14 
15 void Draw(HDC hdc);
16 
WindowProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)17 LRESULT CALLBACK WindowProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
18 {
19   PAINTSTRUCT ps;
20   switch (Msg)
21   {
22   case WM_PAINT:
23     BeginPaint(hWnd,&ps);
24     Draw(ps.hdc);
25     EndPaint(hWnd,&ps);
26     break;
27   case WM_DESTROY:
28     PostQuitMessage(0);
29     break;
30   default:
31     return DefWindowProc(hWnd,Msg,wParam,lParam);
32   }
33   return 0;
34 }
35 
36 char szClassName[] = "WinMain";
37 
WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)38 int WINAPI WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
39 {
40   HWND hwnd;
41   MSG messages;
42   WNDCLASSEX wincl;
43 
44   wincl.hInstance = hThisInstance;
45   wincl.lpszClassName = szClassName;
46   wincl.lpfnWndProc = WindowProc;
47   wincl.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
48   wincl.cbSize = sizeof(WNDCLASSEX);
49 
50   wincl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
51   wincl.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
52   wincl.hCursor = LoadCursor(NULL,IDC_ARROW);
53   wincl.lpszMenuName = NULL;
54   wincl.cbClsExtra = 0;
55   wincl.cbWndExtra = 0;
56   wincl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);;
57 
58   if (!RegisterClassEx(&wincl)) return 0;
59 
60   hwnd = CreateWindowEx(0, szClassName, TITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WIDTH, HEIGHT,
61 			HWND_DESKTOP, NULL, hThisInstance, NULL);
62 
63   ShowWindow(hwnd,nCmdShow);
64 
65   while (GetMessage(&messages,NULL,0,0))
66   {
67     TranslateMessage(&messages);
68     DispatchMessage(&messages);
69   }
70   return (int)messages.wParam;
71 }
72 
Draw(HDC hdc)73 void Draw(HDC hdc)
74 {
75   HBRUSH pinsel;
76   pinsel = CreateSolidBrush(RGB(255,255,0));
77   Rectangle(hdc,10,10,110,110);
78   TextOut(hdc,15,45,"Hello, World!",13);
79 
80   SelectObject(hdc,pinsel);
81   Ellipse(hdc,100,100,200,200);
82   Arc(hdc,120,120,180,180,100,200,200,200);
83   SetPixel(hdc,130,140,0);
84   SetPixel(hdc,170,140,0);
85   MoveToEx(hdc,150,100,0);
86   LineTo(hdc,145,90);
87   LineTo(hdc,155,80);
88   LineTo(hdc,150,75);
89 }
90