🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
16 messages
16 total messages Started by JD Fri, 25 Apr 2003 05:17
WM_NCPAINT & clipping
#16820
Author: JD
Date: Fri, 25 Apr 2003 05:17
4 lines
940 bytes
Could someone please show me how to determine what part of the nonclient area should not be painted?

~ JD
Re: WM_NCPAINT & clipping
#16825
Author: Ed Mulroy [TeamB]
Date: Fri, 25 Apr 2003 12:55
14 lines
1554 bytes
When you receive the WM_NCPAINT message the wParam argument is a handle to
the region to be painted.  All non-client paint messages give you a
rectangular region and a call to GetRegionData can be used to find the
rectangular coordinates of the area to be painted.  The part of the
nonclient area to not be painted is the part of the area for which you have
not received a message requesting that it be painted.

.  Ed

> JD wrote in message
> news:3ea8c4fd$1@newsgroups.borland.com...
>
> Could someone please show me how to determine what
> part of the nonclient area should not be painted?
Re: WM_NCPAINT - no region to be had
#16739
Author: JD
Date: Sat, 26 Apr 2003 15:01
39 lines
2384 bytes
"Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> wrote:
> When you receive the WM_NCPAINT message the wParam argument
> is a handle to the region to be painted. All non-client paint
> messages give you a rectangular region and a call to GetRegionData
> can be used to find the rectangular coordinates [...]

I tried to GetRegionData but there's never anything there which
I know is not the case so my code must be in error. Can you
tell me what I'm doing wrong please?

~ JD
 

void __fastcall TForm1::NewWindowProc( TMessage& Message )
{
    OldWindowProc( Message );
    if( Message.Msg == WM_NCPAINT )
      {
          char *Buffer = NULL;
          RGNDATA *pRgnData;
          HRGN hrgn = (HRGN) Message.WParam;
          DWORD dwCount = GetRegionData( hrgn, 0, NULL );

          if( dwCount > 0 )
            {
                Label1->Caption = "Made it to here";
                Buffer = new char[ dwCount ];
                pRgnData = reinterpret_cast<RGNDATA*>( Buffer );
                GetRegionData( hrgn, dwCount, pRgnData );
                RECT *R = reinterpret_cast<RECT*>(pRgnData + sizeof( RGNDATAHEADER ));
                for(unsigned int x = 0; x < pRgnData->rdh.nCount; x++, R++)
                  {
                      // fill the rect ( R ) for visual confirmation
                  }
            }
          if( Buffer ) delete Buffer;
      }
}
Re: WM_NCPAINT - no region to be had
#16741
Author: Remy Lebeau (TeamB)
Date: Sat, 26 Apr 2003 19:19
13 lines
1334 bytes
"JD" <nospam@nospam.com> wrote in message
news:3eaa9f2d$2@newsgroups.borland.com...

> I tried to GetRegionData but there's never anything
> there which I know is not the case so my code must
> be in error.

Please elaborate.  What do you mean "nothing is there" exactly?  Please
indicate where in your code it is actually failing.


Gambit
Re: WM_NCPAINT - no region to be had
#16742
Author: JD
Date: Sat, 26 Apr 2003 21:36
39 lines
2325 bytes
"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
> Please elaborate. [...]

      DWORD dwCount = GetRegionData( hrgn, 0, NULL );

dwCount is always zero so the if( dwCount > 0 ) block is never
executed. BTW, I tried calling OldWindowProc before and after
checking for WM_NCPAINT and I tried not calling it at (in
conjunction with setting Message.Result = 0). All attempts had
the same result with dwCount being zero.

~ JD

void __fastcall TForm1::NewWindowProc( TMessage& Message )
{
    OldWindowProc( Message );
    if( Message.Msg == WM_NCPAINT )
      {
          char *Buffer = NULL;
          RGNDATA *pRgnData;
          HRGN hrgn = (HRGN) Message.WParam;
          DWORD dwCount = GetRegionData( hrgn, 0, NULL );

          if( dwCount > 0 )
            {
                Label1->Caption = "Made it to here";
                Buffer = new char[ dwCount ];
                pRgnData = reinterpret_cast<RGNDATA*>( Buffer );
                GetRegionData( hrgn, dwCount, pRgnData );
                RECT *R = reinterpret_cast<RECT*>(pRgnData + sizeof( RGNDATAHEADER ));
                for(unsigned int x = 0; x < pRgnData->rdh.nCount; x++, R++)
                  {
                      // fill the rect ( R ) for visual confirmation
                  }
            }
          if( Buffer ) delete Buffer;
      }
}
Re: WM_NCPAINT - no region to be had
#16743
Author: Remy Lebeau (TeamB)
Date: Sat, 26 Apr 2003 22:00
16 lines
1506 bytes
"JD" <nospam@nospam.com> wrote in message
news:3eaafbd2$1@newsgroups.borland.com...

>       DWORD dwCount = GetRegionData( hrgn, 0, NULL );
>
> dwCount is always zero

According to the Win32 API documentation:

    "If the function fails, the return value is zero."

Have you tried using GetLastError() to see if it returns why it failed?


Gambit
Re: WM_NCPAINT - no region to be had
#16745
Author: Chris
Date: Sat, 26 Apr 2003 22:50
30 lines
2274 bytes
"JD" <nospam@nospam.com> wrote in message
news:3eaafbd2$1@newsgroups.borland.com...
>
> "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
> > Please elaborate. [...]
>
>       DWORD dwCount = GetRegionData( hrgn, 0, NULL );
>
> dwCount is always zero so the if( dwCount > 0 ) block is never
<snip>

I just tried your code and it worked for me (well after removing
OldWindowProc( Message )).

The function is called loads of times and

HRGN hrgn = (HRGN) Message.WParam; returns :00000001

when this happens DWORD dwCount = GetRegionData( hrgn, 0, NULL ); returns 0
and the main block doesn't run.

When I move the form around and actually invalidate the form's frame (i.e.
take it off the screen edge) everything works great and the label changes to
"Made it to here".

I know this is not terribly informative, but your code does work (on XP at
any rate), although why it gets the message when the form's frame is not
invalidated is beyond me.

Chris
Re: WM_NCPAINT - no region to be had
#16744
Author: JD
Date: Sat, 26 Apr 2003 22:54
22 lines
1775 bytes
"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>
>"JD" <nospam@nospam.com> wrote in message
>news:3eaafbd2$1@newsgroups.borland.com...
>
>>       DWORD dwCount = GetRegionData( hrgn, 0, NULL );
>>
>> dwCount is always zero
>
>According to the Win32 API documentation:
>
>    "If the function fails, the return value is zero."
>
>Have you tried using GetLastError() to see if it returns why it failed?

GetLastError returns an error code of 87 (decimal) which
translates to: ERROR_INVALID_PARAMETER (The parameter is
incorrect). Zero and NULL are valid according to the docs so
that leaves the HRGN which is supplied by the OS.

~ JD
Re: WM_NCPAINT - no region to be had
#16746
Author: JD
Date: Sat, 26 Apr 2003 23:20
18 lines
1601 bytes
"Chris" <chris@chrischfmouseyREMOVE.karoo.co.uk> wrote:
> I just tried your code and it worked for me (well after
> removing OldWindowProc( Message )).

How did you remove the OldWindowProc? When I tried that the
form never got displayed?

>The function is called loads of times and
>
>HRGN hrgn = (HRGN) Message.WParam; returns :00000001
>
>when this happens DWORD dwCount = GetRegionData( hrgn, 0, NULL ); returns 0
>and the main block doesn't run.

Could you please be a bit more clear about what is what when?

~ JD
Re: WM_NCPAINT - no region to be had
#16747
Author: Chris
Date: Sun, 27 Apr 2003 00:08
70 lines
3317 bytes
"JD" <nospam@nospam.com> wrote in message
news:3eab1440$1@newsgroups.borland.com...
>
> How did you remove the OldWindowProc? When I tried that the
> form never got displayed?
>

I just commented it out, I assumed that OldWindowProc is your code and of
course I did not write such a function on my test.


> >The function is called loads of times and
> >
> >HRGN hrgn = (HRGN) Message.WParam; returns :00000001
> >
> >when this happens DWORD dwCount = GetRegionData( hrgn, 0, NULL ); returns
0
> >and the main block doesn't run.
>
> Could you please be a bit more clear about what is what when?
>

I'll try;

I started a new app and dropped a label on it with it's caption set to
"label1".  I created a message map in the header and then dropped your code
snippet into the unit file.

ala;

(I've loaded a custom control since my last message and BCB4 is not working
now (Argh) so this is from your post and not the IDE but it is an accurate
reflection of what I did)

void __fastcall TForm1::NewWindowProc( TMessage& Message )
{
    //OldWindowProc( Message );    //<--- OldWindowProc is your code I
assume???????
    if( Message.Msg == WM_NCPAINT )
      {
          char *Buffer = NULL;       // <--- set breakpoint 1 here
          RGNDATA *pRgnData;
          HRGN hrgn = (HRGN) Message.WParam;
          DWORD dwCount = GetRegionData( hrgn, 0, NULL );

          if( dwCount > 0 )
            {
                Label1->Caption = "Made it to here";   //  <--- set
breakpoint 2 here
             // <snip>
            }
          if( Buffer ) delete Buffer;
      }
}

Often the app would break on BP1 even though nothing has covered the form's
border, when this is the case GetRegionData fails because hrgn is always at
00000001.

If I actually invalidated the form's border by moving it off screen, BP2
fires and now hrgn is at something like 0d0201030 (made this up but it is a
valid region handle).

So it works but I do not know why it receives so many WM_NCPAINT messages
that seem to be erroneous.

Hope this helps.

Chris
Re: WM_NCPAINT - no region to be had
#16749
Author: JD
Date: Sun, 27 Apr 2003 01:58
26 lines
1998 bytes
"Chris" <chris@chrischfmouseyREMOVE.karoo.co.uk> wrote:
>
>"JD" <nospam@nospam.com> wrote in message
>news:3eab1440$1@newsgroups.borland.com...
>>
>> How did you remove the OldWindowProc? When I tried that the
>> form never got displayed?
>>
>
>I just commented it out, I assumed that OldWindowProc is your code and of
>course I did not write such a function on my test.

It never occured to me that someone looking at my code wouldn't
know that I had replaced the forms WindowProc. What's it
called? Overloaded? OldWindowProc is the default WindowProc.

> [...] I created a message map in the header and then dropped
> your code snippet into the unit file.

All of the code samples that I googled upon replaced the
default WindowProc as I did. What's the difference with using a
message map? Shouldn't I expect the same results? May I see the
map that you used?

~ JD
Re: WM_NCPAINT - no region to be had
#16748
Author: Remy Lebeau (TeamB)
Date: Sun, 27 Apr 2003 01:59
26 lines
2210 bytes
"Chris" <chris@chrischfmouseyREMOVE.karoo.co.uk> wrote in message
news:3eab1f63@newsgroups.borland.com...

> I just commented it out, I assumed that OldWindowProc is
> your code and of course I did not write such a function
> on my test.

My take on it is that JD used subclassing, and OldWindowProc is a pointer to
the previous window procedure that was repleasced with a custom one.


> I started a new app and dropped a label on it with it's caption set to
> "label1".  I created a message map in the header and then dropped your
code
> snippet into the unit file.

You are never calling the base class handling, however.  By using a
MESSAGE_MAP (which, you could have accomplished the same thing by just
overriding WndProc() itself), you're overriding the default handling of the
message.  If you do not pass the message on to the base class (TForm, in
this case), the VCL, as well as windows itself, won't get a chance to
process the message as well.


Gambit
Re: WM_NCPAINT - no region to be had
#16750
Author: JD
Date: Sun, 27 Apr 2003 02:54
19 lines
1903 bytes
"Chris" <chris@chrischfmouseyREMOVE.karoo.co.uk> wrote:
> [...] Often the app would break on BP1 even though nothing
> has covered the form's border, when this is the case
> GetRegionData fails because hrgn is always at 00000001.

Something has to happen to paint the nonclient area when it's
in full view. In this case a region would be overkill since a
RECT will do. MS wouldn't have undocumented behavior in the OS,
would they?

> If I actually invalidated the form's border by moving it off
> screen, BP2 fires and now hrgn is at something like 0d0201030

Well, well, well. Guess what? Works for me too :-O I had this
thing working yesterday and didn't know it. Now I need to
figure out the caption painting for when the form looses focus.

~ JD
Re: WM_NCPAINT - no region to be had
#16751
Author: Ed Mulroy [TeamB]
Date: Sun, 27 Apr 2003 03:09
9 lines
1442 bytes
> ... MS wouldn't have undocumented behavior
> in the OS, would they? ...

HaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHa!!!!!!!

.  Ed

> JD wrote in message
> news:3eab467b$1@newsgroups.borland.com...
Re: WM_NCPAINT - no region to be had
#16752
Author: Remy Lebeau (TeamB)
Date: Sun, 27 Apr 2003 03:14
16 lines
1578 bytes
"JD" <nospam@nospam.com> wrote in message
news:3eab467b$1@newsgroups.borland.com...

> MS wouldn't have undocumented behavior in
> the OS, would they?

You're joking, right?  The OS is full of undocumented goodies.

> Now I need to figure out the caption painting
> for when the form looses focus.

Have a look at the WM_NCACTIVATE message.


Gambit
Re: WM_NCPAINT - no region to be had
#16765
Author: JD
Date: Mon, 28 Apr 2003 14:04
15 lines
1481 bytes
"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>
>"JD" <nospam@nospam.com> wrote in message
>news:3eab467b$1@newsgroups.borland.com...
>
>> MS wouldn't have undocumented behavior in
>> the OS, would they?
>
>You're joking, right?  The OS is full of undocumented goodies.
>

Nah ;-)

~ JD
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads