Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将代码添加到WNDCLASSEX中的WndProc回调会中断代码_C++_User Interface_System - Fatal编程技术网

C++ 将代码添加到WNDCLASSEX中的WndProc回调会中断代码

C++ 将代码添加到WNDCLASSEX中的WndProc回调会中断代码,c++,user-interface,system,C++,User Interface,System,我有这个代码,它是我正在创建的用户界面系统的一部分,它将有多个窗口 bool UISystem::HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { UIWindow* target = NULL; for(vector<UIWindow*>::iterator it = windowList.begin(); it < windowList.end(); it++) {

我有这个代码,它是我正在创建的用户界面系统的一部分,它将有多个窗口

bool UISystem::HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    UIWindow* target = NULL;
    for(vector<UIWindow*>::iterator it = windowList.begin(); it < windowList.end(); it++)
    {
        if((*it)->windowHandle == hwnd)
        {
            target = *it;
            break;
        }
    }

    if(target == NULL)
    { return false; }

    switch(msg)
    {
    case WM_DESTROY:

        return true;

    case WM_PAINT:  

        return true;

    default:
        return false;
    }
}

LRESULT WINAPI UISystem::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    /*if(UISYSTEM->HandleMessage(hwnd, msg, wParam, lParam))
    {
    }*/
    return DefWindowProc(hwnd, msg, wParam, lParam);
}

不确定这是否是根本问题,但需要解决的一件事是删除:

while(GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
发件人:


只要窗口存在,这个while就会循环,并且会阻止UIWindow被正确构造。这个对象(UIWindow)实际上是在:UISystem::HandleMessage中被访问的,但由于它的构造函数永远不会结束,所以它可能是NULL或处于未定义状态

作为旁注,不必维护所有窗口的全局列表,您可以通过使用GWL_USERDATA调用SetWindowLong将用户数据存储在窗口中:luskan,然后如何在不关闭整个应用程序的情况下保持每个窗口的消息泵运行?请看这里:,每个线程应该有一个消息循环,只需将其放在main()中即可功能和它将是好的。在这个循环之前,初始化就完成了。我想我可能是不小心删除了你的评论,对不起!这个看起来怎么样?您希望每个窗口都有一个单独的线程(同时查看CWinThread)?如果是这样,则必须在其自己的线程中创建每个窗口。但并非所有UI都是以这种方式构建的,大多数情况下,您只有一个GUI线程,其中所有窗口都在创建。我的方法不起作用,我将消息循环放在主入口点,但仍然无效:(
while(GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
UIWindow::UIWindow(int x, int y, int width, int height, string & text)