@dchWnd Back to Control Name or Number

Started by JTaylor, March 14, 2021, 02:16:52 PM

Previous topic - Next topic

JTaylor

If I have the Windows Handle of a control is there a way back to the Control Name or Number?   This seems like I am missing the obvious but that is what I excel at so thought I would ask.

Jim

td

The question begs for another question but ignoring the urge.  You could do something like the following in a Dialog Callback:

Code (winbatch) Select
            nCtlNum = DllCall('User32.dll',long:'GetDlgCtrlID', long:hWnd) - 99
            strCtlName = dialogProcOptions(MyDialog_Handle, @dpoCtlName, nCtlNum)
            Message('Control Name', strCtlName)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

If my latest crazy idea works out I am guessing your question will be answered at some point in the near future  :)

That's right...should have thought of this.   Thanks. 

Jim

td

The above 3 lines are not guaranteed to work.  Dialog templates that have GroupBoxes or have tab orders that do not match the order of the control in the dialog template can cause control IDs to differ from control numbers.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Understood.  Thanks again for the reminder.   I knew this at one point but had been awhile since I had used this method and it had slipped my mind.

Jim