Solved

Change title to an object from CPrintDialog class

Posted on 2001-06-30
12
482 Views
Last Modified: 2013-11-20
hi,
I would like to change on run time the title of CPrintDialog dialog. I cannot inherit it. is there a way to do so by using one of its members?
thanks in advance, RanBN
0
Comment
Question by:RanBN
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6241904
Use SetWindowText in OnInitDialog, RanBN
Ex:
BOOL CYourDlg::OnInitDialog()
{
...
   SetWindowText("YourTitle");
...
}
0
 
LVL 2

Expert Comment

by:GloriousRain
ID: 6241909
ok, if you cannot inherit it, instantiate a CPrintDialog object then call SetWindowText()
Ex:
...
CPrintDialog dlg(FALSE);
dlg.SetWindowText("YourTitle")
...
0
 

Author Comment

by:RanBN
ID: 6241916
thanks but,
before DoModal(), hWnd member is NULL, therefore SetWindowText fails.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Expert Comment

by:sedgwick
ID: 6241988
why can't u create your own CPrintDialog derived class?
in the constructor u can send a CString which would later be the title of your CPrintDialog:

//constructor
CMyPrintDialog::CMyPrintDialog(CString sTitle, bool bPrintSetupOnly, ...)
{
m_strTitle = sTitle;
}

CMyPrintDialog::OnInitDialog()
{
     CPrintDialog::OnInitDialog();
     
     SetWindowText(m_strTitle);
     return TRUE;  
}


the code to display your CPrintDialog:
CMyPrintDialog dlg("My Print Dialog", FALSE);    
dlg.DoModal();



good luck
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6241989
the other way i think is to use modaless CPrintDialog and after ->Create() use SetWindowText to change its title, and ShowWindow() to display it.

0
 

Author Comment

by:RanBN
ID: 6242017
Hi and thanks again,
please let me be more specific about my request:
I would like to take the original CPrintDialog, the one which is located when I click on the standard toolBar "File->Print".
well, I would like to change it my my CMyView class. according the MSDN help, I should override massage OnPreparePrinting(CPrintInfo* pInfo).
in class CPrintInfo there is a member m_pPD which provides information about the Print dialog. does anyone know what to do with it in order to change caption?
thanks, RanBN
0
 

Author Comment

by:RanBN
ID: 6242097
Hi and thanks again,
please let me be more specific about my request:
I would like to take the original CPrintDialog, the one which is located when I click on the standard toolBar "File->Print".
well, I would like to change it my my CMyView class. according the MSDN help, I should override massage OnPreparePrinting(CPrintInfo* pInfo).
in class CPrintInfo there is a member m_pPD which provides information about the Print dialog. does anyone know what to do with it in order to change caption?
thanks, RanBN
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6242106
as far as i know there's no member in PRINTDLG (m_pd) which is the caption. (according to MSDN)
0
 

Author Comment

by:RanBN
ID: 6242119
the m_pPD is a pointer to CPrintDialog, but its m_hWnd member is NULL when I have it OnPreparePrinting.
does anyone have an idea?
thanks, RanBN
0
 
LVL 12

Accepted Solution

by:
migel earned 150 total points
ID: 6276311
Hi!
here is method:
1. Derive your class from CPrintDialog
2. Override OnInitDialog and call here SetWindowText("Hello!") << for example
3. Override in the your view class OnPreparePrinting:

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
  // free already allocated dialog:
if (m_pPD)
 delete m_pPD;
m_pPD = new CMyPrintDialog(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES |
          PD_NOSELECTION);
// and pass it to the framework;
     return DoPreparePrinting(pInfo);
// note you shouldn`t delete allocated dialog
// since MFC frees it in the CPrintInfo destructor.
}

Hope it helps you.
0
 
LVL 12

Expert Comment

by:migel
ID: 6276312
oops
m_pPD
 must be
pInfo->m_pPD
0
 

Author Comment

by:RanBN
ID: 6276604
thanks alot
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 152
sumNumber challenge 16 140
Prevent this page from creating additional dialogs. 3 712
dog bark java program 15 119
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question