C++ Issue with creating popup window, getting other window instead(C++ 创建弹出窗口的问题,而不是获取其他窗口)
问题描述
我只是想制作一个弹出窗口,稍后将显示我需要的任何信息.我遇到的问题是......当我点击按钮时,我没有创建一个新的弹出窗口,而是弹出我的主程序窗口的副本.
I am simply trying to make a pop up window, that later on will display whatever information i need it to. The issue I am having is... instead of creating a new popup window when I click the button, a copy of my main program window pops up.
这是我的 WinMain 函数中的代码:
Here is the code in my WinMain Function:
 HINSTANCE hInstanceSaved;//I am declaring an HINSTANCE VARIABLE HERE
 // SO THAT IT IS GLOBAL AND THEN I CAN USE IT WHEN I CREATE MY POPUP WINDOW
 INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine, int nCmdShow)
 {
hInstanceSaved = hInstance;
//here I am giving the global hInstanceSaved variable the value of hInstance
// so that when I click the button, I can have this variale available to me
// so that i can use the CreateWindowEx() function
MSG        Msg;
HWND       hWnd;
WNDCLASSEX WndClsEx;
LPCTSTR ClsName = "ResFund";
LPCTSTR WndName = "Resources Fundamentals";
// Create the application window
WndClsEx.cbSize        = sizeof(WNDCLASSEX);
WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc   = WndProcedure;
WndClsEx.cbClsExtra    = 0;
WndClsEx.cbWndExtra    = 0;
WndClsEx.hIcon         = LoadIcon(hInstance,
                  MAKEINTRESOURCE(IDI_BOOKED));
WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName  = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance     = hInstance;
WndClsEx.hIconSm       = LoadIcon(hInstance,
                  MAKEINTRESOURCE(IDI_BOOKED));
// Register the application
RegisterClassEx(&WndClsEx);
// Create the window object
hWnd = CreateWindowEx(0,
                      ClsName,
                      WndName,
                      WS_OVERLAPPEDWINDOW,
                      200,//CW_USEDEFAULT,//how much to the right
                      200, //CW_USEDEFAULT,//how much downwards
                      800,//CW_USEDEFAULT,//width
                      500,//CW_USEDEFAULT,//height
                      NULL,
                      NULL,
                      hInstance,
                      NULL);
// Find out if the window was created
if( !hWnd ) // If the window was not created,
    return FALSE; // stop the application
// Display the window to the user
ShowWindow(hWnd, nCmdShow);// SW_SHOWNORMAL);
UpdateWindow(hWnd);
///CREATING THE WINDOW CLASS FOR YOUR POP WINDOW:
const char g_szClassName2[] = "invisWindow";//name of the window class
WNDCLASSEX invisWindowClass;
HWND invisHWnd;
invisWindowClass.cbSize         = sizeof(WNDCLASSEX);
invisWindowClass.style          = 0;
invisWindowClass.lpfnWndProc    = WndProcedure;//WndProc;//WNDPROC; //WndProcedure;
invisWindowClass.cbClsExtra     = 0;
invisWindowClass.cbWndExtra     = 0;
invisWindowClass.hInstance     = hInstance;///u might have to get this, but that isn't too hard xD
invisWindowClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
invisWindowClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
invisWindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
invisWindowClass.lpszMenuName  = NULL;
invisWindowClass.lpszClassName = g_szClassName2;
invisWindowClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&invisWindowClass);
while( GetMessage(&Msg, NULL, 0, 0) )
{
         TranslateMessage(&Msg);
         DispatchMessage(&Msg);
}
return 0;
}
当我单击这将使窗口弹出"按钮时,我的代码是:
the code I have for when I click the button "which will make the window pop up" is:
            case IDC_POPUP:
            {
                const char g_szClassName2[] = "invisWindow";
                const char WndName2[] = "invisible Window";
                HWND invisWindowHandle = CreateWindowEx(0,
                      g_szClassName2,
                      WndName2,
                      WS_OVERLAPPEDWINDOW,
                      200,//CW_USEDEFAULT,//how much to the right
                      200, //CW_USEDEFAULT,//how much downwards
                      800,//CW_USEDEFAULT,//width
                      500,//CW_USEDEFAULT,//height
                      NULL,
                      NULL,
                      hInstanceSaved,
                      NULL);
                if( !invisWindowHandle ) // If the window was not created,
                    return FALSE; // stop the application
                ShowWindow(invisWindowHandle, 3);// SW_SHOWNORMAL);
                UpdateWindow(invisWindowHandle);
            }
            break;
现在为什么我没有得到一个新的空弹出窗口,而是我的主程序窗口的副本?
Now why am I not getting a new empty popup window but rather a copy of my main program window?
推荐答案
第二个窗口的窗口过程似乎有些不确定.您是否为它提供了 WndProcedure 函数?该 WndProcedure 是否处理 WM_PAINT 消息?您必须拥有 WM_PAINT 处理程序才能看到一些东西.
There seems to be some uncertainty about the window procedure for the 2nd window. Did you provide a WndProcedure function for it? Does that WndProcedure handle the WM_PAINT message? You have to have the WM_PAINT handler so you can see something.
这篇关于C++ 创建弹出窗口的问题,而不是获取其他窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 创建弹出窗口的问题,而不是获取其他窗口
 
				
         
 
            
        基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				