title: How to eliminate screen flicker when getting handle of screen object to DrawFocusRect
body: <p>I am attempting to draw a focused rectangle around a selected screen object in my Apprehend Screen Capture Component that was developed many years ago.  I can DrawFocusRect by getting the handle to the object under the cursor with Handles := WindowFromPoint( P ); but that requres me to hide then show self for it to work otherwise the handle to self is returned.</p>
  
  <p>Unfortunately when I hide and show the form it causes flicker when the form is hidden and shown.</p>
  
  <p>I can get the bitmap of the selected object with no problem, just painting the selected object is driving me nuts.</p>
  
  <p>Does anyone have any suggestions to draw a FocusedRect around the selected object so there is no flickering?  Is there any API to get a handle to the screen if a form lies on top of it?</p>
  
  <p>I tried using Handles := WindowFromDC(ScreenDC) so I do not have to hide and show the form, but WindowFromDC still returns the form rather than the screen.</p>
  
  <p>The TCaptureObjectForm is transparent and lies over the screen.  I need the TCaptureObjectForm in the component.</p>
  
  <p>// FormMouseMove event - added 08/2/2011</p>
  
  <pre><code>procedure TCaptureObjectForm.FormMouseMove( Sender: TObject; Shift: TShiftState; X, Y: Integer );
  const
    crHand = -18;
  var
    P: TPoint;
    Handles: HWND;
    Rect: TRect;
    ScreenDC: HDC;
  begin
    // hide the TCaptureObjectForm form so the screen is found by WindowFromPoint
    Self.Hide;
    // get the object on the screen
    GetCursorPos( P );
    Handles := WindowFromPoint( P );
    // tried this but it returns self.handle rather than the screen handle
    //ScreenDC := GetDC( 0 );
    //Handles := WindowFromDC(ScreenDC);
    //ReleaseDC( 0, ScreenDC );
    // restore the TCaptureObjectForm
    Self.Show;
    // get object rect
    GetWindowRect( Handles, Rect );
    // draw a rect to show it is focused
    Self.Canvas.DrawFocusRect( Rect );
  end;
  </code></pre>