Thread: DestroyWindow(); wont destroy the window?

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    DestroyWindow(); wont destroy the window?

    first my code:
    Code:
    case WM_COMMAND:
    WORD wID,wNotify;
    
    wID=LOWORD(wparam);
    wNotify=HIWORD(wparam);
    
    case BN_CLICKED:
    if(wID == 90)
    {
    WNDCLASS bw;
    HINSTANCE hInst;
    // register brush insert window class
    memset(&bw,0,sizeof(WNDCLASS));
    bw.style = CS_OWNDC;
    bw.lpfnWndProc = (WNDPROC)WndProc;
    bw.cbClsExtra = 0;
    bw.cbWndExtra = 0;
    bw.hInstance = hInst;
    bw.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    bw.hCursor = LoadCursor( NULL, IDC_ARROW );
    bw.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
    bw.lpszMenuName = NULL;
    bw.lpszClassName = "BrushWin";
    if (RegisterClass( &bw ))
    {
    HWND BrushWin;
    HWND button;
    BrushWin = CreateWindow( 
    "BrushWin", "", 
    WS_CHILD | WS_POPUP | WS_VISIBLE | WS_CAPTION,
    100, 100, 400, 300,
    hWnd, NULL, hInst, NULL );
    
    button = CreateWindow("BUTTON", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 330, 246, 64, 24, BrushWin,(HMENU) 210, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    if(wID == 210)
    {
    DestroyWindow(BrushWin);
    }
    }
    
    }
    return 0;
    break;
    anyway....when that button is pressed, the specified window will not close.

    any help will be greatly appreciated

    -psychopath

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Code:
    case BN_CLICKED:
    if(wID == 90)
      {
      if (wID==210) 
        {
        /*never reached */
        }
      }
    Using some sort of indentation scheme in your code would probably help you identify problems of this nature.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Code:
    case WM_COMMAND:
    	WORD wID,wNotify;
    	
    	wID=LOWORD(wparam);
    	wNotify=HIWORD(wparam);
    	
    case BN_CLICKED:
    	if(wID == 90)
    	{
    		WNDCLASS bw;
    		HINSTANCE hInst;
    		// register brush insert window class
    		memset(&bw,0,sizeof(WNDCLASS));
    		bw.style = CS_OWNDC;
    		bw.lpfnWndProc = (WNDPROC)WndProc;
    		bw.cbClsExtra = 0;
    		bw.cbWndExtra = 0;
    		bw.hInstance = hInst;
    		bw.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    		bw.hCursor = LoadCursor( NULL, IDC_ARROW );
    		bw.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
    		bw.lpszMenuName = NULL;
    		bw.lpszClassName = "BrushWin";
    		if (RegisterClass( &bw ))
    		{
    			HWND BrushWin;
    			HWND button;
    			BrushWin = CreateWindow( 
    				"BrushWin", "", 
    				WS_CHILD | WS_POPUP | WS_VISIBLE | WS_CAPTION,
    				100, 100, 400, 300,
    				hWnd, NULL, hInst, NULL );
    			
    			// x = 270 if BrushWin style = 'WS_DLGFRAME'
    			button = CreateWindow("BUTTON", "Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 330, 246, 64, 24, BrushWin,(HMENU) 210, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    			if(wID == 210)
    			{
    				DestroyWindow(BrushWin);
    			}
    		}
    		
    	}
    	break;
    ok....now then....does anybody have any idea as to what might be the problem?

    -psychopath

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Ken does........study his post a little harder.

    Spock would roll-over in his grave....

    gg

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    o...oops....sorry...

    >>case BN_CLICKED:
    if(wID == 90)
    {
    if (wID==210)
    {
    /*never reached */
    }
    }<<

    how is it 'never reached'?

    -psychopath

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Stop drinking Mellow-Yellow's and get some sleep!!!

    Then tell me why the following code will never print "Hello World".
    Code:
    int X = 42;
    
    if (X == 42)
    {
        if (X == 69)
        {
            puts("Hello World");
        }
    }
    gg

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    ok...tho i still havn't gotten much sleep (and i still love mellow-yellow :P), i'm going to make an attempt at logical thinking (and in the end i'll still be wrong).

    in the code you showed above, 'hello world' is only displayed on the condition that X = 69.
    But X can only = 69 if X = 42, which means X will never = 69?

    -psychopath

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Correct.

    gg

  9. #9
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    so what if it looked like:

    Code:
    int X = 42;
    
    if (X == 42)
    {
        DoSomthing();
    }
    
    if (X == 69)
    {
        puts("Hello World");
    }
    would this work...if not what would?

    -psychopath

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Your code has several other logic and programming errors. I would suggest that you get a good handle on C/C++ programming as a language before attempting Windows programming using those languages.

    gg

  11. #11
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    yes...but in order to have a good understanding of anything, you must first learn from your mistakes. Now I obviously made a mistake, but i don't exactly what it is or how to fix it, so therefore I can't learn from it now can I?

    -psychopath

  12. #12
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    Aww.. for fu*** sake. This is simpliest logical "problem" I can think of. But it does require one to be awake and not drunk...
    Code:
    case WM_COMMAND:
      WORD wID,wNotify;
    
      wID=LOWORD(wparam);
      wNotify=HIWORD(wparam);
    
      switch (wNotify)
      {
      case BN_CLICKED:
        if(wID == 90)
        {
          WNDCLASS bw;
          HINSTANCE hInst;
          // Blah Blah Blah
          if (RegisterClass( &bw ))
          {
            HWND BrushWin;
            HWND button;
            BrushWin = CreateWindow("BrushWin", "",
              WS_CHILD | WS_POPUP | WS_VISIBLE | WS_CAPTION,
              100, 100, 400, 300, hWnd, NULL, hInst, NULL );
            // x = 270 if BrushWin style = 'WS_DLGFRAME'
            button = CreateWindow("BUTTON", "Cancel",
              WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
              330, 246, 64, 24, BrushWin,(HMENU) 210,
              (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
          }
        }
        else if(wID == 210)
        {
          DestroyWindow(BrushWin);
        }
        break;
      }

  13. #13
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    wow...it still doesn't work

    my code:
    Code:
    case WM_COMMAND:
    			WORD wID, wNotify;
    			wID=LOWORD(wparam);
    			wNotify=HIWORD(wparam);
    
    			HWND BrushWin;
    			HWND button;
    							
    			switch (wNotify)
    			{
    			case BN_CLICKED:
    			if(wID == 90)
    			{
    				WNDCLASS bw;
    				HINSTANCE hInst;
    				// register brush insert window class
    				memset(&bw,0,sizeof(WNDCLASS));
    				bw.style = CS_OWNDC;
    				bw.lpfnWndProc = (WNDPROC)WndProc;
    				bw.cbClsExtra = 0;
    				bw.cbWndExtra = 0;
    				bw.hInstance = hInst;
    				bw.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    				bw.hCursor = LoadCursor( NULL, IDC_ARROW );
    				bw.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH );
    				bw.lpszMenuName = NULL;
    				bw.lpszClassName = "BrushWin";
    				if (RegisterClass( &bw ))
    				{
    					BrushWin = CreateWindow( 
    						"BrushWin", "", 
    						WS_CHILD | WS_POPUP | WS_VISIBLE | WS_CAPTION,
    						100, 100, 400, 300,
    						hWnd, NULL, hInst, NULL );
    					
    					// x = 270 if BrushWin style = 'WS_DLGFRAME'
    					button = CreateWindow("BUTTON", "Cancel",
    						WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
    						330, 246, 64, 24,
    						BrushWin,(HMENU) 210, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    				}
    			}
    			else if(wID == 210)
    			{
    				DestroyWindow(BrushWin);
    			}
    			break;
    			}

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, 11:06 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM