Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CStatic::SetBitmap

311 views
Skip to first unread message

Ronnie Turrentine

unread,
Sep 2, 2009, 9:07:01 AM9/2/09
to
In VS 2003, I created a dialog project which contained a CStatic which
stretched across the top of the dialog. Depending on a "state" in the
program, I would show or hide this static control. I used SetBitmap to set
the static to a small red bitmap. The static would be completely filled in
the red bitmap since it has the style SS_CENTERIMAGE. This worked great. I
have moved to VS 2008 and have the manifest set so I use the latest common
controls, etc. Now the static does not get completely filled by the bitmap
even thought the API doc says it should. Any ideas? Here is the code
snippet.

CStatic* pStatic = (CStatic*) GetDlgItem(IDC_911_STATIC);
pStatic->ModifyStyle(0, SS_BITMAP|SS_CENTERIMAGE|WS_CHILD|WS_VISIBLE, 0);
pStatic->SetBitmap( ::LoadBitmap(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDB_RED)) );

David Ching

unread,
Sep 2, 2009, 9:50:12 AM9/2/09
to

"Ronnie Turrentine" <RonnieTu...@discussions.microsoft.com> wrote in
message news:FC94DC4C-8239-4161...@microsoft.com...

> In VS 2003, I created a dialog project which contained a CStatic which
> stretched across the top of the dialog. Depending on a "state" in the
> program, I would show or hide this static control. I used SetBitmap to
> set
> the static to a small red bitmap. The static would be completely filled
> in
> the red bitmap since it has the style SS_CENTERIMAGE. This worked great.
> I
> have moved to VS 2008 and have the manifest set so I use the latest common
> controls, etc. Now the static does not get completely filled by the
> bitmap
> even thought the API doc says it should. Any ideas?

The doc is at
http://msdn.microsoft.com/en-us/library/bb760773%28VS.85%29.aspx It says:

---
Windows XP: This style bit no longer results in unused portions of the
control being filled with the color of the top left pixel of the bitmap or
icon. Unused portions of the control will remain the background color.
---

You might try SS_REALSIZECONTROL.

But for SS_BITMAP it says the control resizes to the size of the bitmap
anyway, so I'm not sure why there would be any extra area that needed
filling?

-- David

Ronnie Turrentine

unread,
Sep 2, 2009, 10:41:01 AM9/2/09
to
Thanks David and thanks for copying the documentation because I can't get
that link to work.

I'll have to go another route for this now. Should be simple to do... I
don't want the control to resize to the bitmap. The control will resize with
the dialog because I need it to go across the entire dialog.

Anyway, thanks for letting me know about the change.

Joseph M. Newcomer

unread,
Sep 2, 2009, 2:16:45 PM9/2/09
to
See below...

On Wed, 2 Sep 2009 06:07:01 -0700, Ronnie Turrentine
<RonnieTu...@discussions.microsoft.com> wrote:

>In VS 2003, I created a dialog project which contained a CStatic which
>stretched across the top of the dialog. Depending on a "state" in the
>program, I would show or hide this static control. I used SetBitmap to set
>the static to a small red bitmap. The static would be completely filled in
>the red bitmap since it has the style SS_CENTERIMAGE. This worked great. I
>have moved to VS 2008 and have the manifest set so I use the latest common
>controls, etc. Now the static does not get completely filled by the bitmap
>even thought the API doc says it should. Any ideas? Here is the code
>snippet.
>
>CStatic* pStatic = (CStatic*) GetDlgItem(IDC_911_STATIC);

****
Why are you using the obsolete GetDlgItem? This is retro Petzold programming! If you are
using more than one GetDlgItem per year, you are not using MFC correctly. Create a member
variable.
****


>pStatic->ModifyStyle(0, SS_BITMAP|SS_CENTERIMAGE|WS_CHILD|WS_VISIBLE, 0);

****
Put spaces around | so the code is readable. Generally, you should not assume that style
bits like this can be changed; create the control with the styles you want.
****


>pStatic->SetBitmap( ::LoadBitmap(AfxGetResourceHandle(),
>MAKEINTRESOURCE(IDB_RED)) );

****
LoadBitmap can distort the colors of bitmaps. You should use LoadImage.

Generally, I do not trust the bitmap drawing logic; I'm more inclined to simply create a
subclass of the control and do the drawing myself; that way, I know it is going to do what
I want, and not change at the whim of some designer who decides that the control should
work differently than it was specified to work.
joe
****
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages