How to stop WM_PAINT from flatting out buttons in a superclass?

Started by rogerio, May 05, 2009, 10:25:07 PM

Previous topic - Next topic

rogerio

If I create a superclass so that I can have several buttons and then add a WM_PAINT, the buttons flatten out. Is this a M$ issue or is there a work around? I know that there are other ways to create the buttons, but I was wanting to add some graphics to them using paint. Thanks...

hutch--

rogerio,

There is a style for buttons which from memory is BS_OWNERDRAW which means you control the complete appearance of the button. I personally use a custom control so that you are in full control of the button logic and appearance if this capacity is needed.

With your question, check out that you are returning the right value for WM_PAINT and see if you need to use the PAINTSTRUCT structure with the BeginPaint/EndPaint API pair.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rogerio

Hi hutch, thanks for the reply. I am using Begin/End paint and returning the hdc and using PAINTSTRUCT. I have noticed that WM_PAINT is temperamental; for instance, if WM_PAINT is present and Begin/End paint are not, the taskbar icon takes about 5 seconds to appear - I am running XP PRO SP3. I think I have tried every combination of attributes possible to keep the button from collapsing.

Looks like I will have to use your other suggestion with the custom control. Thanks...

hutch--

What are you returning from the WM_PAINT message processing ? If you return zero (0) you do not get the default processing for the window (button in this instance). It sounds like a missing repaint problem but there is another consideration, is this a dialog or a window as the two behave differently ? I have seen instances where in a dialog the paint process gets messed up due to the automatic characteristic of a system dialog.

If you can post the bare skeleton of the logic you are using with the WM_PAINT message processing and it may just be something simple. I remember a few of these driving me NUTZ years ago.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

rogerio

Well, I gave up on it and blew it away after I had spent a week trying to work it out. The program just wasn't worth the effort, but here are the basics: I used Icze tut 22 and replaced the edits with buttons. Then I tried placing a ellipse on the button using paint like this:

LOCAL ps:PAINTSTRUCT

.if eax==WM_PAINT
    invoke BeginPaint,hEDT,addr ps

        mov hDC,eax
        invoke Ellipse,hDC,10,10,20,20  ; this was contained in another function with all of the hPen, hBrush info, etc.

    invoke EndPaint,hEDT,addr ps


Every entity was created with CreateWindowEX in including the main window. The buttons were present with the entire WM_PAINT removed, but they flatten out if it was present. Yep, it drove me up the wall, and I still don't understand it.

donkey

What is your return value from WM_PAINT ? It should be 0 but the code you posted does not show what you are returning so I thought I would ask.

Buttons are difficult to paint since you must handle the bitmap and you must also draw a frame rectangle if you don't want them to appear flat. You would use the DrawFrameControl function for this as follows:

; For a pushed button
invoke DrawFrameControl, hdc, OFFSET rectBTN, DFC_BUTTON, DFCS_BUTTONPUSH+DFCS_PUSHED+DFCS_ADJUSTRECT
; For a normal (unpushed) button
invoke DrawFrameControl, hdc, OFFSET rectBTN, DFC_BUTTON, DFCS_BUTTONPUSH+DFCS_ADJUSTRECT
; The DrawFrameControl function in this instance will adjust rectBTN to a new rect that will be the bounding rectangle in which to draw your bitmap


It is important to remember that there is no non-client area in a button, when you draw your ellipse and disallow any further processing the frame rectangle is not drawn so you have no 3D effect and no animation. I have a complete example of processing the WM_PAINT message for buttons that I will fix up and post as an example on my website soon, it is written in GoAsm so I hesitate to post it in this sub-forum...

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

hutch--

rogerio,

A button is actually a predefined window class and this is why its difficult to change its appearance. A standard button is simply a system component that changes from one OS version to another as the vendor Microsoft see fit. To control the appearance of a button, its actually easier to fully write your own, a CreateWindowEx() and a corresponding message handler and then you can draw or write anything you like on the button face as it is just the client area of a window.

You can use the custom button code from masm32 as a bare template to write your own and modify it any way you like to get the results you want. Thats what low level programming is about. You will find the UP / DOWN and dragged on and off logic fun.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

UtillMasm

QuoteWarnning:
QuoteI have a complete example of processing the WM_PAINT message for buttons that I will fix up and post as an example on my website soon.

WoooOooo!
:thumbu

rogerio