Reputation: 103
I've looked all over the internet and still can't seem to find an answer to this question. I'm using Visual C++ (2010), and I'm wondering how I can create a dialog box (MFC, dialog based program) that changes based on user input. For example, let's say I have two radio buttons on the dialog box - one for a circle and for a rectangle. If the user clicks rectangle, I want a static text on that same dialog box that says "length", and then an edit control for the user to put the length. Now, if the user clicks circle, I want a static text on the same dialog box that says "radius" and an edit control for the user to put the radius. So, depending on what shape the user clicks, a different option appears on the same dialog box. Also, when adding a static text or edit control or anything else on the dialog box using their wizard, I can't seem to find where that code is being implemented in the cpp file. Any help would be appreciated on how to implement this. Thanks!
Edit: another thing that would work is if both the radius and the length are shown on the dialog box, but, for example if the user clicks circle, then the user is unable to type in the length edit control, and can only type in the radius edit control. Thanks
Upvotes: 1
Views: 2646
Reputation: 10425
When the user clicks you can change the text on the static control. In design mode change the static control's ID to something unique like IDC_STATIC_SHAPE. Calling SetWindowText on the static control will change its text.
Adding a control to a dialog box does not generate any code in a cpp file. It adds code to the *.rc file, which is a text file that is compiled by the resource compiler and added to your program's resources section.
Upvotes: 1
Reputation: 7620
Simpler way: design your Dialog Box with all needed controls, with WS_VISIBLE style not set, and show/hide them when you want.
Upvotes: 1