Click to See Complete Forum and Search --> : Programmatically created buttons & strings
Ha Kinh
March 28th, 1999, 11:23 AM
In my project I have to display strings as well as buttons with lables. The number & content of text strings, buttons and their positions in the window can only be determined at run time. It is, of course, necessary to be able to detect which button has been pressed by the user. I am most grateful if someone could give me some hints on how to go about doing it.
Thanks
Daren Chandisingh
March 29th, 1999, 03:02 AM
Creating buttons on the fly is quite a simple matter. You just need something like this:
<P>
// this is the buttons identifier. It's used in the parent's command<BR>
// handler<BR>
#define BTN_ID_1 100<BR>
<P>
CRect btnRect(5,5,25,25);<BR>
CButton *pButton = new CButton();<BR>
<P>
pButton.Create ("Click me", BS_PUSHBUTTON, btnRect, this, BTN_ID_1 );<BR>
<BR>
// button is created. Rememeber to delete it later (delete pButton)<BR>
<P>
Somewhere you need a Command handler, this will be in the buttons' parent
window (or dialog)
<P>
BOOL CMyDialog::OnCommand( WPARAM wParam, LPARAM lParam )<BR>
{<BR>
switch (LOWORD(wParam))<BR>
{<BR>
case BTN_ID_1:<BR>
//...<BR>
break;<BR>
}<BR>
}<BR>
I hope this answersthe question. If not, please do feel free to email me any questions directly and I will do my best
to answer them.
Ha Kinh
March 29th, 1999, 06:24 AM
Thanks, I'll try it. Since the number of buttons will vary (from 0 to 35), can they ALL be handled by a single command handler and identified by a single BTN_ID ? We must then detect the button being pressed by its position. Is it possible for the command handler to detect the position of the pressed button?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.