Solved

Change title to an object from CPrintDialog class

Posted on 2001-06-30
12
476 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now