Why Is My Window Closing?

This is a discussion on Why Is My Window Closing? within the C++ Programming forums, part of the General Programming Boards category; The window keeps closing right away. Please tell me what I'm doing wrong. The following is a condensed version of ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    40

    Why Is My Window Freezing?

    The window keeps closing right away. Please tell me what I'm doing wrong. The following is a condensed version of the source for it.

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain(HINSTANCE hInstance, 
                         HINSTANCE hPrevInstance, 
                         LPSTR     lpCmdLine, 
                         int       nCmdShow)
    {
        WNDCLASS WndClass;
        WndClass.style = 0;
        WndClass.cbClsExtra = 0;
        WndClass.cbWndExtra = 0;
        WndClass.lpfnWndProc = WndProc;
        WndClass.hInstance = hInstance;
        WndClass.hbrBackground = (HBRUSH) (COLOR_MENU+1);
        WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        WndClass.lpszMenuName = 0;
        WndClass.lpszClassName = "WinProg";
        
        RegisterClass(&WndClass);
        
        HWND hWindow;
        hWindow = CreateWindow("WinProg","Test Windowl",
                               WS_OVERLAPPEDWINDOW,
                               0,0,600,500,NULL,NULL,
                               hInstance, NULL);
        ShowWindow (hWindow, nCmdShow);
        
        UpdateWindow (hWindow);
        MSG Message;
        while (GetMessage(&Message, NULL, 0, 0));
        {
            DispatchMessage(&Message);
        }
        
        return (Message.wParam);
    }
    
    LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
                              WPARAM wParam, LPARAM lParam)
    {
        switch(uiMessage)
        {
            case WM_PAINT:
                //some GDI functions
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
                break;
            default:
                return DefWindowProc (hWnd, uiMessage,
                                      wParam, lParam);
                
        }
    }
    Last edited by ShadowMetis; 08-19-2004 at 07:34 PM.
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    1
    In the code here:

    Code:
    switch(uiMessage)
        {
            case WM_PAINT:
                //some GDI functions
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
            default:
                return DefWindowProc (hWnd, uiMessage,
                                      wParam, lParam);
                
        }
    You did not include break; statements at the end of your cases, like this:

    Code:
    switch(uiMessage)
        {
            case WM_PAINT:
                //some GDI functions
              break; <-- missing
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
                break;

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    40
    AH!!! Duh on me, lol. Thanks alot.
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    40
    See any other dumb errors? Now, it freezes right after it finishes going through the WM_PAINT proccess. It won't move close or respond at all.
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    Post your complete WndProc().

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21