如何使用c#引入窗口前景?
我试图带一个窗口前景.我正在使用此代码.但它不起作用.有人可以帮忙吗?
ShowWindowAsync(wnd.hWnd,SW_SHOW); SetForegroundWindow(wnd.hWnd); // Code from Karl E. Peterson,www.mvps.org/vb/sample.htm // Converted to Delphi by Ray Lischner // Published in The Delphi Magazine 55,page 16 // Converted to C# by Kevin Gale IntPtr foregroundWindow = GetForegroundWindow(); IntPtr Dummy = IntPtr.Zero; uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow,Dummy); uint thisThreadId = GetWindowThreadProcessId(wnd.hWnd,Dummy); if (AttachThreadInput(thisThreadId,foregroundThreadId,true)) { BringWindowToTop(wnd.hWnd); // IE 5.5 related hack SetForegroundWindow(wnd.hWnd); AttachThreadInput(thisThreadId,false); } if (GetForegroundWindow() != wnd.hWnd) { // Code by Daniel P. Stasinski // Converted to C# by Kevin Gale IntPtr Timeout = IntPtr.Zero; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,Timeout,0); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,Dummy,SPIF_SENDCHANGE); BringWindowToTop(wnd.hWnd); // IE 5.5 related hack SetForegroundWindow(wnd.hWnd); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,SPIF_SENDCHANGE); } 代码解释
内容摘自here 解决方法
我以前用过这个方法:
[DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); Process[] processes = Process.GetProcessesByName("processname"); SetForegroundWindow(processes[0].MainWindowHandle); 更多信息:http://pinvoke.net/default.aspx/user32.SetForegroundWindow (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |