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!

Accessing Dialog Info from a parent Form

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
KR
Good Morning,
Here is my latest dilemma. I'm trying to print information from edit controls that are on a dialog box. I'm using MFC, and the dialog box is called from the main view, which is CFormView derived. I sent a message from the dialog to the View telling the view to print. In the OnPrint function I put the following code:

CEdit * pEdit1 = (CEdit *) GetDlgItem(IDC_NEWEDIT);
pEdit1->GetWindowText(string);

where IDC_NEWEDIT is the name of the edit control on the dialog box. Sadly, pEdit1 returns as NULL.

I thought then I could try

HWND hwndDialog = (HWND)GetDlgItem(IDD_PRINT_DIALOG);
GetDlgItem(IDC_NEWEDIT, &hwndDialog);

Where hwndDialog was a handle to the window that contained the editbox, but hwndDialog returned null as well.

Basically, I'm trying to pull information from a child window control to a CFormView derivitive. Anyone have any suggestions? The dialog box is active, has control, then sends a message to the view, which needs to pull information to it from the dialog box.

My other idea was rather than make the dialog box a dialog box, I could make it another CFormView subclass, but I could not figure out how to call that form from my main form.

Thanks for your help,

CJB
 
Hi

I've only looked at this quickly, but there seems to be one obvious error - you're not referencing your dialog in the OnPrint function (which I assume is a member of your view class). Your code should look something like this:

CMyDialog* pDlg;
// create dialog/set pointer to
// existing dialog here
CEdit* pEdit = (CEdit*)pDlg->GetDlgItem(IDC_NEWEDIT);
ASSERT(pEdit);

If you've used the MFC Class Wizard to create a class for your dialog resource, then data transfer between your dialog class and your view class should be dead easy because of MFC's dialog data transfer mechanism (DDX).

Hope this helps.


 
Phil,
Thanks for the suggestions, and they make sense. However, the problem I am having is getting that pointer to point to the dlgbox, or even getting a hWnd to that dialog box. If I could even get a hWnd to the dialog, I could use
GetDlgItem(m_hWnd, IDC_NEWEDIT) to access the dialog data. If you have any tips on getting the pointer set up, or getting a hWnd, I would really appriciate it.

CJB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top