gurushree
asked on
Adding a print option for a dialog box.
I have a dialog box with tree ctrl, List ctrl, List box on it. I want to print the whole dialog box as it is. How do i do that?
ASKER
Hi,
I tried the solution you had given. BUt the problem is getting the printer DC to pass in Print() function. I tried getting the peinter attributes by calling , CWinApp::GetPrinterDeviceD efaults(). This function returns a PRINTDLG structure from ehich one can get the HDC value. I passed this HDC value to Print() function, still it did not work. So can you suggest a solution to this so that I can get complete solution for my question.
Thanks ,
Gurushree
I tried the solution you had given. BUt the problem is getting the printer DC to pass in Print() function. I tried getting the peinter attributes by calling , CWinApp::GetPrinterDeviceD
Thanks ,
Gurushree
You can get the printer dc by using the following code.
CDC PrnDC;
PRINTDLG PrintDlg;
BOOL bSucc = ::AfxGetApp()->GetPrinterD eviceDefau lts(&Print Dlg) && ::AfxGetApp()->CreatePrint erDC(PrnDC );
if (bSucc)
....
else
....
CDC PrnDC;
PRINTDLG PrintDlg;
BOOL bSucc = ::AfxGetApp()->GetPrinterD
if (bSucc)
....
else
....
ASKER
Hi,
Again I am having problem with printing the dialog box contents. I tried different combinations . In my dialog box I am having a print button. On clicking the print button , I am doing the following,
CDC PrintDC ;
PRINTDLG PrintDlg ;
BOOL bRes = AfxGetApp()->GetPrinterDev iceDefault s(&PrintDl g) && ::AfxGetApp()->CreatePrint erDC(Print DC) ;
if ( bRes )
{
this->Print(&PrintDC, PRF_CHECKVISIBLE) ;
this->Print(&PrintDC, PRF_CLIENT) ;
this->Print(&PrintDC, PRF_NONCLIENT) ;
this->Print(&PrintDC, PRF_CHILDREN) ;
this->Print(&PrintDC, PRF_CLIENT) ;
this->Print(&PrintDC, PRF_ERASEBKGND) ;
}
ReleaseDC(&PrintDC) ;
bRes is TRUE, still the print function does not work. Can u correct me where i am wrong.
Thanks,
Gurushree
Again I am having problem with printing the dialog box contents. I tried different combinations . In my dialog box I am having a print button. On clicking the print button , I am doing the following,
CDC PrintDC ;
PRINTDLG PrintDlg ;
BOOL bRes = AfxGetApp()->GetPrinterDev
if ( bRes )
{
this->Print(&PrintDC, PRF_CHECKVISIBLE) ;
this->Print(&PrintDC, PRF_CLIENT) ;
this->Print(&PrintDC, PRF_NONCLIENT) ;
this->Print(&PrintDC, PRF_CHILDREN) ;
this->Print(&PrintDC, PRF_CLIENT) ;
this->Print(&PrintDC, PRF_ERASEBKGND) ;
}
ReleaseDC(&PrintDC) ;
bRes is TRUE, still the print function does not work. Can u correct me where i am wrong.
Thanks,
Gurushree
First, PrintDC is an object, the DC will be released when the destructor is executed. So, no need to ReleaseDC(&PrintDC).
Second, you should figure out which part does not work. For example, use TextOut to test whether it prints out anything. Or, use CPrintDialog to get the printer DC.
Third, I don't think keeping Print wiht different flags is a good way to test it. Some flags need to be combined.
Second, you should figure out which part does not work. For example, use TextOut to test whether it prints out anything. Or, use CPrintDialog to get the printer DC.
Third, I don't think keeping Print wiht different flags is a good way to test it. Some flags need to be combined.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Again the problem is getting the printer DC. I have a button in dialog box called "Print", so when i click on that button , it should print the dialog box along with the controls. In the handler of Print button, i am having the following code :
{
CPrintDialog dlg(FALSE);
dlg.GetDefaults();
SendMessage(WM_PRINT, (WPARAM)(dlg.m_pd.hDC), PRF_NONCLIENT | PRF_CHILDREN | PRF_CLIENT );
}
If i pass the display device context , by calling GetDC(), Clicking on print button, prints the dialog on display. But nothing happens if i pass printer dc as shown above. I also tried displaying CPrintDialog and calling GetPrinterDC(), Hope i have made my problem clear.
Thanks,
Gurushree
Again the problem is getting the printer DC. I have a button in dialog box called "Print", so when i click on that button , it should print the dialog box along with the controls. In the handler of Print button, i am having the following code :
{
CPrintDialog dlg(FALSE);
dlg.GetDefaults();
SendMessage(WM_PRINT, (WPARAM)(dlg.m_pd.hDC), PRF_NONCLIENT | PRF_CHILDREN | PRF_CLIENT );
}
If i pass the display device context , by calling GetDC(), Clicking on print button, prints the dialog on display. But nothing happens if i pass printer dc as shown above. I also tried displaying CPrintDialog and calling GetPrinterDC(), Hope i have made my problem clear.
Thanks,
Gurushree
Did you read my answer? I wrote use ID_FILE_PRINT_DIRECT message to print directly without displaying print dialog. CView class has this message handler which creates printer DC and the calls OnPrint. If you have dialog based application without view you can borrow code from this message handler how to create printer DC. pDC passed to OnPrint is either screen DC in the case of print preview or printer DC if actual printing is being processed.
ASKER
Hi,
I have a an SDI application and view class derived from CView. In one of the menu handler of the application, i am creating this dialog box, which has print button. so, in print button handler, do i have to send ID_FILE_PRINT_DIRECT, if so i tried the follwing in Print button handler:
{
SendMessage(ID_FILE_PRINT_ DIRECT);
}
and OnPrint has the code which u suggested. but still no luck for me. Please correct me where i am wrong.
Thanks,
Gurushree
I have a an SDI application and view class derived from CView. In one of the menu handler of the application, i am creating this dialog box, which has print button. so, in print button handler, do i have to send ID_FILE_PRINT_DIRECT, if so i tried the follwing in Print button handler:
{
SendMessage(ID_FILE_PRINT_
}
and OnPrint has the code which u suggested. but still no luck for me. Please correct me where i am wrong.
Thanks,
Gurushree
You must send command message with wParam == ID_FILE_PRINT_DIRECT.
From CView deribed class menu handler:
CYourView::OnFilePrint()
{
SendMessage(WM_COMMAND, WPARAM(ID_FILE_PRINT_DIREC T));
}
or dialog button handler
CYourDialog::OnClickPrintB tn
{
GetParent()->SendMessage(W M_COMMAND, WPARAM(ID_FILE_PRINT_DIREC T));
}
From CView deribed class menu handler:
CYourView::OnFilePrint()
{
SendMessage(WM_COMMAND, WPARAM(ID_FILE_PRINT_DIREC
}
or dialog button handler
CYourDialog::OnClickPrintB
{
GetParent()->SendMessage(W
}
ASKER
Hi,
Thanks for your answer. but i have one more problem, the view class which is owning the dialog, has some document displayed in it. When i print the dialog, the view contents are also getting printed. Also, the size of dialog is very muvh reduced. i guess i need to set up some mapping mode. since i am new to these device context, printer functions, can u guide me?
Thanks again,
Gurushree
Thanks for your answer. but i have one more problem, the view class which is owning the dialog, has some document displayed in it. When i print the dialog, the view contents are also getting printed. Also, the size of dialog is very muvh reduced. i guess i need to set up some mapping mode. since i am new to these device context, printer functions, can u guide me?
Thanks again,
Gurushree
void CMyDialog::OnPrintCommand(
{
this->Print(pPrintDC, PRF_NONCLIENT | PRF_CHILDREN | PRF_CLIENT); // you may need to change the flags.
}