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
Why do you call
Code:
pMainFrame->GetDlgItem(AFX_IDW_PANE_FIRST)
What are your expectations of the value retuned by this expression?
Why do you cast this CWnd* type to the CPreviewView*? Note that there is no any class in your project derived from CPreviewView!
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
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.
Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008
Originally Posted by deepakbidap
...
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
Originally Posted by deepakbidap
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".
Re: Migration of Print Preview code from VC++ 6.0 to VC++ 2008
Originally Posted by deepakbidap
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.