Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 forms-2 cursors ?

Status
Not open for further replies.

pierrotsc

Programmer
Nov 25, 2007
358
US
I use imageen library to handle images. I have 2 forms with the same picture inside. I guess that would work too with a Tbitmap.
I want to know if it is possible to display a cursor in each form. That means, i want cursor1 in form1 to be the same as cursor2 in form2. I would only move cursor1 in form1 but i want cursor2 in form2 to mimic cursor1. cursor2 is just for reference only.
Thanks.
Pierrotsc
 
Hi,
I would do this way:

- create a small monochromatic bitmap with an arrow to simulate a cursor named like 'cursor.bmp'

- put two panels in the form. Each one containing a TImage
called like Image1 and Image2 and with the Align property with alClient.

- inside the second panel you will put the TImage that will mimic a cursor flying over the Image2. Name it as CursorImage and load the cursor.bmp file on it.

- program the OnMouseMove of the first TImage to capture the mouse coordinates and adjust the coordinates of the CursorImage:

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
ImageCursor.Left:=X;
ImageCursor.Top:=Y;
end;

Good luck,

Ricardo Bianchin
 
This may be a little more than you need, but here's a function I have for taking a screenshot, including getting the cursor position and drawing it on the image:

Code:
function ScreenShot(DrawCursor: Boolean; Quality: TPixelFormat; Compression: Integer): TBitmap;
var
  DC: HDC;
  R: TRect;
  CI: TCursorInfo;
  Icon: TIcon;
  II: TIconInfo;
begin
  //Create bitmap result
  Result:= TBitmap.Create;
  //Get desktop handle
  DC:= GetDC(GetDesktopWindow);
  try
    //Set result to new screenshot image
    Result.Width:= GetDeviceCaps (DC, HORZRES);
    Result.Height:= GetDeviceCaps (DC, VERTRES);
    Result.PixelFormat:= Quality;
    //Actual acquiring of screenshot image
    BitBlt(Result.Canvas.Handle,
      0,
      0,
      Result.Width,
      Result.Height,
      DC,
      0,
      0,
      SRCCOPY);
  finally
    ReleaseDC(GetDesktopWindow, DC);
  end;
  //Draw cursor
  R:= Result.Canvas.ClipRect;
  Icon:= TIcon.Create;
  try
    CI.cbSize:= SizeOf(CI);
    if GetCursorInfo(CI) then
    if CI.Flags = CURSOR_SHOWING then
    begin
      Icon.Handle:= CopyIcon(CI.hCursor);
      if GetIconInfo(Icon.Handle, II) then
      begin
        //Draw cursor image on screenshot image
        Result.Canvas.Draw(
          ci.ptScreenPos.x - Integer(II.xHotspot) - r.Left,
          ci.ptScreenPos.y - Integer(II.yHotspot) - r.Top,
          Icon);
      end;
    end;
  finally
    Icon.Free;
  end;
end;

JD Solutions
 
Also, don't worry about the 'Compression: Integer' parameter, I'm not using it anymore.

JD Solutions
 
Ok, I am trying to understand your code. Does that takes only a screenshot on the cursor from image1 and duplicate it onto image2? Image1 and image2 are the same image but one is color and the other has a different tones to it. Would i put this screenshot function into my onmousemouve event from image1?
Thanks for the help. I am kind of confused.
Pierrotsc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top