Article View: comp.windows.ms.programmer
Article #2583Re: Bitmaps on Buttons
From: Whiteside S D B
Date: Mon, 13 May 1991 09:55
Date: Mon, 13 May 1991 09:55
32 lines
2258 bytes
2258 bytes
Many thanks to all who replied to my recent query regarding putting bitmaps on buttons. I've managed to do this thanks to their help! One way to do this is: i) Create the button with the style WS_OWNERDRAW, which means you have to draw the item ii) The window procedure associated with the button (or the dialog box function of the dialog with the control in) will receive 3 kinds of message which it will have to deal with: Each message is of type WM_DRAWITEM. This message has the following components: wParam - child control ID lParam - long pointer to DRAWITEMSTRUCT It's the DRAWITEMSTRUCT that tells you what to do. When the control needs to be first drawn the itemAction field of the structure contains ODA_DRAWENTIRE. When the control is pushed the itemAction is ODA_SELECT and the is also received when the button is released. I keep a BOOL variable to alternate two bitmaps: one for button up, one for button down. When focus is given to the button itemAction is ODA_FOCUS Also in the structure you get: the button window handle, a device context and a rectangle structure showing the size of the button. I used LoadBitmap to get a handle to the bitmap and called Petzold's DrawBitmap() function to put it into the device context. Remember to delete the bitmap once you've done this. (The bitmap is selected into a memory device context, thence into the actual device context by DrawBitmap, so it's okay to delete the bitmap). I use C++ so for speed I load the bitmaps in the class constructor and delete them in the class destructor. I hope this info (which isn't all in one place in the literature I've got) helps others make a very pretty interface! Simon Whiteside
Technical Details
Message-ID:
<5144@servax0.essex.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!mcsun!ukc!stl!servax0!sersun1!whisdReferences:
<1991May9.034417.17137@leland.Stanford.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!mcsun!ukc!stl!servax0!sersun1!whisd From: whisd@sersun1.essex.ac.uk (Whiteside S D B) Newsgroups: comp.windows.ms.programmer Subject: Re: Bitmaps on Buttons Keywords: bitmaps buttons Message-ID: <5144@servax0.essex.ac.uk> Date: 13 May 91 09:55:41 GMT References: <1991May9.034417.17137@leland.Stanford.EDU> Sender: news@servax0.essex.ac.uk Reply-To: whisd@essex.ac.uk (Whiteside S D B) Organization: University of Essex, Colchester, UK Lines: 32