troubleshooting Question

Vb.net press a button programatically

Avatar of sgaggerj
sgaggerjFlag for United States of America asked on
Visual Basic.NET
19 Comments4 Solutions899 ViewsLast Modified:
Hi Experts!

I have written a vb.net app to press a specific button on an already running app (specifically the HP Fax app, HPOFXM08.exe) running on Server 2003.

According to Spy++ and Winspector Spy I have found the correct handle to the item to be clicked, but for some reason it's not clicking the button.

The code I'm using is below.

What am i missing?
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmd As Int32) As Boolean

Private Const HP_FAX_APP_TITLE As String = "HP Officejet 7200 series - Send Fax"
Private Const SW_RESTORE As Long = 9
Public Const BM_CLICK As Long = &HF5

Private ipFax as IntPtr

Sub Main()
  ' The Fax app window handle
  Dim parent As IntPtr = FindWindow(vbNullString, HP_FAX_APP_TITLE)
  ShowWindow(parent,SW_RESTORE)
  ' prior to this call, I have (according to Spy++ and Winspector Spy) found the correct handle, but for simplicity sake not
  ' showing the code.
  SendFax()

End Sub

Private Sub SendFax()
  ' this sendmessage returns a 0, whatever that means.
  SendMessage(ipFax, BM_CLICK, 0, 0)
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 4 Answers and 19 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros