C# WinForm 獲取句柄與置頂窗體



[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow(); //獲得本窗體的句柄
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);//設置此窗體為活動窗體
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
//定義變量,句柄類型
public IntPtr Handle1;

Handle1 = new IntPtr(0);
Handle1 = FindWindow(null, Name);
if (Handle1 != IntPtr.Zero)
{
SetForegroundWindow(Handle1);//置頂
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM