Dialog Caption

Posted on 2002-07-30
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?

Question by:jkelly061597
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

Expert Comment

ID: 7188724

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.

Expert Comment

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.


Expert Comment

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.

Technology Partners: 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!


Author Comment

ID: 7218418
Samarat did you find the code?

Expert Comment

ID: 7227934

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

Sorry for delay!

Accepted Solution

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 &= ~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


Author Comment

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


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Use VBA to get user's Mac Address for their computer 5 415
sameEnds challenge 3 196
Window placement 17 100
ShiftLeft challenge 21 95
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.

751 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