Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.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++窗口并添加了一个菜单,但是当我点击菜单时,指定“关于”我想显示一个简单的消息框,但我不能——因为它没有显示。 LPCWSTR App_Name = TEXT("TestApp"); LPCWSTR App_Title = TEXT("TestTitle"); const int windowWidth = 480; const int windowHeight = 480; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = App_Name; wc.lpszMenuName = MAKEINTRESOURCE(MNU_MAINMENU); wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); RECT rc; GetWindowRect(GetDesktopWindow(), &rc); long screenWidth = rc.right; long screenHeight = rc.bottom; HWND hwnd = CreateWindow ( App_Name, App_Title, WS_MINIMIZEBOX | WS_SYSMENU, (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2)-(windowHeight/2), windowWidth, windowHeight, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd, iCmdShow ); UpdateWindow(hwnd); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam; }_C++_Menu_Window_Messagebox - Fatal编程技术网

单击菜单时显示消息框';不出现在屏幕上 我刚刚制作了一个简单的C++窗口并添加了一个菜单,但是当我点击菜单时,指定“关于”我想显示一个简单的消息框,但我不能——因为它没有显示。 LPCWSTR App_Name = TEXT("TestApp"); LPCWSTR App_Title = TEXT("TestTitle"); const int windowWidth = 480; const int windowHeight = 480; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = App_Name; wc.lpszMenuName = MAKEINTRESOURCE(MNU_MAINMENU); wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); RECT rc; GetWindowRect(GetDesktopWindow(), &rc); long screenWidth = rc.right; long screenHeight = rc.bottom; HWND hwnd = CreateWindow ( App_Name, App_Title, WS_MINIMIZEBOX | WS_SYSMENU, (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2)-(windowHeight/2), windowWidth, windowHeight, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd, iCmdShow ); UpdateWindow(hwnd); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam; }

单击菜单时显示消息框';不出现在屏幕上 我刚刚制作了一个简单的C++窗口并添加了一个菜单,但是当我点击菜单时,指定“关于”我想显示一个简单的消息框,但我不能——因为它没有显示。 LPCWSTR App_Name = TEXT("TestApp"); LPCWSTR App_Title = TEXT("TestTitle"); const int windowWidth = 480; const int windowHeight = 480; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = App_Name; wc.lpszMenuName = MAKEINTRESOURCE(MNU_MAINMENU); wc.style = CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); RECT rc; GetWindowRect(GetDesktopWindow(), &rc); long screenWidth = rc.right; long screenHeight = rc.bottom; HWND hwnd = CreateWindow ( App_Name, App_Title, WS_MINIMIZEBOX | WS_SYSMENU, (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2)-(windowHeight/2), windowWidth, windowHeight, NULL, NULL, hInstance, NULL ); ShowWindow(hwnd, iCmdShow ); UpdateWindow(hwnd); MSG msg; while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam; },c++,menu,window,messagebox,C++,Menu,Window,Messagebox,还有留言盒…: LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wparam, LPARAM lparam) { switch( message ) { case WM_COMMAND: id = LOWORD(wparam); event = LOWORD(wparam); switch(id)

还有留言盒…:

LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wparam, LPARAM lparam)
{   
        switch( message )
        {

        case WM_COMMAND:
            id = LOWORD(wparam);
            event = LOWORD(wparam);
            switch(id)
            {
                case MNU_HELP_ABOUT:
                MessageBox(NULL, TEXT("TEXT"), TEXT("TITLE"), MB_OK | MB_ICONINFORMATION);
                break;
            }
        break;

        }
}
菜单工作,因为我添加了一个退出,所以我知道它会响应菜单上的点击,但当我点击“关于”按钮时,你会听到弹出的声音,但没有显示消息框


有什么想法吗?

MessageBox的第一个参数是父项的hWnd。请注意,MessageBox调用是同步的,因此在用户单击OK按钮之前,控件不会返回到WndProc。(因此您的窗口没有响应。)但您尚未提供父hWnd,因此消息框可能是在您的窗口下创建的


尝试将hwnd作为第一个MessageBox参数传递,看看这是否有帮助。

我不知怎么搞明白了。问题是因为我并没有在WM_CREATE中做任何事情,或者“什么都并没有”在表单上-白色背景,或者其他什么。当我开始向窗口添加控件(按钮)时,它突然出现在以前没有的地方。只是奇怪…

已经尝试过了,同样的结果。有它作为默认,只是我的最后一次测试,我没有它。所以…好的。运行SpyXX(我假设它仍然存在),看看您是否可以在windows列表中找到消息框。哦,然后输出一条日志消息或类似的消息,以验证是否确实调用了MessageBox。调试时,输出选项卡中没有任何内容?如果您还没有这样做,尝试在MessageBox调用之前添加对OutputDebugString的调用。