Solved

Initializing ComboBox inside CDialogBar

Posted on 1998-11-30
3
342 Views
Last Modified: 2013-11-20
I am trying to initialize a CComboBox control in a CDialogBar created with the Resource editor.  I attach the tool bar to a Child Window in an MDI app.  I want to fill the contents of the CboBox when the tool bar is loaded.

This is how I am trying to do it...
-- inside   CMyChildFrm::OnCreate(....)
CComboBox* pCombo;

pCombo = (CComboBox*)GetDlgItem(IDC_COMBOBOX);
pCombo->AddString("SomeString");

I am sure I am just overlooking something, what am I doing wrong???

The assertion error occurs when the pCombo->AddString("") is attempted.  It is an Access Violation.

What is the proper casting and access method?

Thanks,
J.R.
0
Comment
Question by:jrmcg
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 100 total points
ID: 1325504
Put a breakpoint and check the status of the pCombo variable, it points to nothing.

You cannot ask your child frame to give you a pointer to IDC_COMBOBOX since that combobox belongs to your dialogbar.

Your childframe can ask the dialogbar for a pointer to that object once that dialogbar is created.

CComboBox* pCombo;
CDialogBar* pBar;
pCombo = (CComboBox*)pBar->GetDlgItem(IDC_COMBOBOX);
if( pCombo != NULL && pCombo->IsKindOf(CComboBox) ) {
  pCombo->AddString("SomeString");
}

0
 
LVL 3

Expert Comment

by:plaroche
ID: 1325505
Sorry, in my answer pBar will be invalid. What I meant was that pBar should be a pointer to your previously created dialogbar object.
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1325506
That did it.  Thanks.  I knew it would be something simple.

J.R.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now