Solved

Change title to an object from CPrintDialog class

Posted on 2001-06-30
12
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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