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: 669
Location: Ukraine
Overclick 01 Sep 2020, 13:51
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 Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 01 Sep 2020, 16:52
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)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
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: 669
Location: Ukraine
Overclick 01 Sep 2020, 17:35
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 Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 01 Sep 2020, 20:36
So, it's just to simplify owner drawn buttons?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
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: 669
Location: Ukraine
Overclick 01 Sep 2020, 22:21
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 Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4024
Location: vpcmpistri
bitRAKE 02 Sep 2020, 01:11
Very interesting. I would call it "duration sensitive button messaging".

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 02 Sep 2020, 01:11
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1777
Roman 15 Jul 2022, 13:55
How many SetTimer-s could sets ?
For example i have 20 buttons. I want do 20 times SetTimer.
And how SetTimer cpu usage ? How load Cpu?

And why Settimer need hwnd? To sand messages window?
Post 15 Jul 2022, 13:55
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2493
Furs 16 Jul 2022, 15:53
SetTimer needs hwnd because it posts WM_TIMER to the window if you decide to not use a callback.

If you don't want this and simply want a callback (function) called, then you can pass NULL to hwnd and supply the last argument to the function of your choice.
Post 16 Jul 2022, 15:53
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.