ATL ActiveX control with wtl :: cbutton dynamically added button code steps
First, you must add an ATL control to generate a corresponding class.
1, contain head files
#include
2. Define the resource ID
#define IDC_BTN_Play 6000
3. Define members in class declarations.
Cbutton m_btnplay;
4, in the WM_CREATE message
Rect rc1;
Rc1.Left = 60;
RC1.TOP = 0;
RC1.BOTTOM = RC1.TOP 18;
Rc1.right = rc1.Left 50;
M_BTnPlayCreate (M_HWND, & RC1, _T ("STOP"), WS_CHILD | WS_VISIBLE, 0, IDC_BTN_PLAY);
5. Define Click Events and Message Mappings.
Message mapping:
Begin_MSG_MAP (CPLAYER)
Message_handler (WM_CREATE, ONCREATE)
Command_handler (IDC_BTN_Play, Bn_Clicked, Onplay)
....
END_MSG_MAP ()
Event function:
LResult Onplay (Word WiNTifyCode, Word WID, HWND HWNDCTL, BOOL & BHANDED)
{
:: MessageBox (M_HWND, _T ("Yes, Play!"), _ T ("OK"), 0);
Return 0;
}
6, ok.