Solved

Initializing ComboBox inside CDialogBar

Posted on 1998-11-30
3
412 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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