Thread: MDI and MENU Problem

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    28

    MDI and MENU Problem

    Hi,

    I have a problem enabling and disabling certain parts of a menu.

    When my MDI Child windows are minimized or not maximized the menu works correctly.
    But if they are maximized the menu fails to be changed.

    Any ideas as to what could be wrong?

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Ok, i have sorted out that problem but now i have another..

    Code:
    LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CREATE:
    		{
    			HFONT hfDefault;
    			HWND hEdit;
    
    			hEdit = CreateWindowEx(0, "RICHEDIT", "", 
    				WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_DISABLENOSCROLL |
    				ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL, 
    				0, 0, 100, 100, hwnd, (HMENU)IDC_CHILD_EDIT, GetModuleHandle(NULL), NULL);
    
    			hfDefault = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
    			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    		}
    		break;
    
    		case WM_MDIACTIVATE:
    		{
    			HMENU hMenu, hFileMenu;
    			UINT EnableFlag;
    
    			hMenu = GetMenu(g_hMainWindow);
    			if(hwnd == (HWND)lParam)
    			{
    				EnableFlag = MF_ENABLED;
    			}
    			else
    			{
    				EnableFlag = MF_GRAYED;
    			}
    
    			EnableMenuItem(hMenu, 1, MF_BYPOSITION | EnableFlag);
    			EnableMenuItem(hMenu, 2, MF_BYPOSITION | EnableFlag);
    
    			hFileMenu = GetSubMenu(hMenu, 0);
    			EnableMenuItem(hFileMenu, IDM_FILE_SAVEAS, MF_BYCOMMAND | EnableFlag);
    
    			EnableMenuItem(hFileMenu, IDM_FILE_CLOSE, MF_BYCOMMAND | EnableFlag);
    			EnableMenuItem(hFileMenu, IDM_FILE_CLOSEALL, MF_BYCOMMAND | EnableFlag);
    
    			DrawMenuBar(g_hMainWindow);
    		}
    		break;
    
    		case WM_CLOSE:
    		{
    			DestroyWindow(hwnd);
    		}
    		break;
    
    		case WM_COMMAND:
    		{
    			switch(LOWORD(wParam))
    			{
    				case IDM_EDIT_CUT:
    				{
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_CUT, 0, 0);
    				}
    				break;
    
    				case IDM_EDIT_COPY:
    				{
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_COPY, 0, 0);
    				}
    				break;
    
    				case IDM_EDIT_PASTE:
    				{
    					SendDlgItemMessage(hwnd, IDC_CHILD_EDIT, WM_PASTE, 0, 0);
    				}
    				break;
    			}
    		}
    		break;
    
    		case WM_SIZE:
    		{
    			HWND hEdit;
    			RECT rcClient;
    
    			GetClientRect(hwnd, &rcClient);
    
    			hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
    			SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
    		}
    		return DefMDIChildProc(hwnd, msg, wParam, lParam);
    
    		default:
    		return DefMDIChildProc(hwnd, msg, wParam, lParam);
    	}
    	return 0;
    }
    The code above is my MDI CHILD Callback.
    When i close one of the MDI Child windows, the window closes but the minimize, maximize and close buttons remain along the menu bar. The more windows that get closed the more the buttons mount along the Menu bar.

    Is this the correct way to close the child windows?

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    An application sends the WM_MDIDESTROY message to a MDI client window to close an MDI child window.
    DefMDIChildProc may do this if given the chance.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Thanks for the help anonytmouse.

    That was exactly what i was missing!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu like file, edit, help, etc...
    By Livijn in forum Windows Programming
    Replies: 44
    Last Post: 01-23-2007, 05:49 PM
  2. Window menu question
    By axr0284 in forum Windows Programming
    Replies: 0
    Last Post: 03-08-2005, 09:01 AM
  3. menu check problem
    By SuperNewbie in forum Windows Programming
    Replies: 5
    Last Post: 11-22-2003, 06:34 PM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. MDI and Child menu's
    By novacain in forum Windows Programming
    Replies: 0
    Last Post: 11-11-2001, 09:27 PM