I have posted a msg a while ago, and now I finally minimized my problem. Its the button doesn't work!

I don't know how exactly detect when a button is pushed or not,

and I duno whats the rite message to send to the button to make it pushed or unpushed,

BN_PUSHED, BN_UNHILITE, BN_HILITE, and BST_PUSHED

which of these message is the rite one for making the button pushed and unpushed???

what I want to do with my button is that :
when I clicked on the button, it than stay pushed, but when I click it again, it will than unpushed.


how can it be done???


please help me out !


thankx in adv,
Posted on 2002-08-17 04:21:24 by Yanda
From the sounds of your question, your working on a toolbar, correct? Anyways, toolbar buttons use styles to determine how they act when the user clicks them, in your case, you want to create a button with the TBSTYLE_CHECK style. This will give you the toogle effect, click on and click off.

Here is an example:


local mytbbutton:TBBUTTON

; Add button...
invoke RtlZeroMemory, addr mytbbutton, sizeof mytbbutton
mov mytbbutton.iString, NULL
mov mytbbutton.idCommand, ID_TB_PEN
mov mytbbutton.fsState, TBSTATE_ENABLED
mov mytbbutton.fsStyle, TBSTYLE_CHECK
push g_icoPen
pop mytbbutton.iBitmap
invoke SendMessage, l_hwndToolbar, TB_ADDBUTTONS, 1, addr mytbbutton


this simply makes a button that uses an icon with no text and as you can see it will function like a toggle thanks to the TBSTYLE_CHECK style. Also note how I've assigned a constant value which is held in the equate, ID_TB_PEN. It's just a number that uniqely identifies your button so windows can later tell you that it was clicked. This number is important or no message is sent (I think). The next step is then handling the click event through your msg proc.

Hope that helps,
James:alright:
Posted on 2002-08-17 16:07:28 by JamesE
add the BS_PUSHLIKE style
Posted on 2002-08-17 19:27:34 by Sabeel
JamesE : hehe nope your wrong, me not working on toolbar buttons, me just working on a normal standard button.
but thankx for the info.


Sabeel: cool thankx, I will give it a try and see what it will do.
thankx for now,,


"I'll be back",, :grin:


thankx
Posted on 2002-08-18 01:44:12 by Yanda
err I am back :(

I added the style u mentioned sabeel, but it doesn't seem to make any differences.


I can get the button STAY PUSHED, when I click on it,, but it will UNPUSHED automatically when I click on other controls, like edit controls, my purpose is that I want it stay PUSHED even I click on other controls.

anyone please give me so advices,,,



thankx in adv,
Posted on 2002-08-18 02:50:42 by Yanda
Yanda,

What you are trying to do is use a standard push button as a check button which is not really what they are intended to do. You can try combining the styles to see if you can get a push button to behave that way but it may not be reliable.

A long time ago I played with the styles in HEX setting parts of the ORRED numbers manually and I could get a push button to behave like a check box, in OR out, but its not documented behaviour so it may not work across all versions of Windows.

Regards,

hutch@movsd.com
Posted on 2002-08-18 03:19:10 by hutch--
Yanda, if i understand you correctly, you can achieve what you want by using an owner drawn button (BS_OWNERDRAW)

You can have bitmaps for ON and OFF and complete control over which is shown and when

Search your WinAPI reference for DRAWITEMSTRUCT, WM_MEASUREITEM and WM_DRAWITEM

Regards
eGo
Posted on 2002-08-18 04:19:55 by eGo
Yanda,

I've used the BMPBUTN.ASM from Hutch's M32LIB folder for a project I was working on and I wanted the ability to have a couple of buttons stay toggled up or down, so I altered the BMPBUTN.ASM to achieve this.

I don't know if you're using Hutch's Masm32 package...but if you are...

Basically I inserted code that checked for the specific buttons I wanted to toggle, and then changed the image that would be displayed when the mouse button was released:

First, in my main procedure, I check if the button is clicked with the mouse and if so, I toggle an indicator (TogJPG):



.ELSEIF wParam == 504 ; button ID# to toggle
mov eax, TogJpg
xor eax, 1
mov TogJpg, eax
...
Do whatever else the button does
...




Then I inserted into the BmpButnProc:



...
code from BmpButnProc
...

.elseif uMsg == WM_LBUTTONUP

.if cFlag == 0
ret
.else
mov cFlag, 0
.endif
;_____________________here's what I added for button toggle__

invoke GetDlgCtrlID,hWin
mov ID, eax

.if ID == 504 ; ID of a toggle Button
.if TogJpg == 1 ; indicator if up or down now
invoke GetWindowLong,hWin,0
mov hBmpU, eax
invoke GetWindowLong,hWin,8
mov hImage, eax
invoke SendMessage, Image, STM_SETIMAGE, IMAGE_BITMAP, hBmpU
.else
invoke GetWindowLong,hWin,4
mov hBmpD, eax
invoke GetWindowLong,hWin,8
mov hImage, eax
invoke SendMessage, hImage, STM_SETIMAGE, IMAGE_BITMAP, hBmpD
.endif

.else
invoke GetWindowLong,hWin,0
mov hBmpU, eax
invoke GetWindowLong,hWin,8
mov hImage, eax
invoke SendMessage, hImage, STM_SETIMAGE, IMAGE_BITMAP, hBmpU
.endif

;___________________________________end of addin for button toggle__

mov eax, lParam
cwde
mov ptX, eax
mov eax, lParam
rol eax, 16
cwde
mov ptY, eax

invoke GetWindowRect,hWin,ADDR Rct
...
the rest of BmpButnProc
...


I'm sure it could be done more elegantly, but this worked fine for me.
Posted on 2002-08-19 09:22:30 by gscundiff
thankx gscundiff


actually I already checked it out,, I know how to work it out on owner draw, or like the way Bmpbutton did in the masm32 package.

but I want to know why the way I am doing now isn't work,,

so far I noticed that there is something wrong within the message handling for my button,,

coz when I create 2 buttons, and two of them toggles each other. which mean when I have first button clicked than it can toggle the second button up or down. and when the second button clicked than it can toggle the first button up or down by using these messages: BM_GETSTATE or BM_SETSTATE.


but thankx for the info gscundiff !:alright:

I still need help:confused:
Posted on 2002-08-20 00:18:57 by Yanda