Solved

Remove Rectangles after painting them on "DeskTopWindow" or screen

Posted on 2009-05-04
4
195 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 36

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PDF files into SQL 2008 Varbinary(Max) 3 78
Delphi OLE Error 8 84
proper way to parse url in delphi 2 135
LAN or WAN ? 11 63
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now