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.