Thread: Window won't display on button command!?

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

    Window won't display on button command!?

    *sigh* first the menu now the buttons....anyway, this time i can't get a window to display when the button is pressed:

    mainprogg.cpp (section)
    Code:
    LRESULT CALLBACK 
    WndProc( HWND hWnd, UINT message,
    WPARAM wParam, LPARAM lParam )
    {
    static HWND level_edit;
    static HWND button;
    
    switch ( message ) {
    
    case WM_CREATE:
    return 0;
    
    case WM_CLOSE:
    if(MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)==IDYES)
    {
    PostQuitMessage( 0 );
    }
    return 0;
    
    case WM_DESTROY:
    return 0;
    
    case WM_KEYDOWN:
    switch ( wParam ) {
    
    case VK_ESCAPE:
    if(MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)==IDYES)
    {
    PostQuitMessage( 0 );
    }
    return 0;
    }
    
    
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case ID_EXIT:
    if(MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)==IDYES)
    {
    PostQuitMessage( 0 );
    }
    break;
    
    case ID_LVLEDIT:
    LvlEdit(hWnd, level_edit, button, GetModuleHandle(0));
    break;
    return 0;
    }
    
    WORD wID,wNotify;
    
      wID=LOWORD(wParam);
      wNotify=HIWORD(wParam);
        if (lParam)
        {
        //if a button was clicked
        if (wNotify==BN_CLICKED)
          {
           //if a buttons id was clicked
          if (wID==10)
          {
          LvlEdit(hWnd, level_edit, button, GetModuleHandle(0));
          }
       }
    }
    return 0;
    windowcall.h
    Code:
    BOOL LvlEdit(HWND hWnd, HWND level_edit, HWND button, HINSTANCE hInstance )
    {
    level_edit = CreateWindow(
    "LVLEDIT", "Level Editor",
    WS_CHILD | WS_CAPTION | WS_VISIBLE,
    200, 0, 592, 516,
    hWnd, NULL, hInstance, NULL );
    
    button = CreateWindow("BUTTON", "Close", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 528, 0, 64, 24, level_edit,(HMENU) 210, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    }
    not quite sure how much of the mainprog.cpp is actually neccessary, but anyway/.......thanks ahead of time

    -psychopath

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Does the code ever enters to where the program creates the window via LvlEdit()?

    Kuphryn

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

    Code:
    //if a buttons id was clicked
          if (wID==10)
          {
          LvlEdit(hWnd, level_edit, button, GetModuleHandle(0));
          }
    except it dosn't work??

    -psychopath

  4. #4
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107
    Try calling GetLastError() after you attempt to create the window.

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    that diddn't seem to do anything either =/

    -psychopath

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    man! this is some crappy code you have there fellah!
    I don't even want to count bugs and bad solutions. anyway:
    Code:
    LRESULT CALLBACK  WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
    {
    	static HWND level_edit;
    	static HWND button;
    
    	switch ( message )
    	{
    		case WM_CREATE:
    		return 0;
    
    		case WM_CLOSE:
    			if(MessageBox (NULL, "Are you sure..." , "Exiting...",  MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION)==IDYES)
    				DestroyWindow(hWnd);			
    			return 0;
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    
    		case WM_KEYDOWN:
    			switch (wParam)
    			{
    			case VK_ESCAPE:
    					CloseWindow(hWnd);
    					break;
    			}
    			return 0;
    
    		case WM_COMMAND:
    			WORD wID     = LOWORD(wParam);
    			WORD wNotify = HIWORD(wParam);
    
    			if (lParam)
    				switch (wID) // Controls
    				{
    				case IDC_EXIT:
    					if (wNotify == BN_CLICKED)
    						CloseWindow(hWnd);
    					break;
    	
    				case IDC_LVLEDIT:
    					if (wNotify == BN_CLICKED)
    						if (!LvlEdit(hWnd, &level_edit, &button, GetModuleHandle(0)))
    						{
    							MessageBox(NULL, "LvlEdit() failed! Commiting suicide...", "Error", MB_OK | MB_ICONERROR);
    							DestroyWindow(hWnd);
    						}
    					break;
    				}
    			else
    				switch (wID) // Menu
    				{
    				}
    
    			return 0;
    }
    and your LvlEdit function:
    Code:
    BOOL LvlEdit(HWND hWnd, HWND *level_edit, HWND *button, HINSTANCE hInstance )
    {
    	*level_edit = CreateWindow("LVLEDIT", "Level Editor",
    	                           WS_CHILD | WS_CAPTION | WS_VISIBLE,
    	                           200, 0, 592, 516,
    	                           hWnd, NULL, hInstance, NULL );
    	if (*level_edit == NULL)
    	{
    		//MyErrorHandler(GetLastError());
    		return FALSE;
    	}
    	
    	*button = CreateWindow("BUTTON", "Close",
    	                       WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
    	                       528, 0, 64, 24,
    	                       level_edit, (HMENU)IDC_MYBUTTON, hInstance, NULL);
    	if (*button == NULL)
    	{
    		//MyErrorHandler(GetLastError());
    		return FALSE;
    	}
    
    	return TRUE;
    }
    and you _should_ put all your's control IDs in resource.h file _and_ use them:
    Code:
    #define IDC_EXIT     1001
    #define IDC_LVLEDIT  1002
    #define IDC_MYBUTTON 1003
    If it still doesn't work try calling ShowWindow after creating child windows and check if "LVLEDIT"-class is registered.
    Last edited by iwabee; 06-22-2004 at 11:00 AM.

  7. #7
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    still can't get it to work =/
    iv'e switched the project to VC++ now, and have removed the menu.....here is the code that should display the window....everything compiles perfectly, but nothing happens when the button is pressed:

    Code:
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    			WORD wID     = LOWORD(wParam);
    			WORD wNotify = HIWORD(wParam);
    
    			if (lParam)
    				switch (wID) // Controls
    				{
    				case 10:
    				LvlEdit(hWnd, level_edit, button, GetModuleHandle(0));
    				if (!LvlEdit(hWnd, level_edit, button, GetModuleHandle(0)))
    						{
    							MessageBox(NULL, "LvlEdit() failed! Commiting suicide...", "Error", MB_OK | MB_ICONERROR);
    							DestroyWindow(hWnd);
    						}
    
    				break;
    
    				}
    			
    			return 0;
    }
    -psychopath

    --EDIT--
    this may be pointless, but here is the code for the button itself:
    Code:
    HWND button;
    button = CreateWindow("BUTTON", "Sprites", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 16, 40, 64, 24, menu_box,(HMENU) 10, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
    Last edited by psychopath; 06-22-2004 at 08:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL rendering problem
    By JJFMJR in forum Game Programming
    Replies: 8
    Last Post: 08-31-2007, 07:26 PM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM