zoukankan      html  css  js  c++  java
  • C#查找某一窗口并按钮

    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);
        }
    }
  • 相关阅读:
    UVA 439 Knight Moves
    UVA 673 Parentheses Balance
    UVa 536 Tree Recovery
    UVA 712 S-Trees
    UVA 12657 Boxes in a Line
    UVA 679 Dropping Balls
    UVA 1603 Square Destroyer
    UVA 1343 The Rotation Game
    UVA 1374 Power Calculus
    UVA 12558 Egyptian Fractions (HARD version)
  • 原文地址:https://www.cnblogs.com/mobydick/p/1753797.html
Copyright © 2011-2022 走看看