Sign in to follow this  

[C++/Windows/VS2k5] Linking a class to a dialog box

This topic is 3780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to create a dialog box for my Windows application in Visual Studio 2005. I am using unmanaged C++, and my target platform is Vista. I've created a dialog resource in my project, and I've also written a class derived from CDialog that I want to use for this resource. However, when I right-click on the dialog box, the "Add Class" item is grayed out. I can cause the dialog box to display in my application without an issue. I just want to use my class to define the behavior of the dialog box. How would I do this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Rainault
I need to create a dialog box for my Windows application in Visual Studio 2005. I am using unmanaged C++, and my target platform is Vista. I've created a dialog resource in my project, and I've also written a class derived from CDialog that I want to use for this resource. However, when I right-click on the dialog box, the "Add Class" item is grayed out. I can cause the dialog box to display in my application without an issue. I just want to use my class to define the behavior of the dialog box. How would I do this?


Sounds like you're coming from VB or C# [smile]

What you need to do (and its sort of involved if you're rolling your own class) is create a mapping between dialog events and your dialog widgets (and possibly the dialog itself).

Whenever that word "mapping" comes up, it usually means you can use "std::map" to good effect.... mapping a Win32 event code directly to some functor.

The functor would be where you would do your calculations and populate the fields of your dialog box.

Or you can call a list of Observers in the functor ... which Observers are interested in that particular event.

I realize this is all "high-level" language... but conceptually this is how you proceed. There are several ways to implement.

I would use some sort of wrapping classes around each widget (multiple inheritance in C++, interfaces in C#/Java) so that each "Widget" would be considered both a "Widget" and an "Observer". That way, you can register each event code, and when the event is triggered... call "Observer::notify()" on each interested widget, and do whatever you need to in the overridden virtual function "notify()"... or "notify(Event e)" if you prefer.

Hope this gives you some ideas.


Chad

Share this post


Link to post
Share on other sites
I actually come from a predominantly C++ background, though recently I've been doing more ASP.NET/C# development. I haven't done much Windows app development, and the few that I have done used SDKs that wrapped all of the gory details.

But I've taken some ideas from what you said. We'll see where I can go with it. Thanks for the help. :)

Share this post


Link to post
Share on other sites

This topic is 3780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this