![](smile.gif)
MFC CStatic Question
I have a CStatic in an MFC program that I''m trying to display info to the user on (it''s a Rectangle control, not a static text control). I need to be able to handle WM_PAINT messages sent to it, so the stuff on it doesn''t get erased as soon as something goes over it, but when I look in the ClassWizard, the only message it seems I can handle (easily?) is BN_CLICKED, which I don''t need
Is there any way to handle WM_PAINT messages for CStatic controls?
![](smile.gif)
i had to use a CStatic once, and unfortunatly, there was no way to automatically update it. Sorry. Maybe there is but i dont know it.
=======================================
A man with no head is still a man.
A head with no man is plain freaky.
=======================================
A man with no head is still a man.
A head with no man is plain freaky.
Few things:
CStatic is, when it all comes down, a CWnd (just like pretty much every other control MFC has). So, it can do anything a CWnd can do.
Unfortunately, Microsoft decided to protect us from having way too many UID''s thanks to the large number of CStatics that never change that most apps have... so they make a generic CStatic UID in the resource.h and map all CStatics to that inherently. Fortunately, you don''t have to leave it that way.
Change the UID of the CStatic you want to change using your resource editor, then you will be able to use MAKEINTRESOURCE and all that to get that particular CStatic control, and gain control over repainting and whatever other CWnd functionality you might want to toy with.
HTH
-fel
CStatic is, when it all comes down, a CWnd (just like pretty much every other control MFC has). So, it can do anything a CWnd can do.
Unfortunately, Microsoft decided to protect us from having way too many UID''s thanks to the large number of CStatics that never change that most apps have... so they make a generic CStatic UID in the resource.h and map all CStatics to that inherently. Fortunately, you don''t have to leave it that way.
Change the UID of the CStatic you want to change using your resource editor, then you will be able to use MAKEINTRESOURCE and all that to get that particular CStatic control, and gain control over repainting and whatever other CWnd functionality you might want to toy with.
HTH
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
quote:
Original post by Qoy
I have a CStatic in an MFC program that I''m trying to display info to the user on (it''s a Rectangle control, not a static text control). I need to be able to handle WM_PAINT messages sent to it, so the stuff on it doesn''t get erased as soon as something goes over it, but when I look in the ClassWizard, the only message it seems I can handle (easily?) is BN_CLICKED, which I don''t need
Is there any way to handle WM_PAINT messages for CStatic controls?
Qoy,
Take a look at CodeGuru
You should be able to find some info on using CStatics in the STATIC CONTORL section.
Good Luck,
David "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
May 16, 2001 01:29 AM
Yes, just change the IDC_STATIC to anything else.
void CStaticButton::OnPaint()
{
CPaintDC dc(this); // needs this
}
- Woodie Dovich
void CStaticButton::OnPaint()
{
CPaintDC dc(this); // needs this
}
- Woodie Dovich
I think what he wants to do is *derive* a class from CStatic, and use that in place of the normal one so he can handle the paint messages. That is super easy (use the classwizard ''new class''!), and you can still use the dialog editor to place the static, and then just change the CStatic member variable in the dialog header file to CMyStatic or whatever.
without deriving from CStatic there is a way of doing it, but its a pain.
Override PreTranslateMessage in the parent class.
then add code like this
if (pMsg && ((pMsg->message)==WM_PAINT))
{
if (::GetDlgCtrlID(pMsg->hwnd) == IDC_STATICIWANTTOHANDLE)
{
HDC hDC = ::GetDC(pMsg->hwnd);
// Do something different here
::ReleaseDC(pMsg->hwnd, hDC);
}
// Return TRUE to stop processing here or FALSE to
// let it go on its merry way
}
Yuch. That''s ugly. Derive from CStatic.
Douglas Sutherland
without deriving from CStatic there is a way of doing it, but its a pain.
Override PreTranslateMessage in the parent class.
then add code like this
if (pMsg && ((pMsg->message)==WM_PAINT))
{
if (::GetDlgCtrlID(pMsg->hwnd) == IDC_STATICIWANTTOHANDLE)
{
HDC hDC = ::GetDC(pMsg->hwnd);
// Do something different here
::ReleaseDC(pMsg->hwnd, hDC);
}
// Return TRUE to stop processing here or FALSE to
// let it go on its merry way
}
Yuch. That''s ugly. Derive from CStatic.
Douglas Sutherland
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement