首页  编辑  

类似Spy++高亮控件

Tags: /C#/界面处理/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "user32.dll" )]

static extern bool IsWindow( IntPtr hWnd);

[ DllImport ( "user32.dll" )]

static extern bool GetWindowRect( IntPtr hWnd, out Rectangle lpRect);

[ DllImport ( "user32.dll" )]

static extern IntPtr GetWindowDC( IntPtr hWnd);

[ DllImport ( "gdi32.dll" )]

static extern bool PatBlt( IntPtr hdc, int nXLeft, int nYLeft, int nWidth,

  int nHeight, uint dwRop);

[ DllImport ( "user32.dll" )]

static extern int ReleaseDC( IntPtr hWnd, IntPtr hDC);

static uint DSTINVERT = 0x00550009 ;

bool TrackerWindow( IntPtr AHandle)

{

    if   ( ! IsWindow(AHandle)) return false ;

    Rectangle vRect;

    if ( ! GetWindowRect(AHandle, out vRect)) return false ;

   vRect = new Rectangle ( 0 , 0 , vRect . Width - vRect . Left,

       vRect . Height - vRect . Top);

    IntPtr vDC = GetWindowDC(AHandle);

   PatBlt(vDC, vRect . Left, vRect . Top, vRect . Width,

       vRect . Height, DSTINVERT);

   PatBlt(vDC, vRect . Left + 4 , vRect . Top + 4 , vRect . Width - 4 * 2 ,

       vRect . Height - 4 * 2 , DSTINVERT);

   ReleaseDC(AHandle, vDC);

    return true ;

}

private void button1_Click( object sender , EventArgs e)

{

   TrackerWindow(textBox1 . Handle);

}