Solved

Remove Rectangles after painting them on "DeskTopWindow" or screen

Posted on 2009-05-04
4
197 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 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