Question

I've got an issue with opening an OpenGL window from my application.

I am using a 64bit console application, and from within that console I want to open another window for OpenGL to draw into.

The call fails at CreateWindowEx(), and fails with "MyApp.exe has triggered a breakpoint" Following code initializes the window itself.

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
    }
}

The previous code leading to it:

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;
    }   
}

What is going wrong in there? I have no idea, and I was using code I used for another application, which worked just fine. Here though it just fails horribly (in the original code it was no console application, but rather a Win32 application without the console).

The final solution would be in a DLL which is called and once it gets called, it should create a window for OpenGL to draw into.

Was it helpful?

Solution

"What if you point your window proc at a real function?"

Written by slugo, that did it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top