马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是鱼哥教我们的创建窗口的最基本的程序#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam , LPARAM lParam);
int
WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
TCHAR *szWndClsName = TEXT("new window class");
TCHAR *szWndName = TEXT("新窗口");
HWND hWnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_APPSTARTING);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszClassName = szWndClsName;
WndClass.lpszMenuName = NULL;
if( !RegisterClass(&WndClass) )
{
MessageBox(NULL, TEXT("注册窗口类失败"), TEXT("警告"), MB_OK | MB_ICONEXCLAMATION);
return 0;
}
hWnd = CreateWindow(szWndClsName,
szWndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
TCHAR *szTextContent = TEXT("只有一行文字");
switch(message)
{
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hDC, szTextContent, -1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
这个没问题
现在把while( GetMessage(&msg, NULL, 0, 0) )中的NULL改成hWnd。那么问题来了:可以关闭窗口,但是任务管理器中显示这个窗口的进程还在,因此,修改程序后生成不成功。
改成-1,关闭窗口直接卡住了。
哪位大神指点指点哈~~
貌似对GetMessage函数不是很理解~~
把WM_DESTROY下的return 0改为break试试
|