Article View: borland.public.cppbuilder.nativeapi
Article #4761Re: Capture WM_NCPAINT?
From: JD
Date: Tue, 29 Nov 2005 11:00
Date: Tue, 29 Nov 2005 11:00
77 lines
3997 bytes
3997 bytes
Paw Suddergaard <paw@top-house.dk> wrote:
>
>Oh i was "simplyfying" my code...
You need to always post the actual code.
> But i still have the problem heres the code now:
The code works. If you add a Sleep after you draw the caption,
you'll see that but then after the Sleep is over, the caption
is painted again!!
I don't know if this is a feature of the OS (XP) or something
the VCL is doing and I'm not inclined to sift through the
messages to try to figure it out. Just knowing that it's
happening is enough for me.
Also, WM_NCPAINT is not sent when the form loses focus but
still the Caption is repainted as disabled!
The following code works but it doesn't account for the form
state so you'll have to add it. It's also slow getting the
caption displayed so you might want to try drawing the caption
twice - (once before you post the custom message):
private: // User declarations
#define UWM_PAINT (WM_USER + 100)
typedef TForm inherited;
MESSAGE void __fastcall WMNCPaint( TMessage &Message );
MESSAGE void __fastcall UWMPaint( TMessage &Message );
MESSAGE void __fastcall WMKillFocus( TMessage &Message );
public: // User declarations
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER( UWM_PAINT, TMessage, UWMPaint )
VCL_MESSAGE_HANDLER( WM_NCPAINT, TMessage, WMNCPaint )
VCL_MESSAGE_HANDLER( WM_KILLFOCUS, TMessage, WMKillFocus )
END_MESSAGE_MAP( inherited )
//-------------------------------------------------------------
MESSAGE void __fastcall TForm2::WMNCPaint(TMessage &Message)
{
inherited::Dispatch(&Message);
::PostMessage( Handle, UWM_PAINT, 0, 0 );
}
//-------------------------------------------------------------
MESSAGE void __fastcall TForm2::WMKillFocus(TMessage &Message)
{
inherited::Dispatch(&Message);
::PostMessage( Handle, UWM_PAINT, 0, 0 );
}
//-------------------------------------------------------------
MESSAGE void __fastcall TForm2::UWMPaint(TMessage &Message)
{
TCanvas *pCanvas = new TCanvas;
pCanvas->Handle = ::GetWindowDC( Handle );
pCanvas->Font->Style = TFontStyles() << fsBold;
pCanvas->Font->Color = clRed;
// calculate the left coordinate for caption drawing
int intLeftShift = GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CXBORDER);
// calculate the top coordinate for caption drawing
int intTopShift = ((GetSystemMetrics(SM_CYCAPTION) - abs(pCanvas->Font->Height)) / 2);
// output the caption string
int pMode = ::SetBkMode( pCanvas->Handle, TRANSPARENT );
pCanvas->TextOut(intLeftShift, intTopShift, "Test!");
::SetBkMode( pCanvas->Handle, pMode );
::ReleaseDC( Handle, pCanvas->Handle );
pCanvas->Handle = NULL;
delete pCanvas;
}
//-------------------------------------------------------------
~ JD
Technical Details
Message-ID:
<438c42d7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43843bb9$1@newsgroups.borland.com> <43843d59$1@newsgroups.borland.com> <438b21c8$1@newsgroups.borland.com> <438b89a3$1@newsgroups.borland.com> <438c0d22$1@newsgroups.borland.com> <438c1578$1@newsgroups.borland.com> <438c19b9$1@newsgroups.borland.com> <438c1ec8$1@newsgroups.borland.com> <438c209c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,95cf0255de9936de X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Capture WM_NCPAINT? Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 64.12.116.131 X-Forwarded-For: 172.163.217.13 References: <43843bb9$1@newsgroups.borland.com> <43843d59$1@newsgroups.borland.com> <438b21c8$1@newsgroups.borland.com> <438b89a3$1@newsgroups.borland.com> <438c0d22$1@newsgroups.borland.com> <438c1578$1@newsgroups.borland.com> <438c19b9$1@newsgroups.borland.com> <438c1ec8$1@newsgroups.borland.com> <438c209c@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <438c42d7$1@newsgroups.borland.com> Date: 29 Nov 2005 04:00:23 -0700 X-Trace: newsgroups.borland.com 1133265623 207.105.83.66 (29 Nov 2005 04:00:23 -0700) Lines: 78 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail