Solved

Dialog Caption

Posted on 2002-07-30
7
1,622 Views
Last Modified: 2013-11-20
A few things:

I do not want MFC to display the current filename in the Title bar of the main window, and I want to have the ability to change the caption at various runtime points... what do I need?

Also: How do I change the caption on a dialog box at runtime? Is it the same as for the main window?

thanks
jeff
0
Comment
Question by:jkelly061597
7 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 7188724
Hi,

For all ur questions, there is only one answer. Use the function SetWindowText(). If U want to set the title for the main window in an SDi/MDI, then use the mainframe pointer and call SetWindowText(...) specifying ur new title. And for dialog, use ur dialog pointer or from the dialog class call SetWindowText(...) function.

If u want to set the title bar initially itself, then for MainFrame, do it in OnCreate function before returning and for dialog, map OnInitDialog message map and call SetWindowText.

Try it out.
VinExpert
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7189276
... so far so good :) ...

To get the mainframe pointer from any location call the AfxGetMainWnd-function. It returns a CWnd*

Other than that, VinExpert has already answered your question.

.f
0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 7189431
From your questions, I gather that you are using
Document-view architecture and most likely MDI!

In this case, you have to override functions in
CDocument; I don't remember the exact name, but is
something like GetTitle.

Even if you do suppress the name, it still leaves
that annoying separator "-" To suppress this, I tinkered
with CMainframe, I will dig up my old code and let you
know; I don't remember as of now.

If you cannot wait, then set break point on CDocument
override; debug it into MFC to figure out how it
peices name together and then break the chain.

For dialog boxes; you can call SetWindowText.

For views : Never call SetWindow text indiscriminately
without understanding which window you are calling for.
There is much more behind the screens then you can see
for a view.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jkelly061597
ID: 7218418
Samarat did you find the code?
0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 7227934
jkelly

was too busy to check ee. Will be able to look and
let u know!

Sorry for delay!
0
 
LVL 2

Accepted Solution

by:
SamratAshok earned 75 total points
ID: 7228508
Hello jkelly

Finally, did the code dig up as promised. Found
couple of different methods exist where you can
control appearance of title. Listing them in
order of simplicity.

1) Override CDocument::SetTitle method

2) Override CMainFrame::PreCreateWindow

Add a line which looks like
cs.style &= ~FWS_ADDTOTITLE;

// This line changes window style settings that
// affect the title generation. play with them
// to see which override works the best.

3) Override CChildFrame::PreCreateWindow

This function is exactly identical to above
one needs same source code, but affects inner
child window behaviour.

Again experiment by setting both on, first only, second only or none permutations.

4) Edit resource string in  editor
Read documentation for further details
or look up source code for AfxExtractSubString
in winstr.cpp to see how it parses the string.

5) Last option. Override OnUpdateFrameTitle function
and code your requirements exactly.

override this function if and only if you absolutely must.
You will be preety much out and open with no MFC intervention regarding titles. You can actually copy
existing MFC source and then tweak it to make it work
for you.


Hope this helps

0
 

Author Comment

by:jkelly061597
ID: 7228813
Thnk you very much... I got it.

jeff
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
Error on moodle after upgrade 3 119
iSeries FTP Exit Program 8 122
Is there a simple front-end menu system. 9 69
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

930 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

10 Experts available now in Live!

Get 1:1 Help Now