Re: Proper use of ON_CONTROL
Mkennedy1102 wrote:
OK Scott, I know this should probably be pretty easy, but I still cant get
it. See if you can clarify a couple of things for me. The notification code,
like you said, is defined by the control, so that should be the CC_CHANGING,
but what then is the ID? It can't be the dialog control ID, because that is
not constant.(I.E. If i use this control in another app, it will not get the
same dialog control ID) Unless I need to somehow retrieve that ID at runtime
and supply it as a variable in the controls message-generating function? I
appreciate you taking the time to help me out. Thanks again.
A control's ID is a constant that you - the application programmer -
assign. It is used to identify the control uniquely within it's parent
window. The ID (like IDC_BUTTON1) is assigned within the dialog editor
when you put a control on a dialog template, or it is assigned by a
CreateWindow parameter for dynamically created controls. Within the
message map, the control's ID is used to dispatch messages from one
particular control. All control ID's are actually assigned at compile
time by #define statements in the resource.h file. That assignment goes
into the .rc file and becomes a property of the control, and it goes
into the message map as a filter to detect messages from the control.
Within a custom control's code, when you need the ID to generate
messages, your ID can be retrieved with GetWindowLong(m_hWnd, GWL_ID).
--
Scott McPhillips [VC++ MVP]