15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Dynamically Changing bitmapped buttons

Kenley Sun -- ksun@novice.uwaterloo.ca
Monday, December 02, 1996

Environment: Win 3.1 VC++ 1.52

I want to create a button class that will be able to do the following:
- Display both text and bitmaps at the same time
- Be able to dynamically change the text and bitmaps being displayed on the
  button (depending on user-interaction state, I want a different bitmap
and/or   text label to appear on the button)

What would be the best way to carry this out?  Can the bitmap button class
in MFC be used to do this or would it be easier to completely write this
from scratch?  What do you thing would be the best way to write this from
scratch?

Thanks!

Kenley
 /| _____ _ __  /| ___ _   _ ____ _   _ _ __
| |/ / _ \ `_ \| |/ _ \ | | / ___| | | | `_ \ 
|   <  __/ | | | |  __/ |_| \___ \ |_| | | | |
|_|\_\___|_|_|_|_|\___|\__, |____/\__,_|_| |_|
<__________________________/




Joe Willcoxson -- joew@statsoft.com
Thursday, December 05, 1996

[Mini-digest: 2 responses]

>Environment: Win 3.1 VC++ 1.52
>
>I want to create a button class that will be able to do the following:
>- Display both text and bitmaps at the same time
>- Be able to dynamically change the text and bitmaps being displayed on the
>  button (depending on user-interaction state, I want a different bitmap
>and/or   text label to appear on the button)
>
>What would be the best way to carry this out?  Can the bitmap button class
>in MFC be used to do this or would it be easier to completely write this
>from scratch?  What do you thing would be the best way to write this from
>scratch?

Wow!  Someone on this list besides Mike B. and Scott W. who would actually
consider writing original code! ...and not whining about why MFC doesn't do
what he wants it to.

I would suggest you derive directly from CButton, overriding DrawItem so
that your button is owner drawn.  In my experience, I just use one bitmap
and blit it to different locations (1 pixel offsets) so that it simulates
being pressed.  You will also need to learn how to use LineDDA if you want
to draw it focused.  If you create your own bitmap button you can make it do
whatever the hell you want.  Store the text for the button with the window
HWND, i.e. use GetWindowText/SetWindowText.  They will work fine.  When you
actually go to use the button, make sure you set the style to BS_OWNERDDRAW.

Maybe after you're done, you can post it for all the quiche eaters who
subscribe to this list.  BTW, I am wearing flame retardant clothing:-)
--
Joe Willcoxson (joew@statsoft.com), Senior Software Engineer
Visit us: http://www.statsoft.com, Visit me: http://users.aol.com/chinajoe
#define STD_DISCLAIMER "I speak only for myself"
"Lotteries are a tax on people who do not understand statistics."


-----From: Marty Fried 

At 11:07 PM 12/2/96 -0500, Kenley Sun wrote:
>Environment: Win 3.1 VC++ 1.52
>
>I want to create a button class that will be able to do the following:
>- Display both text and bitmaps at the same time
>- Be able to dynamically change the text and bitmaps being displayed on the
>  button (depending on user-interaction state, I want a different bitmap
>and/or   text label to appear on the button)
>
>What would be the best way to carry this out?  Can the bitmap button class
>in MFC be used to do this or would it be easier to completely write this
>from scratch?  What do you thing would be the best way to write this from
>scratch?

In one of my apps, I used a standard CBitmapButton, but set it up to be a
toggle, where you click and get an alternate bitmap each time (it was lock
and unlock).  I simply called the LoadBitmaps function, giving it the same
bitmap for up and down, then called the button's Invalidate function.  It
worked well for me.  I imagine you could use the same technique.
________________________________
 Marty Fried (mfried@linex.com)
 Marin County, California






| Вернуться в корень Архива |