Migration of Print Preview code from VC++ 6.0 to VC++ 2008 - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23

Thread: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

  1. #16
    Join Date
    Oct 2003
    Location
    Bangalore
    Posts
    25

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    The code is present in OnDraw() function.
    Attached Files Attached Files

  2. #17
    Join Date
    Oct 2003
    Location
    Bangalore
    Posts
    25

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    Original code,
    CPreviewView* pPreviewView = DYNAMIC_DOWNCAST(CPreviewView, pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    CWnd* pToolBar = pMainFrame->GetDlgItem(AFX_IDW_PREVIEW_BAR);

    Here during debugging,found that,

    pPreviewView=0x00000000
    pToolBar=0x00000000

    I found something,

    The code,
    CPreviewView* pPreviewView = DYNAMIC_DOWNCAST(CPreviewView, pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    when corrected to,
    CPreviewView* pPreviewView= (CPreviewView *)(pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    gives results
    Last edited by deepakbidap; July 25th, 2013 at 04:00 AM.

  3. #18
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    Well, the reason pPreviewView is NULL is you are trying to cast some CWnd* pointer to the CPreviewView* type while the object of this CWnd* is NOT a kind of CPreviewView class! Just read about DYNAMIC_DOWNCAST in MSDN:
    The DYNAMIC_DOWNCAST macro provides a handy way to cast a pointer to a pointer to a class object while checking to see if the cast is legal. The macro will cast the pointer parameter to a pointer to an object of the class parameter's type.

    If the object referenced by the pointer is a "kind of" the identified class, the macro returns the appropriate pointer. If it isn't a legal cast the macro returns NULL.
    Now, please explain
    1. Why do you call
      Code:
      pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST)
      What are your expectations of the value retuned by this expression?
    2. Why do you cast this CWnd* type to the CPreviewView*? Note that there is no any class in your project derived from CPreviewView!
    Victor Nijegorodov

  4. #19
    Join Date
    Oct 2003
    Location
    Bangalore
    Posts
    25

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    1.The Project what I am working is a menu based display software,wherein each menu or submenu or each tab is considered as a pane will be displayed as a page in the print preview.The return value of
    pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST)
    is a handle to the pane(It's a CWnd* object)
    2.The above thing explains

  5. #20
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    Quote Originally Posted by deepakbidap View Post
    The code,
    CPreviewView* pPreviewView = DYNAMIC_DOWNCAST(CPreviewView, pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    when corrected to,
    CPreviewView* pPreviewView= (CPreviewView *)(pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    gives results
    Yes, but only because you have faked the compiler!
    It is just the same as in this example:
    Code:
    CWnd wnd;
    CPreviewView* pPreviewView = (CPreviewView *)&wnd;
    
    pPreviewView->SetPrintView(this);
    and what you get is:
    Unhandled exception at 0x78ad6805 (mfc90ud.dll) in test.exe
    So if you want to cast in a c-style then you have to check using
    Code:
    	ASSERT_KINDOF(CPreviewView, pPreviewView);
    Victor Nijegorodov

  6. #21
    Join Date
    Oct 2003
    Location
    Bangalore
    Posts
    25

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    I have got a mail,I found in the google,

    HTML Code:
    Hi Greg, 
    
    The print preview window in VC6 is not a child window of the MDI mainframe*
    window, when being called it will be displayed to replace the mainframe*
    window, and the mainframe window would be hidden. But in MFC7, the print*
    preview window is a child window of the MDI mainframe window, so it will be*
    contained mainframe window and seems to be somehow "broken".
    However, I don't think it is a bug to MFC7, it just a different*
    implementation from the MFC6's implementation, and under MFC7's scenario I*
    suggest you can maximize the print preview window while it is been called...
    Thanks for your understanding!
    Best regards,
    Gary Chang
    Microsoft Online Partner Support
    Does this mean,I have to implement the Print Preview part from the scratch in Visual Studio 2008.

  7. #22
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,392

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    Quote Originally Posted by deepakbidap View Post
    ...
    Does this mean,I have to implement the Print Preview part from the scratch in Visual Studio 2008.
    I don't know!
    From your "explanation" of your problem
    Quote Originally Posted by deepakbidap View Post
    1.The Project what I am working is a menu based display software,wherein each menu or submenu or each tab is considered as a pane will be displayed as a page in the print preview.The return value of
    pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST)
    is a handle to the pane(It's a CWnd* object)
    it is not obvious that you would need to "implement the Print Preview part from the scratch".
    Victor Nijegorodov

  8. #23
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008

    Quote Originally Posted by deepakbidap View Post
    I found something,

    The code,
    CPreviewView* pPreviewView = DYNAMIC_DOWNCAST(CPreviewView, pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    when corrected to,
    CPreviewView* pPreviewView= (CPreviewView *)(pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST));
    gives results
    Do you understand what a C-style cast does? It does not convert from one type to another.
    Code:
    class Car
    {
        public:
           void StartEngine() {}
    };
    
    class Elephant
    {
    };
    
    int main()
    {
       Elephant e;
       Car* pCar = (Car*)&e;
       pCar->StartEngine();
    }
    I just turned an Elephant into a Car by casting the pointer, right? Wrong.

    That is exactly what you are doing when you blindly cast pointers and assume they magically turn the object into whatever you want it to be. If the object T is not a U, casting a pointer to T to a pointer to U doesn't make a T into a U.

    Regards,

    Paul McKenzie

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center