• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:


I have a dialog-based application, created with the assistent.
I added some member-functions. One of these functions returns the chosen value from a CCombo-box element by calling the CDialog-member-function


when I now create a new CServiceInformatorDlg e.g.newobject
and want to access the GetItem() function which wrapps the GetDlgItemText-function like
newobject.GetItem() NULL is returned.

Whats the problem with my code?

 void CServiceInformatorDlg::GetItem(CString &rProgname)

void CServiceInformatorDlg::OnButton1()
CString rock;
CServiceInformatorDlg test;

Message Box stays empty
1 Solution
You Should try this.

in the GetItem function.

CString Dummy;
GetDlgItemText(IDC_COMBO1, rProgName);
Dummy = rProgName

in OnButtonFunction

CString rock;

ooops in the GetItem Functions declaration put this

GetItem(CString* rProgName)
Well creating a new CServiceInformatorDlg in the OnButton1() doesn't in itself create a window of any type. In fact it just calls your dialog's constructor.

My question to you is... Do you just want to get the information from the combobox for the dialog you are currently processing? If so then just call GetItem(rock) like so:

void CServiceInformatorDlg::OnButton1()
CString rock;

Good Luck,
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Vinayak KumbarSr Program ManagerCommented:

Lot of confusions.....,

Why U want to use
in the same class?. Instead straight away use


And here
>void CServiceInformatorDlg::OnButton1()
>CString rock;
>CServiceInformatorDlg test;

>CServiceInformatorDlg test; creates a new object of CServiceInformatorDlg  class. So test will be created by calling the constructor of the CServiceInformatorDlg class. I think U R inserting the strings to combo in the OnInitDialog function. But now U have not called that function yet. So Ur combo is empty. So U dont get anything. And Ur message box remains empty!!!.

Hope I explained U, the thing what u were doing.

BoogieBoyAuthor Commented:
Yes U r right.
Thats kind of useless to call a new CServiceInformatorDlg object. I am fillin Combo in OnInitDialog.

But the problem is located elsewhere: I have a new dialog CInfoDialog : CDialog and need the Combo data in there. So trying to call GetItem() member function of CServiceInformatorDlg doesnt work. I have to derive CInfoDialog from CServiceInformatorDlg and I dont know how to do this when I create a new dialog with the assistent  the assistent doesnt offer CServiceInformatorDlg as base-class. How do I teach it my base-class?

Is this the right anyway?

thanx for participating
So which one are you trying to do?

Call GetItem() on a CServiceInformatorDlg from a CInfoDialog


Derive CInfoDialog from a CServiceInformatorDlg

To call GetItem() from a CInfoDialog, you need to provide the CInfoDialog with a pointer/reference to the CServiceInformatorDlg, then use that reference to call GetItem()

so make a member variable:

CServiceInformatorDlg* m_pSID;

And a member function

SetSID(CServiceInformatorDlg* pSID)
   m_pSID = pSID;

Then when you want to call GetItem from CInfoDialog use

CString str

To derive from a CServiceInformatorDlg create a new class derived from CDialog, then change all the words CDialog to CServiceInformatorDlg in the header and CPP files, and modify the constructor of CServiceInformatorDlg to take a UINT:

CServiceInformatorDlg (UINT nID, CWnd* pParent = NULL);   // standard constructor

Then in your derived class' constuctor
CInfoDialog::CInfoDialog(CWnd* pParent) :
CServiceInformatorDlg(CServiceInformatorDlg::IDD, pParent)  
BoogieBoyAuthor Commented:
I dont get the point. I want to call GetItem from CInfo Dialog and implemented a membervariable and the memberfunction. But where in the code do I have to call GetItem() via the m_pSID variable?

When I call GetItem() via an BNClick event the programm terminates. Do I have to call it in the implementaion of CInfo Dialog::SetSID(..) and when yes, what is the parameter I have to call SetSID with?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now