I have a dialog based MFC app. I have a button that spawns a new dialog with an image in it. I want to have a second buttong that pops up a dialog with a different image. Both images require a bit of computing to make, but a lot of the code is the same. I'd like to be able to reuse the dialog and its class for both instances. Is this possible? In other words, can I tell the newly spawned dialog who called it?
My thought was to create a dialog and have it flagged so it didn't do anything, then call a function that changes the flag & calls OnPaint, which would then allow either image to be built. Something like this:
Code:
void CFrameDlg::OnBnClickedPreview()
{
CPreviewDlg Dlg;
Dlg.buildPreview();
Dlg.DoModal();
}
... then CPreviewDlg's OnPaint would look like this:
Code:
void CPreviewDlg::OnPaint()
{
if (preview)
// do preview stuff
if (input)
// do input stuff
else
CPaintDC dc(this);
}
In this example, buildPreview() sets a flag in the CPreviewDlg class so that when OnPaint is called, it will assemble the correct image, however, I can't seem to get buildPreview() to call OnPaint. I've tried RedrawWindow, UpdateWindow, and CDialog::OnPaint, but none of them work. Am I making the call wrong, or is this just wrong all together?
FYI: my attempts at CPreview::buildPreview() have looked like this:
Code:
method 1:
preview = true;
CDialog::OnPaint();
method 2:
peview = true;
CRect framerect;
this->GetWindowRect(framerect);
RedrawWindow(framerect, NULL, RDW_INTERNALPAINT);
method 3:
preview = true;
Invalidate();
UpdateWindow();