I have a vb6 form with an ocx control on it. The ocx control has a button on it that I want to press from code. How do I do this?
I have:
Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
SendMessage ocx.hwnd, WM_COMMAND, GetWindowLong(b.hwnd, GWL_ID), b.hwnd
but it doesn't seem to work.
Best Solution
I believe the following will work:
CommandButton
s actually have two functions. One is the usual click button and the other is a toggle button that acts similar to aCheckBox
. The default property of theCommandButton
is actually theValue
property that indicates whether a button is toggled. By setting the property, theClick
event is generated. This is done even if the button is not styled as aToggleButton
and therefore doesn't change its state.