Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Initializing ComboBox inside CDialogBar

Posted on 1998-11-30
3
Medium Priority
?
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

719 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