简单创建一个WIN32应用程序步骤 第2页
WndProc 函数的用途是处理应用程序接收的消息。通常使用 Switch 函数实现此操作。 
我们将处理的第一个消息是 WM_PAINT 消息。当必须更新应用程序窗口的一部分时,应用程序会收到 
此消息。首次创建窗口时,必须更新整个窗口,并传递此消息以指示此操作。 
当处理 WM_PAINT 消息时,首先应做的是调用 BeginPaint,最后应做的是调用 EndPaint。 
在这两个函数调用之间,您可以处理所有的逻辑,以在窗口中排列文本、按钮和其他控件。 
对于此应用程序,我们在窗口中显示字符串“Hello, World!”。若要显示文本, 
请使用 TextOut 函数,如下所示: 
PAINTSTRUCT ps; 
HDC hdc; 
TCHAR greeting[] = _T("Hello, World!"); 
switch (message) 
{ 
case WM_PAINT: 
hdc = BeginPaint(hWnd, &ps); 
// Here your application is laid out. 
// For this introduction, we just print out "Hello, World!" 
// in the top left corner. 
TextOut(hdc, 
5, 5, 
greeting, _tcslen(greeting)); 
// End application-specific layout section. 
EndPaint(hWnd, &ps); 
break; 
}应用程序通常会处理许多其他消息,如 WM_CREATE 和 WM_DESTROY。一个简单而完整的 WndProc 函数如下: 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
PAINTSTRUCT ps; 
HDC hdc; 
TCHAR greeting[] = _T("Hello, World!"); 
switch (message) 
{ 
case WM_PAINT: 
hdc = BeginPaint(hWnd, &ps); 
// Here your application is laid out. 
// For this introduction, we just print out "Hello, World!" 
// in the top left corner. 
TextOut(hdc, 
5, 5, 
greeting, _tcslen(greeting)); 
// End application specific layout section. 
EndPaint(hWnd, &ps); 
break; 
case WM_DESTROY: 
PostQuitMessage(0); 
break; 
default: 
return DefWindowProc(hWnd, message, wParam, lParam); 
break; 
} 
return 0; 
} 上一页  [1] [2] 
简单创建一个WIN32应用程序步骤 第2页下载如图片无法显示或论文不完整,请联系qq752018766