Was wondering if there is anything in GoAsm that will let one hook into a program that
one has ZERO control over. From the MASM32 code that I see at this point I can not
determine if Izcelions code does this.
What I want to do is pull a small rectangle from this program and work with it in my
program. Problem with the program is I do not know how to get the handle of
the program.
I have a working program that does this with a laborious method of mouse clicking
on my window to record the card played. It is not near fast enough to be useful.
If I was playing the hand and trying to record the cards played it would not work.
This program is to be for my use ONLY..
Maybe you can use some tool that can show the handles of the apps or process running in your machine? :idea:
Thank you for responding Felipe.
Sysinternals suite has an item called "handles".
But I'll be darned if I can get anything to come out of it.
Yes I know that I have to be in the command line to execute it.
i am sure there's a way to do this
you might search the forum (and maybe the old forum) for "enumerate windows" or something like that
maybe just "enumerate" as a search term
it depends on how you want to initially identify the window
this is the function WindowFromPoint - it returns a window handle from a point on the screen
it may be a starting place
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633558(v=vs.85).aspx
a program i use for testing programs is called Microsoft Spy++
a free download (i'll let you google it)
Thanks Dave,
Will check both suggestions out.
Long time no see. Wiffie giving you orders to stay off the computer:)
no - i have been very busy with other stuff
been spending a lot of time reconditioning houses, etc
and, i have a lot of stuff in storage that seems to be a never-ending task
getting rid of it, re-boxing, storing at home, etc
some of it, i want to sell on e-bay, i think
when i do have play time, i want to spend more time on arduino's and pi's
and, i am always working on getting my own little ham radio equipment company started
i think i have the first product in mind - a programmable twist on ferrite antenna arrays
no UL approval, no FCC type acceptance requirements, etc
makes it a simple first-product
7-29-2018
Thanks Dedndave for your suggestion. WindowFromPoint doesn't
work for me. So it looks like I am going to have to use the
Izcelion tut24. Below is a sample of the code I tried to use.
It is written for GoAsm 64-bit
POINT STRUCT
Px dd 0
Py dd 0
POINT ENDS
FRAME hWnd,iMsg,wParam,lParam
LOCAL ps:PAINTSTRUCT,pt:POINT,RR:RECT
savehWnd dq 0
; GHSwh swh to control right mouse clicks
; msg3 'WindowFromPoint failed',0
.WM_RBUTTONDOWN
; 1st time the R mouse button is hit it should get the handle from
; the other program on the screen. Then I want to process the data
; from that screen in my program.
; When the R mouse button is hit any time after the 1st time it should
; clear my window and start over for the next hand.
cmp D[iMsg],WM_RBUTTONDOWN
jne >>.WM_LBUTTONDOWN
cmp b[GHSwh],0
jne >>.ClearForNextRound ; Player hit the Claim button
mov b[GHSwh],1 ; set to clear for next round
invoke WindowFromPoint, [pt.Px],[pt.Py] ; this gets the handle
; of the screen program
mov [hWnd],rax
mov [savehWnd],rax ; Handle to the game program
cmp rax,NULL
jne >>.WM_LBUTTONDOWN
invoke MessageBox, NULL,addr msg3,addr msg3,MB_OK
cmp eax,IDOK
jne >>.GetOut
.WM_LBUTTONDOWN
cmp D[iMsg],WM_LBUTTONDOWN
.
.
.
.ClearForNextRound
.
.
.GetOut
7-29-2018
Question about converting Iczelions tut24 to Goasm 64-bit.
There are 2 mousehook.asm programs in Tut24. One wonders why?
Are these tut24 programs able to be converted to GoAsm 64-bit?
mousehook.inc
mousehook.lib
mousehook.rc
mousehook.def
Or is there already something in GoAsm that does hooks??
Thanks for any info.
Going back to your WindowFromPoint attempt, there would appear to be steps missing in getting the right mouse click coordinates from lParam into pt.PX and pt.Py. Once they are there, those client coordinates should then be converted to screen coordinates with ClientToScreen. This will require hWnd which you are overwriting. Also, for that right mouse click to function outside of your application's borders, I believe you will need to use SetCapture.
Thank you WJR for helping.
My problem all along has been getting the handle from the
program that I want to get data from. I have absolutely no
control over it. Program [A].
My program works with a mouse click but it is to slow to use.
So if an api requires hWnd from program A before I have retrieved it
I don't see how I can get around that. (ex: SetCapture)
Below is my latest attempt and it doesn't work.
I sign on to program A. Then sign on to program B.
Move the mouse over program A and right click and it doesn't
work. No error message is generated.
.const
POINT STRUCT
Px dd 0
Py dd 0
POINT ENDS
savehWnd dq 0
.WM_RBUTTONDOWN
cmp D[iMsg],WM_RBUTTONDOWN
jne >>.WM_LBUTTONDOWN
; GHSwh swh to control right mouse clicks
cmp b[GHSwh],0
jne >>.ClearForNextRound ; Player hit the Claim button
mov b[GHSwh],1 ; set to clear for next round
mov rax,Q[lParam] ; loword
and eax,0FFFFh
mov d[pt.Px],eax
mov rax,Q[lParam] ; hiword
shr eax,16
mov d[pt.Py],eax
;???? invoke WindowFromPoint, [pt.Px],[pt.Py] ; this should get
; the handle from program A
invoke GetCapture ; this should get the handle from program A
; but I don't know if the mouse is pointing to program A
mov [hWnd],rax
mov [savehWnd],rax ; Handle for program A
cmp q[savehWnd],0h
jne >>
;??????msg3 'WindowFromPoint failed',0
;msg3 'GetCapture failed',0
invoke MessageBox, NULL,addr msg3,addr msg3,MB_OK
cmp eax,IDOK
jne >>.GetOut
:
;? invoke ScreenToClient, [hWnd],addr pt
invoke ClientToScreen, [savehWnd],addr pt
cmp q[savehWnd],0h
jne >>
;msg1 db 'Client To Screen failed',0
invoke MessageBox, NULL,addr msg1,addr msg1,MB_OK
cmp eax,IDOK
jne >>.GetOut
:
ret
.WM_LBUTTONDOWN
cmp D[iMsg],WM_LBUTTONDOWN
jne >>.WM_PAINT
I don't know if this info will help, but you need to get the ProcessID first, then try to get the window handle.
This example from masm32 examples "\masm32\examples\enumerate\pid" shows how to get the process ID.
Once you have the process ID, it should be a simple matter to find the window handle.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
comment * -----------------------------------------------------
Build this template with
"CONSOLE ASSEMBLE AND LINK"
----------------------------------------------------- *
include \masm32\include\psapi.inc
includelib \masm32\lib\psapi.lib
ShowProcess PROTO pid:DWORD
.code
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
call main
inkey
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
main proc
LOCAL breq :DWORD
LOCAL pbuf :DWORD
LOCAL buffer[4096]:BYTE
push esi
push edi
mov pbuf, ptr$(buffer) ; cast buffer address to a pointer
invoke EnumProcesses,pbuf,4096,ADDR breq ; enumerate processes
shr breq, 2 ; get process count
mov esi, pbuf
mov edi, breq
@@:
invoke ShowProcess,[esi]
add esi, 4
sub edi, 1
jnz @B
pop edi
pop esi
ret
main endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
ShowProcess proc pid:DWORD
LOCAL hProcess :DWORD
LOCAL hMod :DWORD
LOCAL cbNeeded :DWORD
LOCAL pbuf :DWORD
LOCAL ptxt :DWORD
LOCAL buf[260] :BYTE
LOCAL txt[260] :BYTE
mov pbuf, ptr$(buf)
mov ptxt, ptr$(txt)
mov hProcess, rv(OpenProcess,PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,FALSE,pid)
.if hProcess != 0
.if rv(EnumProcessModules,hProcess,ADDR hMod,4,ADDR cbNeeded) != 0
invoke GetModuleBaseName,hProcess,hMod,pbuf,260
mov ptxt, cat$(ptxt,"pid ",str$(pid)," ",pbuf)
.else
mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- EnumProcessModules")
.endif
.else
mov ptxt, cat$(ptxt,"pid ",str$(pid)," -fail- OpenProcess")
.endif
print ptxt,13,10
invoke CloseHandle,hProcess
ret
ShowProcess endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Do a little more research (https://www.google.com/search?hl=en&source=hp&biw=&bih=&q=Get+Window+Handle+from+Process+I.D.&gbv=2&oq=Get+Window+Handle+from+Process+I.D.&gs_l=heirloom-hp.12...1965.24211.0.25958.37.25.0.12.12.0.452.6443.0j3j0j12j4.19.0....0...1ac.1.34.heirloom-hp..7.30.6350.9Nxq4p259pQ) == Google search for "Get Window Handle from Process I.D.", "About 4,830,000 results" 8)
The [hWnd] is for your program. In case your program is lower and to the right of the other one, the word point coordinates should be sign extended to dword. You can try this, where a left button click in your window does SetCapture to allow a right click to get the point in the other program:
.WM_RBUTTONDOWN
cmp D[iMsg],WM_RBUTTONDOWN
jne >>.WM_LBUTTONDOWN
cmp b[GHSwh],0
jne >>.ClearForNextRound ; Player hit the Claim button
INVOKE ReleaseCapture
mov b[GHSwh],1 ; set to clear for next round
mov rax,Q[lParam] ; loword
and eax,0FFFFh
movsx eax,ax ;now dword, possibly signed
mov d[pt.Px],eax
mov rax,Q[lParam] ; hiword
shr eax,16
movsx eax,ax ;now dword, possibly signed
mov d[pt.Py],eax
INVOKE ClientToScreen, [hWnd], ADDR pt
INVOKE WindowFromPoint, [pt.Px], [pt.Py]
mov [savehWnd],rax ; Handle for program A
;
.WM_LBUTTONDOWN
cmp D[iMsg],WM_LBUTTONDOWN
jne >>.WM_PAINT
INVOKE SetCapture, [hWnd]
;
8-4-2018
Thanks for your help WJR.
I made the changes you suggested and compiled the program.
I did try to investigate the error it found. The assembler
books use the same code that GoAsm gives an error on.
Windows 7 pro 64-bit.
movsx eax,ax dw signed
Error message:
Data declaration too small assuming it should hold at least
a 32-bit address: dw signed....
mov rax,Q[lParam] ; loword
and eax,0FFFFh
movsx eax,ax dw signed
mov d[pt.Px],eax
mov rax,Q[lParam] ; hiword
shr eax,16
movsx eax,ax dw signed
mov d[pt.Py],eax
Comment semicolon required before dw signed.
Sorry :redface: