Click here to Skip to main content
Click here to Skip to main content
Go to top

An alternative to the often asked view-in-dialog problem using a dialog bar

, 2 Jul 2002
Rate this:
Please Sign up or sign in to vote.
In this article I show an alternative to the tricky (and thus often unstable) attempts to create a view on a dialog.

Introduction

I tried to create a View on a Dialog, and thus looked up all the articles on the web. There are several attempts to do this, but more or less all of them produce errors and aren't too useful in  my opinion. So I decided to go a different way. I created a new Window type (called CDialogWindow in my demo project) by deriving the class from CFrameWnd. In this CDialogWindow I created a View using Jorge Vigils code from http://www.codeguru.com/doc_view/ReplacingView.shtml (I modified it of course, but am nonetheless grateful to Jorge). This View was a CScrollView which was my main intention, and perhaps this is also yours. Just imagine a task like displaying a bitmap on a dialog in full-size, which doesn't fit in the Dialog form. My own task was to display a video image generated by an ActiveX-Control. Instead of really displaying this image in a dialog, I created the just mentioned view in the CDialogWindow and added a CDialogBar to this window. The result looks nearly like a dialog containing a view.

But unfortunately I have to deal with an unexpected disadvantage using this simple technique. As the CDialogBar isn't connected with an own class but with the CDialogWindow Class, it is not possible to connect variables with the controls. This means of course, that all the advanced controls like spin buttons, scroll bars etc. which need to be represented by a variable of "Control" type, cannot be used. The functionality of the Window is reduced to input and output in text fields using the methods GetDlgItemInt(), GetDlgItemText(), SetDlgItemInt(), SetDlgItemText(). Perhaps someone can improve my project and tell me how to use all sort of controls in such a window.

Usage

As you can see in the demo project, I have added my CDialogWindow to an MDI project, not using any of the classes created by the application wizard. So if you take my project as a start point, you still have all the functionality of an MDI-app. Mainly I haven't used the generated view class but a class which I imported from another project, because this class was good for my purpose. Just to show you how the window works, I have replaced my video image by a simple text. What does this mean for you, if you want to copy some of my code:

  • Copy the CDialogWindow class to your project and create an object with the DoModeless() method as you can see it in the project.
  • If you also want to display anything but not a document, also copy the CExtraView class and modify the OnDraw() method in order to make it display your stuff.
  • If you want to create a view of a document or create a view from your own view class, just replace the class name in the RUNTIME_CLASS Macro in CDialogWindow::OnCreateClient() and don't forget to declare CVideoWindow friend of your own view class. Of course you will have to do some other little modifications like including the header files and so on.

Conclusion

Pleas write me an email if you could improve my classes, especially, if you achieve to use all sort of controls in the dialog bar. I'm sorry, but I generated the demo project using the German version of the SDK. Thus the auto-generated comments are in German. This should not prevent you from understanding the code, as all pieces of my own code are commented in English.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

thom_as
Web Developer
Germany Germany
Thomas Schuster, studying Physics in Ulm / Germany and therefore programming Visual C++.

Comments and Discussions

 
Answerthanks .you help me a lot Pinmemberzxl2004068-Sep-11 20:43 
GeneralThanks,your code has a great help to me. Pinmember82745426-Aug-08 22:04 
QuestionWhat you present isn't really a dialog PinmemberAweAwe28-May-04 9:22 
Generaldocking CdialogBar like toolbal Pinmemberyaser7-Sep-02 10:03 
QuestionFor me illogical conclusion? PinmemberJörgen Sigvardsson18-Jun-02 4:22 
AnswerRe: For me illogical conclusion? PinmemberDaniel Turini3-Jul-02 11:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 3 Jul 2002
Article Copyright 2002 by thom_as
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid