flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] Can't get hotkey to work

Thread Post new topic Reply to topic

Joined: 25 Sep 2016
Posts: 3
zygkzils 25 Sep 2016, 19:38

I can't get hotkey to work, when looking at olly the msg structure seems to catch the hotkey but in lparam position and in different order, what am I doing wrong ?

;setting window transparency example by carlos hernandez/coconut

format PE GUI 4.0
entry start

ID_STATIC = 1001

include 'win32w.inc'

section '.data' data readable writeable

  _class TCHAR 'FASMWIN32',0
  _title TCHAR 'Layered window example',0
  _error TCHAR 'Startup failed.',0
  _scrollbar TCHAR 'scrollbar',0
  _static TCHAR 'static',0
  _conv TCHAR '%i',0

  hwndstatic dd ?
  hwndscroll dd ?

  buffer rb 32


  lpsi SCROLLINFO sizeof.SCROLLINFO,SIF_ALL,5,255,1,255,0

  msg MSG

; MY CODE ****************************************************************

MOD_NOREPEAT equ 0x4000
F_VKEY       equ 0x46 ;F

MOD_ALT      equ 0x0001   ;not used
MOD_SHIFT    equ 0x0004 ;not used

; MY CODE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

section '.code' code readable executable


        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc
        or      eax,eax
        jz      error
        invoke  CreateWindowEx,WS_EX_LAYERED,_class,_title,WS_VISIBLE+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    eax,eax
        jz      error

; MY CODE ****************************************************************

        invoke RegisterHotKey, NULL, 0, MOD_NOREPEAT, F_VKEY

; MY CODE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop

        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg

; MY CODE ****************************************************************
        cmp [msg.message], F_VKEY   ;Tried before calling translation with no results
        je F_VKEY_func

; MY CODE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        jmp     msg_loop


        invoke MessageBox, 0, 0, 0, 0

        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK
        invoke  ExitProcess,[msg.wParam]

proc WindowProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_HSCROLL
        je      wmhscroll
        cmp     [wmsg],WM_CREATE
        je      wmcreate
        cmp     [wmsg],WM_DESTROY
        je      wmdestroy
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     finish
        mov     eax,[wparam]
        cmp     ax,SB_THUMBPOSITION                      ;received when thumb stops dragging
        je      thumbposition
        cmp     ax,SB_THUMBTRACK                         ;received while thumb is dragging
        je      thumbposition
        cmp     ax,SB_LINELEFT                           ;left arrow clicked
        je      lineleft
        cmp     ax,SB_LINERIGHT                          ;right arrow clicked
        je      lineright
        cmp     ax,SB_PAGELEFT                           ;left space between arrow and thumb clicked
        je      pageleft
        cmp     ax,SB_PAGERIGHT                          ;right space between arrow and thumb clicked
        je      pageright
        jmp     defwndproc
  thumbposition:                                         ;for our purposes we'll handle both drag/stop events here
        mov     [lpsi.fMask],SIF_TRACKPOS
        invoke  GetScrollInfo,[hwndscroll],SB_CTL,lpsi
        push    [lpsi.nTrackPos]
        pop     [lpsi.nPos]
        mov     [lpsi.fMask],SIF_ALL
        jmp     update_window
        cmp     [lpsi.nPos],6                           ;transparency under 5 will make window invisible/useless
        jb      defwndproc
        dec     [lpsi.nPos]
        jmp     update_window
        cmp     [lpsi.nPos],254                         ;transparency over 255 will make window invisible/useless
        jg      defwndproc
        inc     [lpsi.nPos]
        jmp     update_window
        mov     eax,[lpsi.nPage]
        sub     [lpsi.nPos],eax
        jmp     update_window
        mov     eax,[lpsi.nPage]
        add     [lpsi.nPos],eax
        mov     ecx,[lpsi.nPos]
        push    ecx
        cinvoke wsprintf,buffer,_conv,ecx
        invoke  SendMessage,[hwndstatic],WM_SETTEXT,0,buffer
        pop     ecx
        invoke  SetLayeredWindowAttributes,[hwnd],0,ecx,LWA_ALPHA
        invoke  SetScrollInfo,[hwndscroll],SB_CTL,lpsi,1
        xor     eax,eax
        jmp     finish
  wmcreate:                                                         ;x,y,width,height
        invoke  CreateWindowEx,0,_static,_title,WS_VISIBLE+WS_CHILD,25,20,195,25,[hwnd],ID_STATIC,[wc.hInstance],NULL
        mov     [hwndstatic],eax
        invoke  CreateWindowEx,0,_scrollbar,NULL,WS_VISIBLE+WS_CHILD+SBS_HORZ,25,55,195,15,[hwnd],ID_SCROLLBAR,[wc.hInstance],NULL
        mov     [hwndscroll],eax
        invoke  SetScrollInfo,[hwndscroll],SB_CTL,lpsi,0
        invoke  SetLayeredWindowAttributes,[hwnd],0,255,LWA_ALPHA
        xor     eax,eax
        jmp     finish
        invoke  PostQuitMessage,0
        xor     eax,eax
        pop     edi esi ebx

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\

  include 'api\kernel32.inc'
  include 'api\user32.inc'    
Post 25 Sep 2016, 19:38
View user's profile Send private message Reply with quote
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20123
Location: In your JS exploiting you and your system
revolution 25 Sep 2016, 19:50
I don't see where you are detecting the WM_HOTKEY message. So far you are only watching for WM_HSCROLL, WM_CREATE and WM_DESTROY.
Post 25 Sep 2016, 19:50
View user's profile Send private message Visit poster's website Reply with quote

Joined: 25 Sep 2016
Posts: 3
zygkzils 25 Sep 2016, 19:55
Yep, that's probably it my friend Very Happy I'm new to windows and I don't see such obvious mistakes

Thank you!
Post 25 Sep 2016, 19:55
View user's profile Send private message Reply with quote

Joined: 25 Sep 2016
Posts: 3
zygkzils 25 Sep 2016, 20:03
Still can't get it to work, can you give me some hint ? or example of how to use it ?

@@edit: Got it! Very Happy
Post 25 Sep 2016, 20:03
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.