Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Display one dialog image in another dialog Picture control

329 views
Skip to first unread message

Rasheed

unread,
Nov 18, 2008, 10:30:15 AM11/18/08
to

Hi All,
I have created a MFC Dialog based application and I have added a
picture control on it.
Now I have inserted another Dialog Resource from menu Insert ->
Resource -> Dialog-> New.
For the newly inserted Dialog, I have created a class
CFirstDialogPage. And I have added a picture control and added the
bitmap on the picture control.

Now I want show the Second dialog bitmap on the First Dialog Picture
control but I am unable to do that.
I have written the code like below in the First Dialog Ok button

void CTestingDlg::OnOK()
{

CRect rect;
CStepOnePage *pPage = new CStepOnePage();

if (pPage->Create(IDD_DIALOG1, this) == FALSE) ;
//IDD_DIALOG1 is the Newly created Dialog ID

CWnd *pWnd = GetDlgItem(IDC_SHEETRECT);
//IDC_SHEETRECT is the Picture control ID of the MainDialog(First
Application Dailog)
ASSERT(pWnd != NULL);
ASSERT(IsWindow(pWnd->m_hWnd) != FALSE);

pWnd->GetWindowRect(&rect);
pPage->ScreenToClient(&rect);
pPage->SetWindowPos(NULL, rect.left, rect.top, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
pPage->EnableWindow(TRUE);

pPage->ShowWindow(SW_SHOW);
pPage->InvalidateRect(NULL);
pPage->UpdateWindow();
//CDialog::OnOK();
}

But by this displaying the Second dialog but as individual
but i want to render the second dialog in the first Dialog but not as
a separate dialog (means Second dialog will be merged as a part of the
first dialog)


Thanks in advance.
Regards
Rasheed.

AliR (VC++ MVP)

unread,
Nov 18, 2008, 11:04:13 AM11/18/08
to
You will have to change the second dialogs style from popup to child. and
set the control property to true.

Here are some examples:
http://www.codeproject.com/KB/dialog/embedded_dialog.aspx
http://www.codeproject.com/KB/dialog/childdlg.aspx

AliR.


"Rasheed" <sk.rashe...@gmail.com> wrote in message
news:33cd7a08-33de-4c4a...@i20g2000prf.googlegroups.com...

Rasheed

unread,
Nov 18, 2008, 11:39:42 AM11/18/08
to
It’s much appreciated Job, i got the solution, i need to set the
control property to true.

Thanks Friend, thanks a lot

AliR (VC++ MVP)

unread,
Nov 18, 2008, 11:50:23 AM11/18/08
to
No problem.

The WS_CHILD style will allow you embed the dialog in another window/dialog.

The Control property will place the dialog in the parent dialogs tab order
so that you can tab into the dialog from a control on the parent dialog.

AliR.


"Rasheed" <sk.rashe...@gmail.com> wrote in message

news:e1136d2d-0e03-4988...@t39g2000prh.googlegroups.com...

Joseph M. Newcomer

unread,
Nov 18, 2008, 12:29:08 PM11/18/08
to
See below...

On Tue, 18 Nov 2008 07:30:15 -0800 (PST), Rasheed <sk.rashe...@gmail.com> wrote:

>
>Hi All,
>I have created a MFC Dialog based application and I have added a
>picture control on it.
>Now I have inserted another Dialog Resource from menu Insert ->
>Resource -> Dialog-> New.
>For the newly inserted Dialog, I have created a class
>CFirstDialogPage. And I have added a picture control and added the
>bitmap on the picture control.
>
>Now I want show the Second dialog bitmap on the First Dialog Picture
>control but I am unable to do that.

****
I presume you are referring to an image of the second dialog. What is the purpose of
this? There are several approaches to how you might do this
****


>I have written the code like below in the First Dialog Ok button
>
>
>
>void CTestingDlg::OnOK()
>{
>
> CRect rect;
> CStepOnePage *pPage = new CStepOnePage();
>
> if (pPage->Create(IDD_DIALOG1, this) == FALSE) ;

****
First, this is bad style; you would want to do CStepOnPage::IDD instead of IDD_DIALOG1,
and you should NEVER use those silly names like IDD_DIALOG1; you should change them to
something meaningful to you. But no matter what name you use, you would not use in in the
Create call.
****


>//IDD_DIALOG1 is the Newly created Dialog ID
>
> CWnd *pWnd = GetDlgItem(IDC_SHEETRECT);

****
Assume GetDlgItem is a dead method and should never be used except in exceptionally rare
and exotic circumstances, of which this is not an example. Right-click on the control and
do "Add Variable". Use that variable. If you are writing more than one GetDlgItem per
year, you are not using MFC correctly.
****


>//IDC_SHEETRECT is the Picture control ID of the MainDialog(First
>Application Dailog)
> ASSERT(pWnd != NULL);
> ASSERT(IsWindow(pWnd->m_hWnd) != FALSE);
>
> pWnd->GetWindowRect(&rect);
> pPage->ScreenToClient(&rect);
> pPage->SetWindowPos(NULL, rect.left, rect.top, 0, 0,
> SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
> pPage->EnableWindow(TRUE);
>
> pPage->ShowWindow(SW_SHOW);
> pPage->InvalidateRect(NULL);
> pPage->UpdateWindow();
> //CDialog::OnOK();
>}
>
>But by this displaying the Second dialog but as individual
>but i want to render the second dialog in the first Dialog but not as
>a separate dialog (means Second dialog will be merged as a part of the
>first dialog)

****
Do you want an image of the dialog, or do you want it to be a child dialog of the first
dialog? That is, do you want a *picture* of the dialog (easy enough to get) or do you
actually want a live set of controls displayed in the area?

To capture an image of the dialog, what I would do is have a button which only is visible
when _DEBUG is declared, e.g.,

#ifndef _DEBUG
c_CopyDialog.ShowWindow(SW_HIDE);
#endif

and this is on the first dialog. THen I'd add a handler:

void CMyDialog::OnBnClickedCopyDialog()
{
#ifdef _DEBUG
CStepOneDialog dlg;
dlg.capture = TRUE;
dlg.DoModal();
#endif
}

In the handler I'd do

BOOL CStepOneDialog::OnInitDialog()
{
...
#ifdef _DEBUG
if(capture)
{ /* capture it */
PostMessage(UWM_CAPTURE);
} /* capture it */
#endif
}

LRESULT CStepOnDialog::OnCapture(WPARAM, LPARAM)
{
#ifdef _DEBUG
...copy this to clipboard
...see my essay on capturing a window to a clipboard on my
... MVP Tips site
CDialog::OnCancel();
return 0;
#endif
}

Now I have a *picture* of the dialog that I can paste into Paint or a picture editor of my
choice, and save as a bitmap file, which I can just include as a picture file in the
original dialog. This is so I can show a picture of what will come next.

But if you want an active dialog shown on your original dialog, you would create a child
dialog (set the style to Child) and create it. Then you would do

CStepOneDialog c_ChildDialog;

in your class definition of your main dialog, and do

c_ChildDialog.Create(CStepOneDialog::IDD, ...);

note that no 'new' is required.
****


>
>
>Thanks in advance.
>Regards
>Rasheed.

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages