RectVisible - Windows API

Please discuss general Delphi programming topics here.

RectVisible - Windows API

Postby Kambiz » April 5th, 2006, 11:16 pm

The RectVisible function determines whether any part of the specified rectangle lies within the clipping region of a device context.

Code: Select all
function RectVisible(DC: HDC; const Rect: TRect): BOOL; stdcall;

The PtVisible function determines whether the specified point is within the clipping region of a device context.

Code: Select all
function PtVisible(DC: HDC; X, Y: Integer): BOOL; stdcall;


Drawing on a canvas is very time-consuming, especially when there are many things to draw. Using two mentioned APIs, we can determine which parts of a canvas is updated, and redraw only those parts to save lot of cpu time. Sounds great! Yeah?

However, there is a fact that says: "There's always something to suck". Let I tell you when these two APIs suck. To have a wrong return value, the following conditions should be satisfied:

  1. The DC parameter shoud be a metafile device context (e.g. TMetafileCanvas.Handle).
  2. The dimension of metafile device context (DC) should be bigger than dimension of its referenced device context (RefDC parameter of TMetafileCanvas constructor).
  3. The Rect parameter should be outside of the referenced device context's bounding rectangle (RefDC). Obviously, it should be inside bounding rectangle of the metafile device context (DC).
To see it by yourself, compile and run the attached program. The program displays a green or red rectangle on botton right corner of the form. Here are interpretation of the colors:

  • GREEN RECTANGLE
    The RectVisible API tells the rectangle is visible, which is true.
  • RED RECTANGLE
    The RectVisible API tells the rectangle is not visible, which is wrong because you are seeing it with your own eyes.
There is something more. During drawing a metafile, Windows calls the RectVisible function internally. Because of the bug in the RectVisible function, if we draw a metafile on a metafile canvas at a position that satifies the above conditions, the metafile will not be drawn. As a workaround, you can draw the metafile on a bitmap, and then draw the bitmap on the metafile canvas.

Maybe there's no bug in these APIs, and I just did something wrong. :?
Attachments
RectVisibleBug.zip
RectVisible Bug - Demonstration
(1.75 KiB) Downloaded 96 times
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby kokkoras » April 5th, 2006, 11:37 pm

Have you tried to post this question in the Delphi newsgroups of Borland? The audience there is bigger and the B-Team members are always around for the realy hard questions.
Fotis
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece

Postby Kambiz » April 6th, 2006, 10:55 am

I tested the case with pure API calls to be sure it's a Windows bug. I think it's better to ask for a fix on microsoft newsgroups.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Kambiz » April 6th, 2006, 12:36 pm

I found a post on google groups that describes this problem with metafiles. However, since two years ago nobody answered it. :(

http://groups.google.com/group/comp.os.ms-windows.programmer.graphics/browse_thread/thread/5376b6e431e6d9bd/b2e297499dca9d56
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby norbert » May 15th, 2006, 7:08 pm

Hihi,

Currently, I have once again the same problem here. during the last ten years I tried several time to get a solution even directly from Microsoft. They told me that this should be fix in the next API revision........

Perhaps with vista....???

For a 'cutting plotter (A0 size)' preview, I have been searching at least 10 years for a code helping me to overlay two meta EMF files transparently. I did not yet manage it and asked for a hint in this forum half an hour before. So You are not allone. (programmer since 1969!)

Whenever I asked with or without an explanation of the problem, I never got any answer. So I think this might be a sin as a gift for generations, and it follows us to everywhere.
norbert
Active Member
Active Member
 
Posts: 17
Joined: May 13th, 2006, 8:49 am
Location: Germany


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron