Click to See Complete Forum and Search --> : Help me to Create Button
Drago
May 7th, 1999, 02:02 PM
Hi,
I need your help. I try dynamicly create a button.
I use CreateWindow .How can I add function to do OnClick() event.
Please help me !!!!!
Thanks a lot.
Drago
sayoyo
May 11th, 1999, 03:09 PM
Hi,
this a example how to create a button dynamically, hope it will help:
RECT r;
CButton pNewButton;
r.bottom = 30;
r.left = 10;
r.right = 50;
r.top = 10;
pNewButton = new CButton;
pNewButton->Create("Button",WS_VISIBLE,r,AfxGetMainWnd(),5001);
it will create your button on your main Window,
if you want to execute some funciton with this button, you have to add some
information at your Message_map of your main window,
<mainWindow.h>
// Generated message map functions
//{{AFX_MSG(mainWindow)
....
afx_msg void OnButtonDyn(); // line to add
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
<mainWindow.cpp>
BEGIN_MESSAGE_MAP(mainWindow, CDialog)
//{{AFX_MSG_MAP(mainWindow)
...
ON_BN_CLICKED(5001, OnButtonDyn) // line to add
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void mainWindow::OnButtonDyn()
{
//do somthing...
}
Valerie Bradley
May 11th, 1999, 03:26 PM
Here is another way you can do it. Instead of making a dynamic button, you might want to consider creating the button in the resource editor, and then simply not showing the button until you need it.
I.e., when you create the button resource, there should be an option in its properties to make it not visible at run time. Then, you add code in your application to make the button visible when its needed.
ShowWindow(SW_SHOW); will make the button appear.
ShowWindow(SW_HIDE); will make it disappear.
I don't know if this is a viable solution for you, but it will solve your problem of handling button clicks... the button exists, you can associate a variable with it, and you can implement all the OnClick functionality you need for it.
Good luck, and happy coding!
=================================================
Valerie L. Bradley
Software Engineer
Intel Corporation
* All opinions expressed are mine and not those of my employer.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.