flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > [share] BN_PUSHED for BN_PUSHBUTTON with accelerator

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 199
Overclick
Hi
I want to share my experience how I win a battle against BN_PUSHBUTTON without needs to create subclass and Proc for it to get Pushed state. All you need is BS_NOTIFY style. I share it cause I used a lot of time by myself for searching this solution. I hope it help someone.
Code:
.data
        buttonstimer_16 db 0
        buttonstimer_count dw 200
        buttonstimer_stage dw 0
        activebuttonfocus dw 0
.code
wm_command:
        mov     rax,[wParam]
        mov     rbx,rax
        shr     rax,16

        cmp     rax,BN_CLICKED
        je      bn_clicked
        cmp     rax,BN_DOUBLECLICKED
        je      bn_pushed
        cmp     rax,BN_SETFOCUS
        je      bn_setfocus
        cmp     rax,BN_KILLFOCUS
        je      removebuttonstimer

        xor     rax,rax
        ret

        bn_setfocus:
                mov     [activebuttonfocus],bx
                invoke  SetTimer,[hWnd],15,50,0
                xor     rax,rax
                ret
        bn_clicked:
                cmp     bx,ID_YOUR_BUTTON
                je      removebuttonstimer
                xor     rax,rax
                ret
        bn_pushed:
                ;...
                ;do whatever you want here as single click
                ;...
                ret
wm_timer:
        cmp     [wParam],15
        je      buttonstimer
        cmp     [wParam],16
        je      bn_pushedtimer

        xor     rax,rax
        ret
        buttonstimer:
                cmp     [activebuttonfocus],0
                jne     @F
                jmp     removebuttonstimerself
                @@:
                invoke  SendDlgItemMessage,[hWnd],[activebuttonfocus],\
                                BM_GETSTATE,0,0
                bt      ax,3
                jc      @F
                removebuttonstimerself:
                invoke  KillTimer,[hWnd],15
                jmp     removebuttonstimer
                @@:
                bt      ax,2
                jnc     removebuttonstimer
                cmp     [buttonstimer_16],0
                jne     @F
                invoke  SetTimer,[hWnd],16,500,0
                mov     [buttonstimer_16],1
                jmp     bn_pushed
                @@:     
                xor     rax,rax
                ret
                removebuttonstimer:
                invoke  KillTimer,[hWnd],16
                mov     [buttonstimer_16],0
                mov     [buttonstimer_count],200
                mov     [buttonstimer_stage],0
                xor     rax,rax
                ret
        bn_pushedtimer:
                cmp     [activebuttonfocus],0
                je      removebuttonstimerself
                inc     [buttonstimer_stage]
                cmp     [buttonstimer_stage],1
                jne     @F
                jmp     setbn_pushedtimer
                @@:
                cmp     [buttonstimer_stage],10
                jne     @F
                mov     [buttonstimer_count],100
                jmp     setbn_pushedtimer
                @@:
                cmp     [buttonstimer_stage],30
                jne     bn_pushed
                mov     [buttonstimer_count],20
                setbn_pushedtimer:
                invoke  SetTimer,[hWnd],16,[buttonstimer_count],0
                jmp     bn_pushed    

If you don't need accelerator just watch for BM_GETSTATE returned flags for Pushed state.
Post 01 Sep 2020, 13:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3025
Location: vpcmipstrm
bitRAKE
I really like these kinds of helpful snippets of functionality. Are you trying to do a toggle state or something like that? I'll need to create a template to try this out and see what the effect is.

OFFTOPIC: "bt eax,3" is one byte shorter and the same functionality.

_________________
¯\(°_o)/¯ unlicense.org
Post 01 Sep 2020, 16:52
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 199
Overclick
Quote:

I really like these kinds of helpful snippets of functionality. Are you trying to do a toggle state or something like that? I'll need to create a template to try this out and see what the effect is.

You don't need that))
Quote:

"bt eax,3" is one byte shorter and the same functionality.

I'll keep in mind, thanks. I'm sure there is some more optimisations can be done.
Post 01 Sep 2020, 17:35
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3025
Location: vpcmipstrm
bitRAKE
So, it's just to simplify owner drawn buttons?

_________________
¯\(°_o)/¯ unlicense.org
Post 01 Sep 2020, 20:36
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 199
Overclick
It is BN_PUSHBUTTON which have limited notifications especially for Pushed stage.
Post 01 Sep 2020, 22:21
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3025
Location: vpcmipstrm
bitRAKE
Very interesting. I would call it "duration sensitive button messaging".

_________________
¯\(°_o)/¯ unlicense.org
Post 02 Sep 2020, 01:11
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.