Home > Software engineering >  VB button handle, known how to monitor button was clicked?
VB button handle, known how to monitor button was clicked?

Time:09-23

The great god, I am new one, recently wanted to do a monitoring program with VB6.0 by use third party programs a button is clicked,
Handle to the button has been available, but monitor button click event cannot be achieved,
Have verified methods: SendMessage function unrealized more, using method is as follows (part of the third party programs can monitor to the click event) :
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
A timer, a command, a text,
VB codePrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const BM_GETSTATE=& amp; HF2
Private Sub Form_Load ()
Timer1. Interval=50
Timer1. Enabled=True
End Sub

Private Sub Timer1_Timer ()
Dim As Long a
A=SendMessage (Command1 HWND BM_GETSTATE, 0, 0)
Text1. Text=a
If a=108 Then MsgBox "button is pressed the"
End Sub
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

The great god, please help to see if there are other ways to achieve, thank you very much!

CodePudding user response:

Oneself the top, the great god please help!

CodePudding user response:

Message HOOK cannot "across processes", only "DLL remote injection",


Use Timer control, cannot "timely" reaction, is likely to be less than a message,

CodePudding user response:

Thanks for your reply, for the first time to write, a relevant example reference?

CodePudding user response:

WinAPIOverridehttp://jacquelin potier. Free. Fr/winapioverride32/

CodePudding user response:

Problems have been solved, thank you for your help! Share your experience:
First caught the need to monitor button handle, with findwindowex (can cooperate spy++ lookup handle), and then use getwindowrect handle to get coordinates, then click with hooks to monitor events,

CodePudding user response:

reference 5 floor admini2016 reply:
problem has been solved, thank you for your help! Share your experience:
First caught the need to monitor button handle, with findwindowex (can cooperate spy++ lookup handle), and then use getwindowrect handle to get coordinates, then click with hooks to monitor events,

Methods well, global mouse messages HOOK is feasible,

But you have to check at the same time "control the window is the foreground window!!!!


Otherwise, it is blocked by other Windows, but it is in the other window at that point the mouse control area, you also say "click"?
There is another, "controls in the window" can be drag position, so that every time you also need to get "controls the rectangle to just go,"

CodePudding user response:

There are such problems


"But you have to check at the same time" control the window is the foreground window! ""

With what method can achieve this?

Matrix problem is I use the timer update matrix of location, stupid way, is there any other way?

CodePudding user response:

refer to 7th floor admini2016 response:
there are such problems


"But you have to check at the same time" control the window is the foreground window! ""

With what method can achieve this?

Matrix problem is I use the timer update matrix of location, stupid way, is there any other way?

You find the button control, total want to find the first "controls in the window!"
Keep this window handle value in monitoring to "school official cites use the mouse to click" message,
Using API function GetForegroundWindow () to obtain a handle to the foreground window, whether with "by watch window",
(you don't use Spy++ view button on the handle, directly to the "program" with you? Even as it is, you can put the sentence to the program window with ah)
Window handle phase at the same time, to see whether "click position" on the button,
(ps: in fact you should not use timer update "button rectangle", should is here get button rectangular area, and then check if click on location in this area)

CodePudding user response:

Thanks, monitor button is basically realized, and then ask a thing, there are ways to a handle (form) of a cell's text information out?

CodePudding user response:

Form?

If it is "form controls," like all sorts of form controls are no good,
Impression only the ListView control that can handle, message content,

The first thing you want to make sure that is what you said this "form" what controls,

CodePudding user response:

Refer to the following code, replace handle with external buttons look,

 '-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
window codePrivate Sub Command1_Click ()
MsgBox 1
End Sub
Private Sub Form_Load ()
OldPrc=SetWindowLong (Command1 HWND, - 4, AddressOf CommandProc)
End Sub

'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
module codeDeclare the Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal HWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
Declare the Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public OldPrc As Long
The Public Function CommandProc (ByVal HWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
The Debug. Print Hex (Msg)
If the Msg=& amp; H201 Or Msg=& amp; H100 Then Exit Function
CommandProc=CallWindowProc (OldPrc HWND, Msg, wParam, lParam)
End the Function


Untested code, reference the: https://zhidao.baidu.com/question/522714025.html

CodePudding user response:

11 references sysdzw response:
reference code below and change the handle to external buttons look,

 '-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
window codePrivate Sub Command1_Click ()
MsgBox 1
End Sub
Private Sub Form_Load ()
OldPrc=SetWindowLong (Command1 HWND, - 4, AddressOf CommandProc)
End Sub

'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
module codeDeclare the Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal HWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • API
  • Related