How do you use combo boxes with a Doc View SDI Application
-
Hey Guys, I know the following might sound like a silly question, but I have a project which is a Doc-View SDI MFC project. Any way a requirement has emerged which means I need to use combo boxes in the actual view window. Does anyone have any experience at using something like this, In particular can you use a combo box in the view class of an SDI app? If so how do you incorporate it. Looking forward to your reply. Best Regards Danny Nowlan
-
Hey Guys, I know the following might sound like a silly question, but I have a project which is a Doc-View SDI MFC project. Any way a requirement has emerged which means I need to use combo boxes in the actual view window. Does anyone have any experience at using something like this, In particular can you use a combo box in the view class of an SDI app? If so how do you incorporate it. Looking forward to your reply. Best Regards Danny Nowlan
-
Hey Guys, I know the following might sound like a silly question, but I have a project which is a Doc-View SDI MFC project. Any way a requirement has emerged which means I need to use combo boxes in the actual view window. Does anyone have any experience at using something like this, In particular can you use a combo box in the view class of an SDI app? If so how do you incorporate it. Looking forward to your reply. Best Regards Danny Nowlan
Since controls are just windows you can use them as a child window on any window. An easy way is to add a CComboBox member to your window class:
CComboBox m_MyCombobox;
Add a WM_CREATE handler to the window class. In the handler call Create() for the combo box.
int CMyWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;m\_MyCombobox.Create(CBS\_DROPDOWN, CRect(10,10,100,15), this, IDC\_MYCOMBOBOX); ...possibly populate the combo box here using AddString() etc ... return 0;
}
This example places a 100 wide by 15 high CBS_DROPDOWN style combo box at 10,10 in the window. You could handle WM_SIZE in the window and move the combo box in response to the user resizing the window. Hope this helps get you started! Mark
-
Since controls are just windows you can use them as a child window on any window. An easy way is to add a CComboBox member to your window class:
CComboBox m_MyCombobox;
Add a WM_CREATE handler to the window class. In the handler call Create() for the combo box.
int CMyWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;m\_MyCombobox.Create(CBS\_DROPDOWN, CRect(10,10,100,15), this, IDC\_MYCOMBOBOX); ...possibly populate the combo box here using AddString() etc ... return 0;
}
This example places a 100 wide by 15 high CBS_DROPDOWN style combo box at 10,10 in the window. You could handle WM_SIZE in the window and move the combo box in response to the user resizing the window. Hope this helps get you started! Mark
Hey Mark, Thanks for that mate. I implemented it and I had no errors, however the Combo box still isn't showing up. I also created a IDC_MYCOMBOX resource with the type set to child. Any ideas? For what its worth I am dealing with a view that is derived from CView as opposed to CFormView. Is that part of my problem? Thanks again to everyone for all their help. Danny
-
Hey Mark, Thanks for that mate. I implemented it and I had no errors, however the Combo box still isn't showing up. I also created a IDC_MYCOMBOX resource with the type set to child. Any ideas? For what its worth I am dealing with a view that is derived from CView as opposed to CFormView. Is that part of my problem? Thanks again to everyone for all their help. Danny
Danny Nowlan wrote:
I implemented it and I had no errors, however the Combo box still isn't showing up.
Sorry :) The limited example code didn't have enough style flags. try
m_MyCombobox.Create(CBS_DROPDOWN|WS_VISIBLE|WS_CHILD, CRect(10,10,100,15), this, IDC_MYCOMBOBOX);
Calling MyCombobox.ShowWindow(SW_SHOW) would make it show as well. Useful if you want to create it hidden and show it later I suppose. Mark