1 //+---------------------------------------------------------------------------
3 // HELLO_WIN.C - Windows GUI 'Hello World!' Example
5 //+---------------------------------------------------------------------------
9 #define APPNAME "HELLO_WIN"
11 char szAppName
[] = APPNAME
; // The name of this application
12 char szTitle
[] = APPNAME
; // The title bar text
15 HINSTANCE g_hInst
; // current instance
17 void CenterWindow(HWND hWnd
);
19 //+---------------------------------------------------------------------------
23 // Synopsis: very unusual type of function - gets called by system to
24 // process windows messages.
26 // Arguments: same as always.
27 //----------------------------------------------------------------------------
29 LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
33 // ----------------------- first and last
43 // ----------------------- get out of it...
49 if (VK_ESCAPE
== wParam
)
54 // ----------------------- display our minimal info
60 hdc
= BeginPaint(hwnd
, &ps
);
62 GetClientRect(hwnd
, &rc
);
63 SetTextColor(hdc
, RGB(240,240,96));
64 SetBkMode(hdc
, TRANSPARENT
);
65 DrawText(hdc
, pWindowText
, -1, &rc
, DT_CENTER
|DT_SINGLELINE
|DT_VCENTER
);
71 // ----------------------- let windows do all other stuff
73 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
78 //+---------------------------------------------------------------------------
82 // Synopsis: standard entrypoint for GUI Win32 apps
84 //----------------------------------------------------------------------------
87 HINSTANCE hPrevInstance
,
97 // Fill in window class structure with parameters that describe
100 ZeroMemory(&wc
, sizeof wc
);
101 wc
.hInstance
= hInstance
;
102 wc
.lpszClassName
= szAppName
;
103 wc
.lpfnWndProc
= (WNDPROC
)WndProc
;
104 wc
.style
= CS_DBLCLKS
|CS_VREDRAW
|CS_HREDRAW
;
105 wc
.hbrBackground
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
106 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
107 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
109 if (FALSE
== RegisterClass(&wc
)) return 0;
111 // create the browser
115 WS_OVERLAPPEDWINDOW
|WS_VISIBLE
,
125 if (NULL
== hwnd
) return 0;
127 pWindowText
= lpCmdLine
[0] ? lpCmdLine
: "Hello Windows!";
129 // Main message loop:
130 while (GetMessage(&msg
, NULL
, 0, 0) > 0)
132 TranslateMessage(&msg
);
133 DispatchMessage(&msg
);
139 //+---------------------------------------------------------------------------
141 //+---------------------------------------------------------------------------
143 void CenterWindow(HWND hwnd_self
)
145 RECT rw_self
, rc_parent
, rw_parent
; HWND hwnd_parent
;
146 hwnd_parent
= GetParent(hwnd_self
);
147 if (NULL
==hwnd_parent
) hwnd_parent
= GetDesktopWindow();
148 GetWindowRect(hwnd_parent
, &rw_parent
);
149 GetClientRect(hwnd_parent
, &rc_parent
);
150 GetWindowRect(hwnd_self
, &rw_self
);
151 SetWindowPos(hwnd_self
, NULL
,
152 rw_parent
.left
+ (rc_parent
.right
+ rw_self
.left
- rw_self
.right
) / 2,
153 rw_parent
.top
+ (rc_parent
.bottom
+ rw_self
.top
- rw_self
.bottom
) / 2,
155 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
159 //+---------------------------------------------------------------------------