Solved

Initializing ComboBox inside CDialogBar

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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