Author Topic: @dchWnd Back to Control Name or Number  (Read 92 times)

JTaylor

  • Pundit
  • *****
  • Posts: 1646
    • Data & Stuff Inc.
@dchWnd Back to Control Name or Number
« on: March 14, 2021, 02:16:52 pm »
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

  • Tech Support
  • *****
  • Posts: 3672
    • WinBatch
Re: @dchWnd Back to Control Name or Number
« Reply #1 on: March 14, 2021, 03:48:27 pm »
The question begs for another question but ignoring the urge.  You could do something like the following in a Dialog Callback:

Code: Winbatch
            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

  • Pundit
  • *****
  • Posts: 1646
    • Data & Stuff Inc.
Re: @dchWnd Back to Control Name or Number
« Reply #2 on: March 14, 2021, 05:22:24 pm »
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

  • Tech Support
  • *****
  • Posts: 3672
    • WinBatch
Re: @dchWnd Back to Control Name or Number
« Reply #3 on: March 15, 2021, 09:31:19 am »
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

  • Pundit
  • *****
  • Posts: 1646
    • Data & Stuff Inc.
Re: @dchWnd Back to Control Name or Number
« Reply #4 on: March 15, 2021, 10:07:57 am »
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