Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with CComboBox.AddString() in modal dialog

247 views
Skip to first unread message

Jean Libera

unread,
Dec 28, 1996, 3:00:00 AM12/28/96
to

I am having a problem with CComboBox.AddString(). The combo box is
part of a modal dialog box, and I am adding the strings during the
OnInitDialog() method. The CComboBox is referenced through a member
variable which I created using the Class Wizard.

I am trying to add 4 strings:

int errorCode = m_mybox.AddString(L"Jean");
errorCode = m_mybox.AddString(L"Joseph");
errorCode = m_mybox.AddString(L"Natasha");
errorCode = m_mybox.AddString(L"Daniel");

The error codes are 0 for all except the 3rd string, which has an error code
of -2. After adding the 4 strings, I check the number of strings in the
combo box, and it is 4. I have even retrieved a few of the strings out of the
combo box, and they look OK.

However, the dialog box is actually displayed, using DoModal(), none of the 4
strings in the combo box is visible.

Has anyone ever seen anything like this? I would be very grateful for any
suggestions.

I am using VC4.2 with UNICODE on Windows NT 4.0.

Jean Libera
jli...@mcs.com


Rail J. Rogut

unread,
Dec 28, 1996, 3:00:00 AM12/28/96
to Jean Libera

Hi Jean,

This is a trap many of us have climbed out of... In the resource editor
click on the down arrow of the combo box and you can set a size for the
drop down portion of the combo box.

Good luck.

Rail
Oceanway Recording
rai...@earthlink.net

Chris Marriott

unread,
Dec 28, 1996, 3:00:00 AM12/28/96
to

In article <jlibera.6...@mcs.com>, Jean Libera <jli...@mcs.com>
writes

>I am having a problem with CComboBox.AddString(). The combo box is
>part of a modal dialog box, and I am adding the strings during the
>OnInitDialog() method. The CComboBox is referenced through a member
>variable which I created using the Class Wizard.
>
>I am trying to add 4 strings:
>
>int errorCode = m_mybox.AddString(L"Jean");
>errorCode = m_mybox.AddString(L"Joseph");
>errorCode = m_mybox.AddString(L"Natasha");
>errorCode = m_mybox.AddString(L"Daniel");
>
>The error codes are 0 for all except the 3rd string, which has an error code
>of -2. After adding the 4 strings, I check the number of strings in the
>combo box, and it is 4. I have even retrieved a few of the strings out of the
>combo box, and they look OK.
>
>However, the dialog box is actually displayed, using DoModal(), none of the 4
>strings in the combo box is visible.
>
>Has anyone ever seen anything like this? I would be very grateful for any
>suggestions.

My only suggestion is that you read the documentation more carefully.
The return value from the "AddString" command is NOT, in general, an
error code!

Chris

----------------------------------------------------------------
Chris Marriott, SkyMap Software, U.K. e-mail: ch...@skymap.com
Creators of fine astronomy software for Windows.
For full details, visit our web site at http://www.skymap.com


Shen Wenjun

unread,
Dec 29, 1996, 3:00:00 AM12/29/96
to

In article <jlibera.6...@mcs.com>, Jean Libera <jli...@mcs.com>
writes
>I am having a problem with CComboBox.AddString(). The combo box is
>part of a modal dialog box, and I am adding the strings during the
>OnInitDialog() method. The CComboBox is referenced through a member
>variable which I created using the Class Wizard.
>
>I am trying to add 4 strings:
>
>int errorCode = m_mybox.AddString(L"Jean");
>errorCode = m_mybox.AddString(L"Joseph");
>errorCode = m_mybox.AddString(L"Natasha");
>errorCode = m_mybox.AddString(L"Daniel");
>
>The error codes are 0 for all except the 3rd string, which has an error
code
>of -2. After adding the 4 strings, I check the number of strings in the
>combo box, and it is 4. I have even retrieved a few of the strings out of
the
>combo box, and they look OK.
>
>However, the dialog box is actually displayed, using DoModal(), none of
the 4
>strings in the combo box is visible.
>
>Has anyone ever seen anything like this? I would be very grateful for any

>suggestions.

1. .AddString() returns the zero-based index to the string you added, or
CB_ERR/CB_ERRSPACE if an error occurs. So it does not always return error
code. Please refer to the VC online book.

2. Please check the size of your Combobox, be sure that it is enough to
show all your strings.

3. Put base dialog class's OnInitDialog() first during your own method.
Like below:
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();

... // puts your codes here

return TRUE;
}

Good luck.
--
Shen Wenjun
Dept. of Physics, Fudan University, Shanghai 200433, P.R.C.
wjs...@fudan.edu.cn

Jean Libera

unread,
Dec 30, 1996, 3:00:00 AM12/30/96
to

Thanks to all who responded. As mentioned by several people, the problem was that
the height of the drow down portion of the combo box was incorrectly set. I think
that I didn't notice that you could set this because it was so close to 0.

It seems that when you are using the resource editor, if you click in the text-entry
portion of the list box, you get selection handles which allow you to adjust the
width of the combo box. If you click on the down arrow at the far right, you get
selection handles which allow you to adjust the height of the drop down part of the
list box.

Thanks again!

Jean Libera


0 new messages