Author Topic: Focus  (Read 2712 times)


  • Member
  • ****
  • Posts: 868
« on: May 04, 2019, 07:03:51 AM »

; 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

    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
; more code

   cmp D[iMsg],WM_DESTROY
    jne >.default        ; no more messages to check
                           ; so pass to DefWindowProc
   invoke PostQuitMessage,NULL
    jmp >>.END
   invoke DefWindowProc, [hWnd],[iMsg],[wParam],[lParam]
    xor rax,rax
ENDF               ; end of WndProc


  • Member
  • *****
  • Posts: 13275
  • Assembly is fun ;-)
    • MasmBasic
Re: Focus
« Reply #1 on: May 04, 2019, 12:14:41 PM »
SetFocus expects a window handle, not a DC.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.


  • Member
  • **
  • Posts: 238
    • WJR's website
Re: Focus
« Reply #2 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.