Thread: Window not getting automatic messages

  1. #1
    myNegReal
    Join Date
    Jun 2005
    Posts
    100

    Window not getting automatic messages

    I'm working on a game engine for Windows using OpenGL and have come across a little problem. My window isn't getting it's messages. Like ones that would automatically be sent. I can't close the window with the X button, I can't maximize, minimize or even move the window. However I can send a message to the window handle and it'll recieve that, so I have a workaround to close the window for now. The window handle DC, RC, and HINSTANCE are inside a struct Window, maybe they're being obscured or not sent properly and that's what causing them to not be sent/recieved? I'm thinking maybe that because the HWND is inside a struct, the class and window procedure aren't linking properly? Any ideas? If you need any code to look at, just say so.

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Yes please post code

  3. #3
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    The struct is like this
    Code:
    typedef struct {
        HINSTANCE hInstance;
        HWND hwnd;
        HDC hdc;
        HGLRC hrc;
        GLData data;
    } Window;
    GLData is another struct that holds data like the width and height of the screen.
    WinMain:
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow) {
        GLData wndDat = {800, 600, 32, 16, false, 100.0f};
        Window window = {hInstance, NULL, NULL, NULL, wndDat};
        WNDCLASSEX wc;
        MSG msg;
        bool isRunning;
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(GetModuleHandle(NULL), "MainIcon");
        wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), "MainIcon", IMAGE_ICON, 16, 16, 0);
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = NULL;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = "UVClass";
        if (!RegisterClassEx(&wc)) {
            ERRORBOX("Could not register class.");
            return 0;
        }
    while(isRunning) {
            if (createGLWindow(&window)) {
                if (!init()) {
                    isRunning = false;
                } else {
                    bool msgRun = true;
                    while (msgRun) {
                       if (PeekMessage(&msg, window.hwnd, 0, 0, PM_REMOVE) != 0) {
                           if (msg.message == WM_QUIT) {
                               if (msg.wParam == 1)
                                   isRunning = false;
                               msgRun = false;
                           }
                           else {
                               if (msg.message == WM_SIZE) {
                                   glSize(window.data);
                               } else {
                                   TranslateMessage(&msg);
                                   DispatchMessage(&msg);
                               }
                           }
                       } else {
                            if (Input::vkeys[VK_ESCAPE])
                                PostMessage(window.hwnd, WM_QUIT, 1, 0);
                           update(0);
                           draw();
                           SwapBuffers(window.hdc);
                       }
                    }
                }
                deInit();
                destroyGLWindow(&window);
            } else {
                ERRORBOX("Window initialization failed.");
                isRunning = false;
            }
        }
        if (!UnregisterClass("UVClass", window.hInstance))
            ERRORBOX("Could not unregister class.");
        return 0;
    }
    And the window procedure:
    Code:
    RESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    	switch(msg) {
    case WM_CLOSE:
    			PostQuitMessage(1);
    			break;
            case WM_KEYDOWN:
                Input::vkeys[wParam] = true;
                break;
            case WM_KEYUP:
                Input::vkeys[wParam] = false;
                break;
    		default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    	return 0;
    }
    When I post a message to window.hwnd and then test for it in the loop, it works, but the window procedure doesn't seem to be working.
    Edit:
    The procedure must be working, sorry, that's what I use to check input, and that's working, for some reason it's just not getting the window messages.
    Last edited by Ganoosh; 07-15-2005 at 06:09 PM.
    Using Dev-C++ on Windows

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You could try using NULL as the second argument to PeekMessage. You should process all the messages that your app receives. If it's an OpenGL issue the games forum may have better ideas.

  5. #5
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    It's not OpenGL I'm pretty sure but I think for some reason the messages sent when you click the buttons and move and such aren't being sent or caught. I'm gonna try and look into a manual way to do this for now if I can't figure it out.

    Edit: Nevermind, I got it, apparently these messages are sent through WM_SYSCOMMAND and are processed in the default window procedure, as you can see i had it intercepting all of these messages, got it fixed now though.
    Last edited by Ganoosh; 07-15-2005 at 11:31 PM.
    Using Dev-C++ on Windows

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM