News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Focus

Started by shankle, May 04, 2019, 07:03:51 AM

Previous topic - Next topic

shankle

       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

jj2007

SetFocus expects a window handle, not a DC.

wjr

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.