Win32 绘制文本在重建后仍然存在
Win32 Paint Text still there after rebuilding
在为我的Windows类制作完包装器的同时,我用一些文本做了一个测试,以确保一切正常。但是,无论我是否删除或注释掉文本"这是一个测试!!!",在运行程序时,它在可执行文件运行期间仍然保留在那里。
LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
//hdc = BeginPaint(hwnd, &ps);
//TextOut(hdc, 0, 0, L"This is a TEST!!!", 17);
//EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
bWindowClosed = TRUE;
break;
case WM_CREATE:
MessageBox(NULL, L"Create", L"test", MB_OK);
break;
default:
return CBaseWindow::WinMsgHandler(hwnd, uMsg, wParam, lParam);
}
return 0;
};
编辑:
这是 winmain 源文件。我有一种感觉,这与我包围一切的方式有关。CDerivedWindow 是一个包装类,用于封装大部分窗口初始化过程。
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
CDerivedWindow mainWnd(hInstance);
WNDCLASSEX wcx;
// Fill in the window class structure with default parameters
wcx.cbSize = sizeof(WNDCLASSEX); // size of structure
wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = CBaseWindow::stWinMsgHandler; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = hInstance; // handle to instance
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // predefined app. icon
wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // predefined arrow
wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // white background brush
wcx.lpszMenuName = NULL; // name of menu resource
wcx.lpszClassName = L"True Wild"; // name of window class
wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // small class icon
initSprites();
// register the window
if (mainWnd.RegisterWindow(&wcx))
{
DWORD dwError = 0;
DWORD dwStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
RECT rc;
rc.top = 100;
rc.left = 100;
rc.right = SCREEN_WIDTH;
rc.bottom = SCREEN_HEIGHT;
// create the window and start the message loop
// we will get kicked out of the message loop when the window closes
if (mainWnd.Create(dwStyle, &rc))
{
// message loop
MSG msg;
//game Loop
while (TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Translate the message and dispatch it to WindowProc()
TranslateMessage(&msg);
DispatchMessage(&msg);
if (mainWnd.IsWindowClosed())
return 0;
}
//Run game code
render();
}
return 0;
}
else
return -1;
}
else
return -2;
return 0;
}
编辑答案 1:
// the message handler for this window
LRESULT CALLBACK WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
bWindowClosed = TRUE;
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
};
如果不
处理WM_PAINT,则应将其传递给DefWindowProc()
以验证工作区并重新绘制窗口。
看起来您正在突破开关/机箱并返回 0。我会替换:
return 0;
跟
return DefWindowProc(hwnd, uMsg, wParam, lParam);
相关文章:
- C++模板来检查友元函数的存在
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 如何检查QList中是否存在值
- 根据某个函数是否存在启用模板
- 如何将分支添加到已存在的TTree:ROOT
- 地图计数确实很重要,或者只是检查是否存在
- 通用C++/Python 多语言的存在
- Win32 绘制文本在重建后仍然存在