首页  编辑  

焦点移到其他程序中的窗体上

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

using System . Runtime . InteropServices;

[ DllImport ( "user32.dll" )]

public static extern bool SetWindowPos( IntPtr hWnd,

    IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

public IntPtr HWND_TOP = IntPtr . Zero;

public uint SWP_NOMOVE = 2 ;

public uint SWP_NOSIZE = 1 ;

public uint SWP_NOACTIVATE = 0x10 ;

public uint SWP_SHOWWINDOW = 0x40 ;

private void button1_Click( object sender , EventArgs e)

{

    Process [] vProcesses = Process . GetProcessesByName( "notepad" );

    if (vProcesses . Length <= 0 ) return ;

   SetWindowPos(vProcesses[ 0 ] . MainWindowHandle, HWND_TOP, 0 , 0 , 0 , 0 ,

       SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

}