How do I ensure a unique ID for my dynamically created button?
-
Hi all, I create a button dynamically but as it is now, I create the button ID myself like this cause in this case I can't use the editor to create it: #define ID_MY_BUTTON 33333 But how do I ensure a unique ID for this dynamically created button? /Tommy
-
Hi all, I create a button dynamically but as it is now, I create the button ID myself like this cause in this case I can't use the editor to create it: #define ID_MY_BUTTON 33333 But how do I ensure a unique ID for this dynamically created button? /Tommy
-
You can use _APS_NEXT_CONTROL_VALUE. Resource editor store here value which will be given to the next created control - so values above this not used. Acid will burn!
-
You can use _APS_NEXT_CONTROL_VALUE. Resource editor store here value which will be given to the next created control - so values above this not used. Acid will burn!
Ok, so you mean that I can do like this: m_pBtn->Create(_T("Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE); Because m_pBtn is not associated with a resource editor created control, it's createed from scratch and subclassed dynamically. /T
-
Ok, so you mean that I can do like this: m_pBtn->Create(_T("Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE); Because m_pBtn is not associated with a resource editor created control, it's createed from scratch and subclassed dynamically. /T
This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!
-
This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!
Ok, thx XKent! /T
-
This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!
Hi again, What must I include in order to use the _APS_NEXT_CON... value?