0
我從我的應用程序打開OpenGL窗口時遇到了問題。CreateWindowsEx()失敗,觸發斷點
我正在使用一個64位控制檯應用程序,並且從該控制檯中我想打開另一個窗口供OpenGL繪製。
調用在CreateWindowEx()失敗,並且失敗,並且「MyApp.exe已觸發斷點」 以下代碼初始化窗口本身。
bool OpenGL_Display::CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag, int posX, int posY)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left/Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = NULL; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
HWND hwndC = GetConsoleWindow();
// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
hwndC, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
}
前面的代碼導致它:
extern "C" __declspec(dllexport) void OpenGLDisplay_Init(int width, int height, int posX, int posY)
{
oglDisp.Init_Display(width, height, posX, posY);
}
void OpenGL_Display::Init_Display(int width, int height, int posX, int posY)
{
if (!CreateGLWindow("Ophthametrics Live Display", width, height, 24, false, posX, posY))
{
throw;
}
}
什麼是有問題呢?我不知道,我正在使用我用於其他應用程序的代碼,它工作得很好。雖然它只是失敗了(在原始代碼中,它不是控制檯應用程序,而是沒有控制檯的Win32應用程序)。
最終的解決方案將在一個被調用的DLL中,一旦它被調用,它應該創建一個窗口供OpenGL繪製。
'HWND hwndC = GetConsoleWindow();' - 是否返回有效的'HWND'?另外,對於沒有父節點的情況,只需在'hwndC'處傳遞'NULL'即可。 – slugonamission
是的,它返回一個有效的句柄。我也試着用NULL作爲父窗口,但它仍然發生同樣的錯誤。 – SinisterMJ
如果您將窗口過程指向實際功能會怎樣? – slugonamission