Solved

Remove Rectangles after painting them on "DeskTopWindow" or screen

Posted on 2009-05-04
4
201 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 37

Assisted Solution

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

Accepted Solution

by:
Hypo earned 475 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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