Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to send a message to a button on a tab control

I would like to send a button click (BM_CLICK) message to the Advanced button on the Port Settings tab of the Communications Port (COM1) Properties window (from the Device Manger). I know I can do this with sendkeys but I would like to use this as a learning experience with the FindWindow and SendMessage APIs.

I can get the window handle of the Communications Port (COM1) Properties window using the window caption in FindWindow:
windowTitle = serialPorts(index).name & " Properties" 'from WMI
parentHwnd = FindWindow(vbNullString, windowTitle)

I can even send messages to the OK and Cancel buttons using the class and button caption with FindWindowEX and SendMessage:
buttonHwnd = FindWindowEx(parentHwnd, 0&, "Button", "OK")
SendMessage buttonHwnd, BM_CLICK, 0&, 0&

I tried getting the window handle for the Port Settings tab and then the Advanced button but that doesn't work:
windowTitle = "Communications Port (" & serialPorts(index).deviceID & ") Properties"
parentHwnd = FindWindow(vbNullString, windowTitle)
childHwnd = FindWindowEx(parentHwnd, 0&, "#32770", "Port Settings")
buttonHwnd = FindWindowEx(childHwnd, 0&, "Button", "&Advanced...")

How do I do this?

Thanks,
quantum1976
[1319 byte] By [quantum1976] at [2007-11-11 8:02:23]
# 1 Re: How to send a message to a button on a tab control
In case you can't get that working, here's a potential alternative: http://support.microsoft.com/default.aspx?scid=kb;en-us;815320
Phil Weber at 2007-11-11 17:26:09 >