Controls

This is a discussion on Controls within the Windows Programming forums, part of the Platform Specific Boards category; my question is Im making an MDI program, so when teh user clicks certain buttons, a new form will pop ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    215

    Controls

    my question is Im making an MDI program, so when teh user clicks certain buttons, a new form will pop up with different types of controls on them to set. Right now I only have one MDI, i mean I dont understand how to make a bunch of different types of windows. Lets say the user clicks button 1, then button 1 should then make a new window pop up and it should have certain controls, but then lets say they close that window and click button 2, a new window should come up with different controls as the first, and Im kind of puzzled on how to do that. Right now I only have one working and im trying to figure out how to make multiple ones with differing controls.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Just do this the normal way. Register a class and create a window procedure for every window type you want to support:
    Code:
    LRESULT CALLBACK WndProcSpreadSheet(HWND hwnd, ...)
    {
       // Window procedure for spread sheet...
       switch(uMsg)
       {
          case WM_CREATE:
          {
               // Create child controls here
          }
        }
        return DefMDIChildProc(...);
    }
    
    LRESULT CALLBACK WndProcEditor(HWND hwnd, ...)
    {
       // Window procedure for editor...
       switch(uMsg)
       {
          case WM_CREATE:
          {
               // Create child controls here
          }
        }
        return DefMDIChildProc(...);
    }
    
    ...
    
    wc.lpfnWndProc = WndProcSpreadSheet;
    wc.lpszClassName = TEXT("clsSpreadSheet");
    RegisterWindowEx(&wc);
    
    wc.lpfnWndProc = WndProcEditor;
    wc.lpszClassName = TEXT("clsEditor");
    RegisterWindowEx(&wc);
    and then just pass the appropriate class name to CreateMDIWindow().
    Code:
    if (bWantEditor)
    {
        CreateMDIWindow(..., TEXT("clsEditor"), ...);
    }
    else if (bWantSpreadSheet)
    {
        CreateMDIWindow(..., TEXT("clsSpreadSheet"), ...);
    }

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    215
    OK, got that down now im adding controls to this one window, but when I try to add strings to the combo box, it doesnt add.

    here's the code i put in the LRESULT CALLBACK MDI() function

    Code:
    ...
    
    			hWndComboTime1 = CreateWindow(
                "COMBOBOX", 
                "", 
                WS_VISIBLE | WS_CHILD | WS_GROUP | CBS_DROPDOWN, 
                165, 
                0, 
                200, 
                20, 
                hwnd, (HMENU)ID_TIME_COMBO1, 
                GetModuleHandle((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE)),NULL);
    
                if (!hWndComboTime1)
                    MessageBox(NULL, "ComboBox Failed.", "Error", MB_OK | MB_ICONERROR);
    
    
    	SendMessage(GetDlgItem(hWndComboTime1, ID_TIME_COMBO1), CB_ADDSTRING, 0,"Second(s)");
                SendMessage(GetDlgItem(hwnd, ID_TIME_COMBO1), CB_ADDSTRING, 0, "Minute(s)");
                SendMessage(GetDlgItem(hwnd, ID_TIME_COMBO1), CB_ADDSTRING, 0, "Hour(s)");
                SendMessage(GetDlgItem(hwnd, ID_TIME_COMBO1), CB_ADDSTRING, 0, "Day(s)");
    
    		 SendMessage(GetDlgItem(hwnd,ID_TIME_COMBO1),CB_SETCURSEL,1, 0);  
    			hfDefault = GetStockObject(DEFAULT_GUI_FONT);
    	
                SendMessage(hWndTimeRadio1, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    			SendMessage(hWndTimeRadio2, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    			SendMessage(hWndTimeEdit1, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    			SendMessage(hWndComboTime1, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    
    
    				}

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I'm not sure why it doesn't work, but there is no need to use GetDlgItem() when you already have the window handle:
    Code:
    SendMessage(hWndComboTime1, CB_ADDSTRING, 0, (LPARAM) TEXT("Second(s)"));

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    215
    Im thinking it where i create it in the CreateWindow thing, im suppose to have (HINSTANCE)GetWindowLong(hwnd, GWL, HINSTANCE) if i were just making it in the main window.

    here's the code, ill show you what im talking about.

    Code:
    	hWndComboTime1 = CreateWindow(
                "COMBOBOX", 
                NULL, 
                WS_VISIBLE | WS_CHILD | WS_GROUP | CBS_DROPDOWN, 
                165, 
                0, 
                200, 
                20, 
                hwnd, (HMENU)ID_TIME_COMBO1, 
                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),NULL);
    however i tried that already in the child it didnt work, and i changed that to GetModuleHandle((HINSTANCE)GetWindowLong(hwnd,GWL_ HINSTANCE)) and i also tried GetModuleHandle(NULL). But none of them worked. I used the GetModuleHandle because thats what the other controls use instead of hInstance in the main window creation.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    215
    Would this be easier if instead using and MDI type thing, i switch it to an SDI, and instead of using forms when pressing these buttons, have a dialog box come up with the stuff i need to set or reset?

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Sorry, I missed the problem. The height of a combo box includes the drop down portion. Change the height to 200 or so.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    215
    Excellent, thanks! it worked. I did change it to a dialog box instead however because I wanted the main form to be disabled when the next form came up, so I thought itd be better to use a dialog box instead. But thanks a lot.!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused about adding controls to main window
    By terracota in forum Windows Programming
    Replies: 4
    Last Post: 11-24-2004, 12:35 PM
  2. Subclassing controls
    By filler_bunny in forum Windows Programming
    Replies: 3
    Last Post: 04-28-2004, 06:43 PM
  3. I need help disabling Keyboard and Mouse input on Edit controls
    By Templario in forum Windows Programming
    Replies: 4
    Last Post: 01-07-2003, 12:59 AM
  4. MFC Controls and Thread Safety :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 12-06-2002, 11:36 AM
  5. Diff between window controls and dialog controls
    By Garfield in forum Windows Programming
    Replies: 13
    Last Post: 01-18-2002, 05:49 AM

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