Home > Net >  Please teach gop vb.net call API (SendMessage) problem.
Please teach gop vb.net call API (SendMessage) problem.

Time:09-19

 
Public Class Main
Const WM_KEYDOWN=256
Const WM_KEYUP=257
Public Const VK_NEXT=& amp; H22
Dim p As the New System. Diagnostics. The Process
Dim bln_ loaded As Boolean
Private Shared Function SetParent (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End the Function
Public Shared Function ShowWindow (ByVal HWND As IntPtr, ByVal nCmdShow As Integer) As an Integer
End the Function
Private Declare Auto Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal HWND As an Integer, ByVal wMsg As an Integer, ByVal wParam As an Integer, ByVal lParam As String) As an Integer

Private Sub sbtn_ cutting _Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles sbtn_ cut into big wisdom. Click
Dim inst As Process
Dim myProcess () As the Process
MyProcess=System. Diagnostics. Process. GetProcessesByName (" WPS ")
If myProcess. Count=0 Then
MsgBox (" first run the program!" , MsgBoxStyle. Information, "notice")
The Exit Sub
End the If
For Each inst myProcess In
'If inst. Handle. ToInt32=myExcel. Hinstance Then

P=System. Diagnostics. Process. GetProcessById (inst. Id)
System. The Threading. Thread.sleep (100)
SetParent (p. ainWindowHandle, pnl_11. Handle)
ShowWindow (p. ainWindowHandle, 3)
'End If
Bln_ loaded=True
Next
End Sub

Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
If bln_ has load=True Then
SendMessage (p.H andle WM_KEYDOWN, VK_NEXT, 0)
'System. Threading. Thread. Sleep (500)
SendMessage (p.H andle, WM_KEYUP VK_NEXT, 0)
End the If
End Sub
The End of the Class


Purpose is to find the software, then put him into his own FRM, give the software sends the message SendMessage, let him turn pages, it is found the software window, also added to their own window, is sending a message to the window, he no response, is he not flip, SendMessage parameters are looking for is not complete, you see where is wrong,

CodePudding user response:

This statement... Feeling a little problem,
In addition to determine vk_next page? Remember this guy is rbutton or space,,,
Try to change the API first:
 
The Public Function SendMessage (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End the Function

Comes with a calling code you consult
Public Sub SendPaintMessage (ByVal handle As IntPtr)
SendMessage (handle, WM_PAINT, IntPtr. Zero, IntPtr. Zero)
End Sub

Public Sub SendMouseClick (ByVal handle As IntPtr, ByVal x As an Integer, ByVal y As an Integer)
If the handle & lt;> IntPtr. Zero Then
Dim lParam As IntPtr=New IntPtr ((y & lt; <16) Or x)
Dim wParam As IntPtr=IntPtr. Zero
SendMessage (handle, WM_LBUTTONDOWN wParam, lParam)
Threading. Thread.sleep (100)
My application.doevents ()
SendMessage (handle, WM_LBUTTONUP wParam, lParam)
End the If
End Sub

Public Sub SpaceKeyDown (ByVal handle As IntPtr)
If the handle & lt;> IntPtr. Zero Then SendMessage (handle, WM_KEYDOWN, Keys, Space, IntPtr. Zero)
End Sub
Public Sub SpaceKeyUp (ByVal handle As IntPtr)
If the handle & lt;> IntPtr. Zero Then SendMessage (handle, WM_KeyUP, Keys, Space, IntPtr. Zero)
End Sub

Public Sub SendEnter (ByVal handle As IntPtr)
If the handle & lt;> IntPtr. Zero Then
SendMessage (handle, WM_KEYDOWN, Keys, Enter, IntPtr. Zero)
Threading. Thread.sleep (10)
My application.doevents ()
SendMessage (handle, WM_KeyUP, Keys, Enter, IntPtr. Zero)
End the If
End Sub


CodePudding user response:

The other, the last parameter:

 
PostMessage (handle, WM_KEYDOWN, Keys. Space, MapVirtualKey (Keys) Space, WM_KEYDOWN))
Explain MapVirtualKey is API, with integer,

CodePudding user response:

refer to the second floor response: clear dawn month
the other, the last parameter:

 
PostMessage (handle, WM_KEYDOWN, Keys. Space, MapVirtualKey (Keys) Space, WM_KEYDOWN))
Explain MapVirtualKey is API, with integer,

Thank you, I see,

CodePudding user response:

refer to the second floor response: clear dawn month
the other, the last parameter:

 
PostMessage (handle, WM_KEYDOWN, Keys. Space, MapVirtualKey (Keys) Space, WM_KEYDOWN))
Explain MapVirtualKey is API, with integer,

Whether or not, before, need to set the window to focus?

CodePudding user response:

The WPS with what page? Are you sure send button right?

CodePudding user response:

reference clear dawn month 5 floor response:
WPS with what page? Are you sure send button right?

I know, may not directly to the main form SendMessage, if they were going to find a specific handle to the child form or control?
Bosses, give me an enumeration child form and control API functions and examples, if there is a method of vb.net can better,

CodePudding user response:

refer to the second floor response: clear dawn month
the other, the last parameter:

 
nullnullnullnull
  • Related