簡體   English   中英

創建彈出窗口,獲取其他窗口的C ++問題

[英]C++ Issue with creating popup window, getting other window instead

我只是試圖制作一個彈出窗口,稍后將顯示我需要的任何信息。 我遇到的問題是...當我單擊按鈕時,沒有創建新的彈出窗口,而是彈出了主程序窗口的副本。

這是我的WinMain函數中的代碼:

 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;

}

單擊“將使窗口彈出”按鈕時的代碼為:

            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;

現在為什么為什么我沒有得到一個新的空彈出窗口,而是一個主程序窗口的副本?

關於第二個窗口的窗口過程似乎有些不確定性。 您是否為此提供了WndProcedure函數? 該WndProcedure是否處理WM_PAINT消息? 您必須具有WM_PAINT處理程序,才能看到一些內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM