The MASM Forum

Projects => Rarely Used Projects => GoAsm => Topic started by: shankle on May 04, 2019, 07:03:51 AM

Title: Focus
Post by: shankle on May 04, 2019, 07:03:51 AM
       5-3-2019

; Purpose of this code is to try and move the focus to my program
; from a program I have no control over.

; I need to left click the mouse in my program to change
; the focus from the game program to my program.
; The code shows as an error with msg20

hdc   dq 0

.WM_LBUTTONDOWN
    cmp D[iMsg],WM_LBUTTONDOWN
     jne >>.WM_KEYDOWN
    mov rax,0x000         ;wParam code for MK_LBUTTON
    cmp rax,MK_LBUTTON
      je >>
;   msg20         db '0x000 & MK_LBUTTON failed',0
    invoke MessageBox, NULL,addr msg20,addr msg20,MB_OK
     jmp >>.PQM
:
    invoke SetFocus,[hdc]    ; my program
    cmp rax,0
     jg >>
   ;msg18         db 'SetFocus failed',0
   invoke MessageBox, NULL,addr msg18,addr msg18,MB_OK
    jmp >>.PQM
:
.WM_KEYDOWN
; more code

.WM_DESTROY
   cmp D[iMsg],WM_DESTROY
    jne >.default        ; no more messages to check
                           ; so pass to DefWindowProc
.PQM
   invoke PostQuitMessage,NULL
    jmp >>.END
.default
   invoke DefWindowProc, [hWnd],[iMsg],[wParam],[lParam]
    ret
.END
    xor rax,rax
    ret
ENDF               ; end of WndProc
Title: Re: Focus
Post by: jj2007 on May 04, 2019, 12:14:41 PM
SetFocus expects a window handle, not a DC.
Title: Re: Focus
Post by: wjr on May 05, 2019, 01:26:34 AM
MK_LBUTTON = 0x0001 and you are always comparing it to 0x000 loaded from the previous line... instead of 0x000 it looks like you were intending on using [wParam]. No need to do that comparison though, since that bit should be set anyways in this case.