Solved

X Marks The Spot

Posted on 2000-03-15
2
151 Views
Last Modified: 2010-04-04
What I need, is to be able to draw an X (similar to the one used in the expertsexchange logo) at a point defined by x and y which is given by the user of my application.

i.e. If the user has entered 100 for x and 100 for y then the mark will be drawn at 100, 100.

Also, it must be able to be drawn on any area of the desktop (not only on my form). When the user changes one of the values (x or y) the mark must move, leaving the underlying desktop intact.

I thought that this would be easier if I could create a "virtual cursor" (i.e. to have 2 cursors on the screen, my standard cursor plus one to mark the spot) with the crCross cursor. If this can be done I'd prefer it.

Please include code.

Chris.
0
Comment
Question by:she3i3i
2 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 50 total points
ID: 2619985
Try this lot:

procedure TForm1.Button1Click(Sender: TObject);
var
  dc : hdc;
  X, Y : LONGINT;
begin
  dc := GetDc(0);
  bmpBuffer := TBitmap.Create;
  bmpBuffer.Width := Screen.Width;
  bmpBuffer.Height := Screen.Height;

  BitBlt(bmpBuffer.Canvas.Handle, 0, 0, Screen.Width - 1, Screen.Height - 1, dc, 0, 0, SRCCOPY);

  X := 100;
  Y := 100;

  MoveToEx(Dc, X, Y, nil);
  LineTo(Dc, X + 100, Y + 100);
  MoveToEx(Dc, X + 100, Y, nil);
  LineTo(Dc, X, Y + 100);
  ReleaseDc(0, Dc);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  dc : hdc;
begin
  dc := GetDc(0);

  BitBlt(dc, 0, 0, Screen.Width - 1, Screen.Height - 1, bmpBuffer.Canvas.Handle, 0, 0, SRCCOPY);
  ReleaseDc(0, Dc);
end;

Button1 will snap the desktop and draw your X (crudely), while Button2 will restore it. You can make it a bit more intelligent and just snap the section of the desktop that you're working with

The Neil
0
 
LVL 1

Author Comment

by:she3i3i
ID: 2622551
Very good.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

775 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