Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access controlls on dialog bar?

Status
Not open for further replies.

MrSandman666

Programmer
Feb 5, 2001
54
0
0
DE
Hi guys.

It's been a while but still feels good to be back again. I'm slowly picking up programming again and right now I'm trying to get an MDI application together, which includes a few dialog bars. I'm an absolute newbie when it comes to MFC, so please be kind.
I know how to create and midify the Dialog Bar and I know how to process events from the controlls contained in it. However, till now I've had no luck whatsoever in actually accessing these controlls. I can not read the value of an edit controll or change it's properties. I can't populate a treeview, etc. Well, you get the idea.
I'm currently doing this:

void CMainFrame::OnRolldice()
{
CString Result;
CEdit* cNumberOfDice = (CEdit*)GetDlgItem(IDC_DR_DICE);

int len = cNumberOfDice->LineLength(cNumberOfDice->LineIndex(0));
cNumberOfDice->GetLine(0, Result.GetBuffer(len), len);
Result.ReleaseBuffer(len);

MessageBox(Result);
}

This works, except for the fact that GetDlgItem always returns NULL! Therefore, I get an access violation each time I run this code.

Any help? Please?
 
Oh yeah, I forgot to mention:
I can not assign member variables to the controlls, as would be expected. Since the Dialog Bar doesn't have it's own class derived, like a FormView would, it doesn't show up in the class wizard.
 
>> Since the Dialog Bar doesn't have it's own class
>> derived, like a FormView would, it doesn't show up in
>> the class wizard.

make a class for the dialog (using Class Wizard). You are in control. Resistance is futile. [lol]

-pete
 
The problem is that you usually don't derive classes from the CDialogBar class.
And the class wizard doesn't support deriving from CDialogBar either. Of course, I could do it manualy but there has to be another way!
 
Alright, never mind! I found the solution in another forum. I guess this is a typical newbie-fault.
Of course, it has to look like this:
CEdit* cNumberOfDice = (CEdit*)m_wndDlgBar.GetDlgItem(IDC_DR_DICE);
[2thumbsup]
 
Yeah that works. You can create a CDialog class for the resource using class wizard and then use search and replace to change "CDialog" to "CDialogBar" and you then have a class for the dialog bar. You can create member variables using class wizard etc.

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top