Dynamic controls
-
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
-
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
grassrootkit wrote:
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
Just like any other button click:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
grassrootkit wrote:
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
Just like any other button click:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
Can't follow you. I'm creating the control like:
CButton\* pButton = new CButton; pButton->Create("&ENTER", WS\_CHILD | WS\_VISIBLE, CRect(0, 0, 100, 43), this, 1);
How do I assign a handler for this? I do not even know it's ID here. Little unclear.
-
grassrootkit wrote:
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
Just like any other button click:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_BN_CLICKED(IDC_SOME_BUTTON, OnButtonClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Can't follow you. I'm creating the control like:
CButton\* pButton = new CButton; pButton->Create("&ENTER", WS\_CHILD | WS\_VISIBLE, CRect(0, 0, 100, 43), this, 1);
How do I assign a handler for this? I do not even know it's ID here. Little unclear.
grassrootkit wrote:
I do not even know it's ID here.
Have you bothered to read the documentation? The fifth argument is the ID.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
:confused: I'm missing the punch line, Mike.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
How do I add event handler for dynamically created controls in MFC? For example a button & an onclick event.
You need to define a hard-coded range of IDs for your dynamically created controls. for example, you can decide that the range #define IDC_DYNAMIC_CONTROL_RANGE_START 1300 #define IDC_DYNAMIC_CONTROL_RANGE_START 2000 And when you create a new control, you assign the first free ID in the range; that means you will have a limit on how many controls you will be able to support.
This signature was proudly tested on animals.
-
:confused: I'm missing the punch line, Mike.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
grassrootkit wrote:
I do not even know it's ID here.
Have you bothered to read the documentation? The fifth argument is the ID.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
DavidCrow wrote:
Have you bothered to read the documentation? The fifth argument is the ID.
:doh: . Please excuse. That's dumb. Thanks for the reply.