How do I click a button on a vb6 form?

I have a vb6 kind with an ocx control on it. The ocx control has a switch on it that I intend to push from code. Just 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

yet it does not appear to function.

2
2022-06-07 15:16:14
Source Share
Answers: 4

This:

Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
b = True

does function. Entirely unintuitive. I would certainly anticipate it to toss a mistake given that a bool is not a legitimate CommandButton, yet it is as a result of the default building point.

WM_LBUTTONDOWN would certainly be a computer mouse click, what I desire is a switch click (switch as in a hwnd switch, not a computer mouse switch).

I do not have accessibility to the resource of the ocx (it is a 3rd event control). If I did, I would certainly reveal the function that I intended to call (the initial author of the ocx need to have revealed it).

0
2022-06-07 20:26:20
Source

I think the adhering to will certainly function:

Dim b As CommandButton
Set b = ocx.GetButton("btnPrint")
b = True

CommandButtons in fact have 2 functions. One is the common click switch and also the various other is a toggle switch that acts comparable to a CheckBox. The default building of the CommandButton is in fact the Value building that shows whether a switch is toggled. By establishing the building, the Click occasion is created. This is done also if the switch is not styled as a ToggleButton and also consequently does not transform its state.

2
2022-06-07 18:00:56
Source

Do you have accessibility to the OCX code? You should not actually be straight conjuring up the click of a switch. You need to refactor the code to make sure that the OCX switch click code calls a function, as an example

CMyWindow::OnLButtonDown()
{
  this->FooBar();
}

Then from your VB6 application, straight call the FooBar method. If you can not straight call functions from VB6 you can cover the FooBar() method with a windows message proc function, as an example

#define WM_FOOBAR WM_APP + 1

Then make use of SendMessage in the VB6, like SendMessage(WM_FOOBAR, ...)

0
2022-06-07 18:00:51
Source

If you have accessibility to the OCX code, you can reveal the linked occasion trainer and also invoke it directly.ยข Don't recognize if an equal of.Net Button is Click() method existed back in VB6 days

1
2022-06-07 15:40:14
Source