button vb


2down voteaccepted

There are a few ways to do that for example:

  1. You can find OK button position(FindWindowEx and GetWindowRect), set the cursor position(SetCursorPosition) on it and click(mouse_event) on that or set focus on the button and press Enter(keyb_event).
  2. Send BM_CLICK message to window message translator with the OK button ID.

I suggest you to go with the second approach:

<Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function

Public BM_CLICK As Integer = &HF5 

SendMessage(`OK BUTTON HANDLE`, BM_CLICK, 0, 0)

You can find the button handle with FindWindowEx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s