-
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.
-
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"), ...);
}
-
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));
}
-
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)"));
-
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.
-
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?
-
Sorry, I missed the problem. The height of a combo box includes the drop down portion. Change the height to 200 or so.
-
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.!