![]() |
|
QA: How do I add a title to a view?
By Joao Paulo Figueira, September 29, 2003.
QuestionI want to add a title to a CView. How do I do this without changing my view code? AnswerBefore I answer this question, let me make a brief comment on why this is a valid question. The Designed for Windows for Pocket PC Handbook for Software Applications document clearly states that the application title must be displayed on the NavBar (topmost bar on the Pocket PC screen) and that the NavBar should not be used for anything application specific. So there is a real interest in devising a customized solution like this. Now, on to the answer.
The class is derived from CControlBar and implements three virtual members that allow it to behave like an MFC toolbar: OnUpdateCmdUI, CalcFixedLayout and CalcDynamicLayout. To set the title, you use the SetTitle method. By default, this method redraws the title bar, but you can override this functionality setting the bRepaint parameter to FALSE. Use in a Document / View ApplicationTo use this title bar class in a document view application, use the sample application as a guide. This is a revised version of the PicView application I published on the CodeProject a few months ago. It implements the document / view model in a simplified way (does not allow you to create new documents), but shows the basic principles. The title bar object is encapsulated in the view object and is created when the view is created, when the OnCreate event is processed:
Notice that the title bar is a child of the frame window (a sibling to the view). Destruction of the title is done when the view's OnDestroy event is called:
The title's text is set during the view's OnUpdate processing:
Finally, the sample application supports a very simple mechanism for showing and hiding the title. This is achieved through a main menu option that toggles the title appearance.
The layout is recalculated by forcing a call to RecalcLayout, that will resize the view so that the title will be shown or hidden. And that's it. SampleYou can download a sample here - PicView.zip (170K). Related resources:
DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||