Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

VC++ 5.0 GUI doubt

i would like to know how could i place a button at runtime into my dialog box ?
0
charul
Asked:
charul
  • 3
  • 3
  • 2
  • +1
1 Solution
 
charulAuthor Commented:
none
0
 
charulAuthor Commented:
Edited text of question
0
 
thresher_sharkCommented:
The simplest solution to your problem would be to have the button exist all the time in the dialog, but have it hidden.  You can change the visible status by going to the button's properties.  Then, when you need the button, use something like GetDlgItem (YOUR_BUTTON_RESOURCE_IDENTIFIER)->ShowWindow (SHOW);

If you have any questions on implementing this solution, please feel free to ask.  Thanks!
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
jhanceCommented:
If you're using MFC here is how to do it:

   CButton  xbutton = new CButton();
    xbutton->Create(
        "Some Name",
        WS_CHILD | WS_VISIBLE | WS_BORDER,
        CRect(0, 240, 200, 270), this, XBUTTON
    );
0
 
thresher_sharkCommented:
jhance - Don't you think my solution would be easier since you wouldn't need to worry about coordinates and things of that nature?  You would be able to place the button using the Resource Editor which is much easier than:
1) Choose coordinates
2) Compile
3) Does it look right?  If no, go to 1.

?
0
 
Answers2000Commented:
I would do it your way thresh if there's only 1 or 2 buttons, use ShowWIndow to show/hide buttons, use EnableWindow to enable/disable buttons

I haven't tested it out - but does the button created dynamically in jhance's way get added to the keyboard sequence (e.g. can you tab to it, and then off it to another control).  I seem to recall, it won't on a dialog, unless you also make the dialog handle the tabbing about messages...but this is fuzzy, so perhaps I'm wrong here
0
 
jhanceCommented:
thresher...

I agree that your method (i.e. hiding/showing a button) is preferred but it's not what the question asked.  Sometimes you don't know what button you will need until runtime.  An example of this would be a dialog editor type application which cannot use your method.
0
 
thresher_sharkCommented:
That's true, good point.  Thanks for clarifying.
0
 
charulAuthor Commented:
Thanks very much. Let me try out the suggestion.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now