我只是想制作一个弹出窗口,稍后会显示我需要的任何信息。我遇到的问题是......当我点击按钮时,而不是创建一个新的弹出窗口,弹出我的主程序窗口的副本。
以下是我的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;
}
当我点击按钮&#34时我所拥有的代码;这将使窗口弹出"是:
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;
为什么我没有得到一个新的空弹出窗口,而是我的主程序窗口的副本?
答案 0 :(得分:0)
第二窗口的窗口过程似乎存在一些不确定性。你有没有提供WndProcedure功能? WndProcedure是否处理WM_PAINT消息?您必须拥有WM_PAINT处理程序才能看到某些内容。