title: Multi-monitor screenshot - positioning mouse cursor
body: <p>I have a procedure which takes a screenshot of a monitor and optionally includes the mouse cursor in the snapshot. The original function was only for one monitor. When drawing the mouse cursor, it currently shows properly only on the Main Monitor. But, I can't figure out how to position it on any other monitor. See the comments towards the end of this procedure.</p>
  
  <pre><code>procedure ScreenShot(var Bitmap: TBitmap; const MonitorNum: Integer;
    const DrawCursor: Boolean; const Quality: TPixelFormat);
  var
    DC: HDC;
    C: TCanvas;
    R: TRect;
    CursorInfo: TCursorInfo;
    Icon: TIcon;
    IconInfo: TIconInfo;
    M: TMonitor;
    CP: TPoint;
  begin
    M:= Screen.Monitors[MonitorNum];
    DC:= GetDC(GetDesktopWindow);
    try
      C:= TCanvas.Create;
      try
        C.Handle:= DC;
        R:= M.BoundsRect;
        Bitmap.Width:= R.Width;
        Bitmap.Height:= R.Height;
        Bitmap.PixelFormat:= Quality;
        Bitmap.Canvas.CopyRect(Rect(0,0,R.Width,R.Height), C, R);
      finally
        C.Free;
      end;
    finally
      ReleaseDC(GetDesktopWindow, DC);
    end;
    if DrawCursor then begin
      R:= Bitmap.Canvas.ClipRect;
      Icon:= TIcon.Create;
      try
        CursorInfo.cbSize:= SizeOf(CursorInfo);
        if GetCursorInfo(CursorInfo) then
        if CursorInfo.Flags = CURSOR_SHOWING then
        begin
          Icon.Handle:= CopyIcon(CursorInfo.hCursor);
          if GetIconInfo(Icon.Handle, IconInfo) then
          begin
            CP:= CursorInfo.ptScreenPos;
  
            //Transition mouse position...?
            CP.X:= CP.X + M.Left;
            CP.Y:= CP.Y + M.Top;  //No difference?
  
            Bitmap.Canvas.Draw(
              CP.X - Integer(IconInfo.xHotspot) - R.Left,
              CP.Y - Integer(IconInfo.yHotspot) - R.Top,
              Icon);
          end;
        end;
      finally
        Icon.Free;
      end;
    end;
  end;
  </code></pre>
  
  <p>How do I transition the mouse position properly depending on which monitor I'm using?</p>