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);

const uint BM_CLICK = 0xF5;

IntPtr msgHandle 
= FindWindow(null"Form1");
if (msgHandle != IntPtr.Zero)
{
    
//找到Button
    IntPtr btnHandle = FindWindowEx(msgHandle, 0"Button""确定");
    
if (btnHandle != IntPtr.Zero)
    {
        SendMessage(btnHandle, BM_CLICK, 
00);
    }
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案