HELP!Beginner Help with GetDlgItem and ComboBox
Hi,
I know how to use GetDlgItem to get a HWND to a control and how to set/get text.
Are there any decent guides on how to work with the actual controls outside of MFC. I.e. I have a combo that I want to populate at run time.
Probably a really simple question to answer for some of you!
Cheers,
Paul.
[347 byte] By [
beecheyp] at [2007-11-19 11:36:18]

# 1 Re: HELP!Beginner Help with GetDlgItem and ComboBox
First, GetDlgItem() returns a CWnd*, not a HWND (and yes, CWnd provides an HWND operator).
Now, do you actually ask how to populate a combo boxe with Win API? Then basically, you have to send LB_ADDSTRING to the list box of the combo.
cilu at 2007-11-11 0:07:59 >

# 2 Re: HELP!Beginner Help with GetDlgItem and ComboBox
Just use MSDN
# 3 Re: HELP!Beginner Help with GetDlgItem and ComboBox
MFC is mostly just a wrapper around WIN32 APIs. If you have VC installed, you should be able to find MFC source codes (unless you unchecked this option during installation). In MFC source files you can find pretty easily how to insert item to combo box, clear listbox, and whole lot of other stuff without use of MFC. Example:
_AFXWIN_INLINE int CComboBox::GetCount() const
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0); }
I think that this all is also written somewhere at MSDN, but its easier for me to find info in CPP files with 'Go to definition' command.
Hob
Hobson at 2007-11-11 0:09:57 >

# 4 Re: HELP!Beginner Help with GetDlgItem and ComboBox
First, GetDlgItem() returns a CWnd*, not a HWND (and yes, CWnd provides an HWND operator).
I think that OP means ::GetDlgItem
HWND GetDlgItem(HWND hDlg, int nIDDlgItem);
Hob
Hobson at 2007-11-11 0:11:05 >

# 5 Re: HELP!Beginner Help with GetDlgItem and ComboBox
I think that OP means ::GetDlgItem
HWND GetDlgItem(HWND hDlg, int nIDDlgItem);
Oops. My bad. Sorry. I was misled by the MFC reference.
cilu at 2007-11-11 0:12:03 >

# 6 Re: HELP!Beginner Help with GetDlgItem and ComboBox
Hi,
I know how to use GetDlgItem to get a HWND to a control and how to set/get text.
Are there any decent guides on how to work with the actual controls outside of MFC. I.e. I have a combo that I want to populate at run time.
Probably a really simple question to answer for some of you!
Cheers,
Paul.
just check it out in MSDN
you can found various method of combo box and for you
you can use
CComboBox::InsertString
which takes 2 parameter first is index,where to insert and second is string which to be insert
# 7 Re: HELP!Beginner Help with GetDlgItem and ComboBox
you can found various method of combo box and for you you can use CComboBox::InsertStringIsn't that an MFC function? :rolleyes:
# 8 Re: HELP!Beginner Help with GetDlgItem and ComboBox
Are there any decent guides on how to work with the actual controls outside of MFC. I.e. I have a combo that I want to populate at run time.Without using MFC, the usual way to communicate with controls is by sending them messages. For example, the combobox-related messages (like CB_ADDSTRING, CB_INSERTSTRING etc.) all begin with CB_. See MSDN for details - for example, to see the documentation for comboboxes, look here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxes.asp). For an overview of all controls, see here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/wincontrols.asp).