?
Solved

Remove Rectangles after painting them on "DeskTopWindow" or screen

Posted on 2009-05-04
4
Medium Priority
?
202 Views
Last Modified: 2012-05-06
I am drawing a rectangle around buttons in my application by using this funny method below.
The problem is that after I draw these rectangles I cannot clear them (unless I 'drag' my form off the screen and back on again).

I have tried calling canvas.repaint / canvas.refresh but it doesn't work.
procedure BorderMyControl(DaControl : TControl);
var
  C : TCanvas;
  DeskTopWindowDC : HDC;
begin
  C := TCanvas.Create;
  with C do
  try
    DeskTopWindowDC := GetWindowDC(GetDeskTopWindow);
      try
        Handle := DeskTopWindowDC;
        Brush.Style := bsClear;
        Pen.Width := 3;
        Rectangle(Rect(DaControl.Left - 2, DaControl.Top - 2, DaControl.Left + DaControl.Width + 2, DaControl.Top + DaControl.Height + 2));
      finally
        ReleaseDC(GetDesktopWindow, DeskTopWindowDC);
    end;
  finally
    Free;
  end;
end;

Open in new window

0
Comment
Question by:rfwoolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 100 total points
ID: 24302596
it would be solved with a bevel too
0
 
LVL 12

Accepted Solution

by:
Hypo earned 1900 total points
ID: 24302830
Isn't your problem that you paint it on the Desktop DC, and not on your controls Parent DC? I belive that's what causes your problem. When I ran your exapmle, the border was not painted at the correct locations, but anyway, I got the idea of what you were talking about. After I changed the DC to be the parent of the Control instead, then I could call Repaint on the parent, and the border was removed.

    DeskTopWindowDC := GetWindowDC(DaControl.Parent.Handle);

regards
Hypo
0
 
LVL 13

Author Comment

by:rfwoolf
ID: 24307171
I'm satisfied at the answer but I'm sure I did try and refresh the desktop and failed. One of the problems I'm sure I'm running into is that the form's canvas includes the header, so if I draw a rectangle starting at 0,0 on the form it will appear on the title bar. Anyway, let's see if we can address this in a separate question.
0
 
LVL 13

Author Comment

by:rfwoolf
ID: 24307189
Sorry I wasn't clear above, what I'm trying to say Hypo is this:
Your solution is a great workaround for my particular problem, but,
what if I did want to draw on the desktop, and what if I did have trouble removing the squares on the desktop window handle? Your answer doesn't address this.
Anyways, I would prefer to draw on the form instead of the desktop so let's just move on :p

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question