VanPers
VanPers

Reputation: 339

What difference between control's window handle and controlID

I'm learning Win32 assembly. Have some question I search but not suitable result.

Anyone can explain for me What difference between control's window handle and controlID.

Upvotes: 1

Views: 403

Answers (1)

Hans Passant
Hans Passant

Reputation: 941635

They have nothing in common. Every window has a handle, returned by CreateWindowEx(). Such a window can have a few extra properties attached, like a menu handle. The hMenu argument in CreateWindowEx(). If the window doesn't have a menu, a child window won't have one, then you can use that argument to pass an arbitrary other bit of data. It will be assigned to the GWLP_ID property (see GetWindowLongPtr). Also note the GWLP_USERDATA, an extra property that's entirely yours to use as you see fit.

Dialogs take advantage of this, a dialog template that you create in the resource editor gives you a way to number the child controls. With a helper function like GetDlgItem() to get the handle back for a control with a specific number. Which is pretty necessary for dialogs since it is Windows that create the child controls from the dialog template so you don't know the window handles for them yourself.

Upvotes: 2

Related Questions