Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three dialogs say x,y and z in my application. On x dialog which is my main window, I am displaying some graphics using its OnPaint() function . Also I have placed a button 'b1' on 'x' . On click of b1, dialog 'y' pops up which have a 'preview button' on it .I want that clicking on 'preview' button opens dialog window 'z' with the same graphics that dialog 'x' has . For doing so, I have copied DC of x to DC of z using bitblt. But on 'z' , its showing the opened dialog windows y and z aswell mixing up with graphs of dialog 'x' .But I want only the graphs of my window x, no preview of opened dialog windows 'y' and 'z'. Is there any way to copy DC of my main dialog .
Posted

It would be a result,
if your m_pcX is not set... :)

Please post
your lines of constructing (instancing) of y and z :)
 
Share this answer
 
Assumed your z has a pointer to x and there is a function:

void x::OnDraw(CDC* pDC)
{
...
}


Now you coul call it form your
void x::OnPaint()
{
  CPaintDC dc(this);
  OnDraw(&dc)
}

...as well from your
void z::OnPaint()
{
  CPaintDC dc(this);
  px->OnDraw(&dc)
}


It would be a solution without any copying of DC... :)
 
Share this answer
 
As an alternative solution
you could provide an additional constructor of x:
x::x(const x& original, bool bHideB1 = true)
{
  // copy the members here...
...
  // and set a new member
  m_bHideB1 = bHideB1;
}

... and extend your
BOOL x::OnInitDialog()
{
...
  if (m_bHideB1) {
    CWnd* pcWnd = GetDlgItem(IDC_BUTTON1);
    if (pcWnd) {
      pcWnd->ShowWindow(SW_HIDE);
    }
  }
...
}

Now you could modify your "preview" reaction:
void y::OnPreview()
{
  x anotherX(*px); // here px is pointer to parent x dialog
  anotherX.DoModal();
}

It would be a solution without the class z... :)
 
Share this answer
 
Hi Eugen,

Thanks for the reply.But I would like to say that Answer1 suggested by you is giving some unhandled exception .And Answer2 will not suit as per my requirement coz I have different tool bars and buttons in my 'x' dialog window that I don't want to show in my preview :(
 
Share this answer
 
Hi Chandan,
could you post your debug stack at the exception, please ? :)


When not - you could call x::OnDraw(..) -
for a compatible memory DC for z
and then copy it to the DC of z... :)
 
Share this answer
 
v2
VB
CGraphChoosePreview::OnPaint() line 156 + 7 bytes
CWnd::OnWndMsg(unsigned int 15, unsigned int 0, long 0, long * 0x0303e500) line 1825
CWnd::WindowProc(unsigned int 15, unsigned int 0, long 0) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x0303e828 {CGraphChoosePreview hWnd=0x004d05ea}, HWND__ * 0x004d05ea, unsigned int 15, unsigned int 0, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x004d05ea, unsigned int 15, unsigned int 0, long 0) line 368
AfxWndProcBase(HWND__ * 0x004d05ea, unsigned int 15, unsigned int 0, long 0) line 220 + 21 bytes
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e428ea0()
USER32! 7e428eec()
NTDLL! 7c90e473()
CWnd::UpdateWindow() line 118 + 63 bytes
CWnd::RunModalLoop(unsigned long 4) line 3455
CDialog::DoModal() line 536 + 12 bytes
CGraphChoice::OnGraphPreview() line 1011
_AfxDispatchCmdMsg(CCmdTarget * 0x0303f298 {CGraphChoice hWnd=0x002103fa}, unsigned int 2294, int 0, void (void)* 0x00408b52 CGraphChoice::OnGraphPreview(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 2294, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CDialog::OnCmdMsg(unsigned int 2294, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 97 + 24 bytes
CWnd::OnCommand(unsigned int 2294, long 7276046) line 2088
CWnd::OnWndMsg(unsigned int 273, unsigned int 2294, long 7276046, long * 0x0303eadc) line 1597 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 2294, long 7276046) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x0303f298 {CGraphChoice hWnd=0x002103fa}, HWND__ * 0x002103fa, unsigned int 273, unsigned int 2294, long 7276046) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x002103fa, unsigned int 273, unsigned int 2294, long 7276046) line 368
AfxWndProcBase(HWND__ * 0x002103fa, unsigned int 273, unsigned int 2294, long 7276046) line 220 + 21 bytes
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e42927b()
USER32! 7e4292e3()
USER32! 7e44ff7d()
USER32! 7e4465d2()
USER32! 7e425e94()
USER32! 7e43b082()
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e42a013()
USER32! 7e42a998()
CWnd::DefWindowProcA(unsigned int 514, unsigned int 0, long 2162747) line 1000 + 32 bytes
CWnd::WindowProc(unsigned int 514, unsigned int 0, long 2162747) line 1586 + 26 bytes
AfxCallWndProc(CWnd * 0x0303f2f8 {CButton hWnd=0x006f060e}, HWND__ * 0x006f060e, unsigned int 514, unsigned int 0, long 2162747) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x006f060e, unsigned int 514, unsigned int 0, long 2162747) line 368
AfxWndProcBase(HWND__ * 0x006f060e, unsigned int 514, unsigned int 0, long 2162747) line 220 + 21 bytes
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e4189cd()
USER32! 7e418a10()
USER32! 7e4274ff()
USER32! 7e43c6d3()
CWnd::IsDialogMessageA(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 182
CWnd::PreTranslateInput(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 3424
CDialog::PreTranslateMessage(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 92
CWnd::WalkPreTranslateTree(HWND__ * 0x003103e4, tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 2667 + 18 bytes
CWinThread::PreTranslateMessage(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 665 + 18 bytes
CWinThread::PumpMessage() line 841 + 30 bytes
CWnd::RunModalLoop(unsigned long 4) line 3478 + 19 bytes
CDialog::DoModal() line 536 + 12 bytes
CPipeImView::ChooseGraphs() line 3095 + 11 bytes
CPipeImView::OnViewCalMainMenu() line 14423
_AfxDispatchCmdMsg(CCmdTarget * 0x003f7b60 {CPipeImView hWnd=0x004903d8}, unsigned int 33341, int 0, void (void)* 0x0040b5be CPipeImView::OnViewCalMainMenu(void), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 33341, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CView::OnCmdMsg(unsigned int 33341, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 159 + 24 bytes
CPipeImView::OnCmdMsg(unsigned int 33341, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 6815
CFrameWnd::OnCmdMsg(unsigned int 33341, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 890 + 33 bytes
CMainFrame::OnCmdMsg(unsigned int 33341, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 1009 + 24 bytes
CWnd::OnCommand(unsigned int 33341, long 5047758) line 2088
CFrameWnd::OnCommand(unsigned int 33341, long 5047758) line 317
CWnd::OnWndMsg(unsigned int 273, unsigned int 33341, long 5047758, long * 0x0303f7c8) line 1597 + 28 bytes
CWnd::WindowProc(unsigned int 273, unsigned int 33341, long 5047758) line 1585 + 30 bytes
AfxCallWndProc(CWnd * 0x003f6f08 {CMainFrame hWnd=0x003103e4}, HWND__ * 0x003103e4, unsigned int 273, unsigned int 33341, long 5047758) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x003103e4, unsigned int 273, unsigned int 33341, long 5047758) line 368
AfxWndProcBase(HWND__ * 0x003103e4, unsigned int 273, unsigned int 33341, long 5047758) line 220 + 21 bytes
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e42927b()
USER32! 7e4292e3()
COMCTL32! 5d0cb72d()
COMCTL32! 5d09f7d9()
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e42a013()
USER32! 7e42a998()
CWnd::DefWindowProcA(unsigned int 514, unsigned int 0, long 851984) line 1000 + 32 bytes
CWnd::WindowProc(unsigned int 514, unsigned int 0, long 851984) line 1586 + 26 bytes
CControlBar::WindowProc(unsigned int 514, unsigned int 0, long 851984) line 470 + 20 bytes
AfxCallWndProc(CWnd * 0x003f73dc {CToolBar hWnd=0x004d05ce}, HWND__ * 0x004d05ce, unsigned int 514, unsigned int 0, long 851984) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x004d05ce, unsigned int 514, unsigned int 0, long 851984) line 368
AfxWndProcBase(HWND__ * 0x004d05ce, unsigned int 514, unsigned int 0, long 851984) line 220 + 21 bytes
USER32! 7e418734()
USER32! 7e418816()
USER32! 7e4189cd()
USER32! 7e418a10()
USER32! 7e4274ff()
USER32! 7e43c6d3()
CWnd::IsDialogMessageA(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 182
CWnd::PreTranslateInput(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 3424
CControlBar::PreTranslateMessage(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 424
CWnd::WalkPreTranslateTree(HWND__ * 0x003103e4, tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 2667 + 18 bytes
CWinThread::PreTranslateMessage(tagMSG * 0x00dd8108 {msg=0x00000113 wp=0x00001000 lp=0x00000000}) line 665 + 18 bytes
CWinThread::PumpMessage() line 841 + 30 bytes
CWinThread::Run() line 480 + 11 bytes
CWinApp::Run() line 400
AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00041f2a, int 1) line 49 + 11 bytes
WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x00041f2a, int 1) line 30
WinMainCRTStartup() line 330 + 54 bytes
KERNEL32! 7c817077()
 
Share this answer
 
May be your pointer of x was not set correctly ? :)

What line does generate the exception ?

Is it px->OnDrraw(..);

You could set a breakpoint and observe the px by debugging :)


...or (assumed you construct your dialogs with passing of the parent(this))
you could try also the following test :) :

void z::OnPaint()
{
  CPaintDC dc(this);

  CWnd* pcWnd = GetParent();
  if (pcWnd) {
    x* pcX = (x*) pcWnd->GetParent();
    if (pcX) {
      pcX->OnDraw(&dc);
    }
  }
}
 
Share this answer
 
v3
yah, at
px->OnDraw(..);
only ,its throwing exception.I tried by setting breakpoint ,but its not going under OnDraw() function. :(
 
Share this answer
 
v2
Could you describe the transfer of px in to the z::OnPaint() please ?
 
Share this answer
 
v2
CWnd* pcWnd = GetParent();  
    if (pcWnd) 
    {    
        x* pcX = (x*) pcWnd->GetParent(); 
        if (pcX) 
        {      
            pcX->OnDraw(&dc);
        }

    }


I tried this too.But no luck.. Graph's preview is not coming. Window 'z'is visible blank.
 
Share this answer
 
v3
:)

No, so it can not go... :)

Please follow the insructions:

void x::OnSettings()
{
  y myY(this);
  myY.DoModal();
}


void y::OnPreview()
{
  z myZ(this);
  myZ.DoModal();
}


z::z(CWnd* pcParent)
: CDialog(IDD_z, pcParent)
{
  m_pcX = NULL; // please declare the new member in the header: x* m_pcX !
  if (pcParent) {
    m_pcX = (x*) pcParent->GetParent();
  }
}


void z::OnPaint()
{
  CPaintDC dc(this);

  if (m_pcX) {
    m_pcX->OnDraw(&dc);
  }
}


Good luck :)
 
Share this answer
 
v2
still blank window is coming with no graphs :(
 
Share this answer
 
It worked.Thank U very much :) :) :) :) :-D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900