I've been working on a button that has two states ie On\Off type thing. For each state the Text Colour, Back Colour and text string can be different. Hopefully I haven't spent time reinventing the wheel. I seem to have a slight problem in when that the button is first drawn and the mouse is over it the mousecursor chenges to the hour glass until the mouse is moved.The same thing happens if in response to WM_COMMAND message I bring up a MessageBox with no owner.

Any help or pointing out the "Bleeding Obivious" would be greatly appreciated.

Thanks
Posted on 2001-09-18 07:13:07 by edgarbrits
Sounds like you want to do owner drawn buttons.

I have an example 'class' file of this in one of my test programs, on my web-site. It draws a custom window with objects (mainly the button objects). The 'class' souce is appended here, but i will hack out the needed parts below:

(This loads an up and down bitmap for the button, but there is no reason why you can't draw text and lines etc instead on the HDC)



CBBu_Class db "button",0

.code

->> WM_CREATE

; Create a button window...
; you can do extra SetWindowLong APIs here to control
; icons (hour glass stuff) after this.

invoke CreateWindowEx, NULL, addr CBBu_Class, NULL, \
BS_OWNERDRAW or WS_CHILD or WS_VISIBLE, \
xP, yP, wx, wy, hWnd, NULL, hInst, NULL
mov [edi].hWnd, eax

invoke LoadBitmap, hInst, BitDown
mov [edi].hButtonDown, eax

invoke LoadBitmap, hInst, BitUp
mov [edi].hButtonUp, eax





-->> WM_DRAWITEM message: A== lParam sent:

mov esi, A
mov eax, (DRAWITEMSTRUCT PTR [esi]).hwndItem
.if( eax == [edi].hWnd )
invoke CreateCompatibleDC, (DRAWITEMSTRUCT PTR [esi]).hdc
mov hdc, eax

mov eax, (DRAWITEMSTRUCT PTR [esi]).itemState
and eax, ODS_SELECTED
.if( eax )
invoke SelectObject, hdc, [edi].hButtonDown
.else
invoke SelectObject, hdc, [edi].hButtonUp
.endif

invoke BitBlt, (DRAWITEMSTRUCT PTR [esi]).hdc, \
(DRAWITEMSTRUCT PTR [esi]).rcItem.left, \
(DRAWITEMSTRUCT PTR [esi]).rcItem.top, \
(DRAWITEMSTRUCT PTR [esi]).rcItem.right, \
(DRAWITEMSTRUCT PTR [esi]).rcItem.bottom, \
hdc, NULL, NULL, SRCCOPY
invoke DeleteDC, hdc
.endif


-->> WM_DESTROY
invoke DeleteObject, [edi].hButtonUp
invoke DeleteObject, [edi].hButtonDown
invoke DestroyWindow, [edi].hWnd


Hope this can help.. Basically ignore all the .xxx stuff and think of them as unique variables.

NaN
Posted on 2001-09-18 10:41:58 by NaN
Stupid me,

I tired it on Win95 & 98 it it was ok. It just seems to be my Win2k
box.

:stupid:


OOP scares me. :confused:
Posted on 2001-09-20 03:42:27 by edgarbrits
OOP is ez... what is scarry is when people dont realize when something should be OOP or not.. (and personally, i feel just as guilty as anyone else, it takes experience, but when you reailize when and when not, you got a powerfull asset on your side...)

NaN
Posted on 2001-09-21 02:40:56 by NaN