简体   繁体   English

C ++ Win32 Window没有响应

[英]C++ Win32 Window unresponsive

I have a console application from which I create a window. 我有一个控制台应用程序,我从中创建一个窗口。

I can render stuff in the window just fine. 我可以很好地在窗口中渲染东西。 But the window is unresponsive/uncontrollable by the user. 但是窗口没有响应/用户无法控制。

As soon as you mouse over the window you get the hourglass cursor and cannot move the window. 只要将鼠标移到窗口上,就会得到沙漏光标并且无法移动窗口。

What might be causing this? 可能是什么导致了这个?

EDIT: 编辑:

    WNDCLASSEX wndClass;         // Window class
    ZeroMemory(&wndClass, sizeof(wndClass)); // Clear the window class structure
    wndClass.cbSize = sizeof(WNDCLASSEX); 
    wndClass.style          = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC;
    wndClass.lpfnWndProc    = DefWindowProc;
    wndClass.cbClsExtra     = 0;
    wndClass.cbWndExtra     = 0;
    wndClass.hInstance      = nullptr;
    wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wndClass.lpszMenuName   = NULL;//MAKEINTRESOURCE(IDR_MAINMENU);
    wndClass.lpszClassName  = _classname.c_str();
    wndClass.hIconSm        = 0;

    if (RegisterClassEx(&wndClass) == 0)// Attemp to register the window class
        throw std::exception("WINDOW ERROR: Failed to register the window class!");

    DWORD dwStyle = 0;              // Window styles
    DWORD dwExStyle = 0;            // Extended window styles

    dwStyle = WS_OVERLAPPEDWINDOW |        // Creates an overlapping window
              WS_CLIPCHILDREN |            // Doesn"t draw within child windows
              WS_CLIPSIBLINGS;              // Doesn"t draw within sibling windows

    //adjust window size
    RECT rMain;
    rMain.left = 0;
    rMain.right = width;
    rMain.top = 0;
    rMain.bottom = height;  

    AdjustWindowRect(&rMain, dwStyle, 0);

    // Attempt to create the actual window
    _hwnd = CreateWindowEx( dwExStyle,     
                            className,
                            windowTitle,      
                            dwStyle,         
                            0, 0,           
                            rMain.right - rMain.left,
                            rMain.bottom - rMain.top,  
                            nullptr,             
                            0,  
                            nullptr,
                            0); 


    ShowWindow(_hwnd, SW_SHOW);
    SetForegroundWindow(_hwnd);
    SetFocus(_hwnd);

Since it's already mentioned in comments, I'll make this community wiki 由于已在评论中提及,我将制作此社区维基

You need to get the messages for the window and dispatch them accordingly. 您需要获取窗口的消息并相应地发送它们。

/* 
 *  HWND hWnd: this is the handle to your window (that is returned from CreateWindow[Ex]
*/
MSG msg;
while (GetMessage(&msg, hWnd, NULL, NULL) > 0){
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

If you don't do this, your wndProc function will never get any messages, and Windows finds it unresponsive (thus the hourglass). 如果你不这样做,你的wndProc函数将永远不会收到任何消息,Windows发现它没有响应(因此沙漏)。

消息循环的一部分被“暂时”评论过,我错过了这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM