代码如下:
#include "Windows.h"
//处理WM_PAINT消息
void OnPaint(HWND hWnd)
{
//获取设备上下文句柄
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWnd, &ps);
//获取窗口客户去矩形
RECT rcClient;
GetClientRect(hWnd, &rcClient);
//在窗口客户区内显示文本
DrawText(hDC, "Hello , World!", -1, &rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
//释放设备上下文
EndPaint(hWnd, &ps);
}
//主窗口过程函数
LRESULT CALLBACK MainWndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT: //窗口绘制消息
{
OnPaint(hWnd);
}break;
case WM_DESTROY: //窗口销毁消息
{
PostQu