News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help with onwer drawn buttons!!!

Started by xandaz, March 09, 2010, 10:56:02 PM

Previous topic - Next topic

xandaz

   Hey guys.... here i am again. i've been trying to create owner drawn buttons and it works more or less fine but i think the buttons are slow. They seem to take time to deselect. Can someone help?
   This is more or less what is done:

WndProc PROC blah,blah....

.if WM_CREATE and lParam.hWndParent==NULL
   invk. CreateWindowEx,....BS_OWNERDRAWN,.....
   mov hButton,eax

.elseif uMsg==WM_MEASUREITEM or WM_INITDIALOG ; none of the messages seem to be sended
; so i had to load the bitmaps in WM_CREATE ( bitmaps == both states of button)

.elseif uMSg==WM_DRAWITEM
   
      mov edi,lParam
      assume edi:PTR DRAWITEMSTRUCT
      invk. CreateCompatibleDC,[edi].hdc
      mov Memdc,eax

     .if lparam.itemState==ODS_FOCUS ; seems to be working better than ODS_SELECTED as in the SDK examples
           invk. SelectObject, hBitmap1
     .else
           invk. SelectObject,hBitmap2
     .endif
           invk. StretchBlt,[edi].hdc,0,0,32,32,Memdc,0,0,32,32,SRCCOPY

; After all this is done the appears drawn but unlike a normal button such as with BS_PUSHBUTTON that when clicked repeatedlly responds on time , this owner drawn button takes a little more time.
; Also i've created a debug window to post me the different itemStates of the DRAWITEMSTRUCT of WM_DRAWITEM messages and the onely state that i get is ODS_FOCUS and action ODA_SELECT.
; there aren't any more styles that can be combined with BS_OWNERDRAW are there?
can some pls spare some time and help?
i appreciatte always
bests from xandaz

Ramon Sala

.if WM_CREATE and lParam.hWndParent==NULL

should be:

.if uMsg==WM_CREATE and lParam.hWndParent==NULL
Greetings from Catalonia

Ghandi

Even:



.if (uMsg == WM_CREATE) && (lParam.hWndParent == NULL)

.endif



HR,
Ghandi

xandaz

   Yeah , i know that... i just put it this way because it seemed simpler to wirte it that way... in the file it's actually :
    .if uMsg==WM_CREATE
        mov edi,lParam
        assume edi:PTR CREATESTRUCT
        .if [edi].hWndParent==NULL

    Maybe you can just gimme a link to an owner drawing tute?
    Thanks anyway...

hutch--

xandaz,

You have the source available for a bitmap button in the masm32 library, supply it two bitmaps, up and down and you have absolute control of the appearance.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

xandaz

 Hi again guys. Again it was a stupid mistake. I forgot to read the part where it says that DRAWITEMSTRUCT.itemState is a combination of several values.
So, as i wasn't using TEST or ANDs i never got the ODS_SELECTED state. Things seem to be working fine except for the fact that the button still seeems a bit slow.
I've done something among these lines - here, i'm just specifying the WM_DRAWITEM message processing :

WndProc   PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

   .
   .
.if uMSg==WM_CREATE
   .
   .
   invoke   LoadBitmap,hInstance,addr BitmapClicked
   mov   hBmpClicked,eax
   invoke   LoadBitmap,hInstance,addr BitmapUnclicked
   mov   hBmpUnclicked,eax      
   .
   .
   .
   .
.elsesif uMsg==WM_CREATE
   
   mov   edi,lparam
   assume   edi:PTR DRAWITEMSTRUCT
   
   invoke   CreateCompatibleDC,[edi].hDC
   mov   MemDC,eax
   
   mov   eax,[edi].itemState
   test   eax,ODS_SELECTED
   jz   unclicked
   invoke   SelectObject,hBmpCLicked
   jmp   DrawButton
uncliked:
   invoke   SelectObject,hBmpUnclicked
DrawButton:
   invoke   BitBlt,[edi].hDC,0,0,32,32,MemDC,0,0,SRCCOPY
   invoke   DeleteDC,MemDC

.elseif uMsg==WM_DESTROY
   invoke   DeleteObject,hBmpClicked
   invoke   DeleteObject,hBmpUncliked
   invoke   PostQuitMessage,NULL
   
   .
   .
   .
WndProc   endp      

   I'm not sure what you mean hutch. Are u talking about bmpbutton example? it's just that i'd like to draw the button myself and give it the best performance.
   Thanks anyways pplz
   bests from me :).

xandaz

   Thanks hutch. I saw the BmpButton routine. It seems kinda complicated tho. Isn't there a way to make BS_OWNERDRAW more efficient? Or am i doing sometihng wrong?
   thnaks and laterz

xandaz

    Sorry i just saw that i put WM_CREATE two times. The second is WM_DRAWITEMSTRUCT. sowwy
   bye! :)

Greenhorn__

#8
Hi,

maybe this sample helps you a little bit ...

;[...]

.if (uMsg == WM_CREATE)
;-- create a private DC for drawing actions and
;   store it in a global variable
invoke GetDC, 0 ; Desktop window
push eax ; save the Desktop window DC
invoke CreateCompatibleDC, eax
.if (eax)
mov g_hdcMem, eax ; store the private DC
.else
; error handling ...
.endif
pop eax ; restore the Desktop window DC ...
invoke ReleaseDC, eax ; ... and release it.

;-- Bitmap stuff
invoke   LoadBitmap,hInstance,addr BitmapClicked
.if (eax)
mov   g_hBmpClicked,eax
.else
; error handling ...
.endif
invoke   LoadBitmap,hInstance,addr BitmapUnclicked
.if (eax)
mov   g_hBmpUnclicked,eax
.else
; error handling ...
.endif

.elseif (uMsg == WM_DESTROY)
.if (g_hdcMem)
invoke DeleteDC, g_hdcMem ; delete the private DC
.endif
; cleanup bitmaps here ...

.elseif (uMsg == WM_DRAWITEM)
invoke DrawButton, hWnd, lParam

;[...]

DrawButton proc hWnd:DWORD, lpdis:DWORD

mov   edi,lpdis
assume   edi:PTR DRAWITEMSTRUCT

.if ([edi].CtlType != ODT_BUTTON)
mov eax, 0 ; this message is not for us ...
ret
.endif

.if ([edi].itemState & ODS_SELECTED)
invoke SelectObject, g_hdcMem, g_hBmpClicked
push eax ; save hbmpOld
invoke BitBlt,[edi].hDC,0,0,32,32,MemDC,0,0,SRCCOPY
pop eax
invoke SelectObject, g_hdcMem, eax ; restore private DC
.if ([edi].itemState & ODS_HOTLIGHT)
;[...]
.else
invoke SelectObject, g_hdcMem, BitmapUnclicked
push eax ; save hbmpOld
invoke BitBlt,[edi].hDC,0,0,32,32,MemDC,0,0,SRCCOPY
pop eax
invoke SelectObject, g_hdcMem, eax ; restore private DC
.endif

; text drawing routines ...

assume edi:nothing
mov eax, 1
ret
DrawButton endp



You can take a look at here for ownwerdrawn examples ...
http://www.c-plusplus.de/forum/viewtopic-var-t-is-39375.html


Regards
Greenhorn
You can fool some of the people all of the time, and all of the people some of the time, but you can not fool all of the people all of the time.
(Abraham Lincoln)

xandaz

   Thanks a lot Greenhorn. I'm looking into it as we speak. i'll let you know later if things went well.
   Bests from X

donkey

Hi xandaz,

I have an example in GoAsm on my website of owner drawn buttons with the images coming from an image list. Though its written in GoAsm it is fairly easy to follow for a MASM user as the syntax is similar and the example is very small. I've never had any complaints over speed with it and it seems pretty quick.

http://www.quickersoft.com/donkey/files/OwnerDrawBtn.zip

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

xandaz

    Thanks a lot donkley. i checked it out. I'm convinced that that's the way it is with owner drawn buttons. Yours aren't as fast as the regular buttons either. They look pretty good tho.
    Ty and bests from X :)