C# FindWindow SendMessage


 導入命名空間

using System.Runtime.InteropServices;

添加代碼

[DllImport ( "user32.dll", EntryPoint = "FindWindow", SetLastError = true )]
private static extern IntPtr FindWindow( string lpClassName, string lpWindowName );

[DllImport ( "user32.dll", EntryPoint = "FindWindowEx", SetLastError = true )]
private static extern IntPtr FindWindowEx( IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow );

[DllImport ( "user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto )]
private static extern int SendMessage( IntPtr hwnd, uint wMsg, int wParam, int lParam );

[DllImport ( "user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true )]
private static extern void SetForegroundWindow( IntPtr hwnd );
IntPtr hwndCalc = FindWindow(null, "窗體標題"); //查找計算器的句柄
if (hwndCalc != IntPtr.Zero)
{
IntPtr hwndThree = FindWindowEx(hwndCalc, 0, null, "確定"); //獲取按鈕的句柄
SendMessage(hwndThree, 0xF5, 0, 0); //鼠標點擊的消息,對於各種消息的數值,大家還是得去API手冊
}




免責聲明!

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



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