zoukankan      html  css  js  c++  java
  • 在C#中向windows窗体发送消息示例

    // define
    [DllImport("User32.dll")]
            public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

            [DllImport("User32.dll")]
            static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

            const int WM_LBUTTONDOWN = 0x201;
            const int WM_LBUTTONUP = 0x0202;

      // sample, u should use spy++ to find windows class name and control class name

            IntPtr hwndWin = FindWindow("TfrmMain", "window title");
                if (hwndWin.Equals(IntPtr.Zero) == false)
                {
                    IntPtr hwndBtn = FindWindowEx(hwndWin, IntPtr.Zero, "TButton", "control text");
                    if (hwndBtn.Equals(IntPtr.Zero) == false)
                    {
                        SendMessage(hwndBtn, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
                        SendMessage(hwndBtn, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
                    }
                }

  • 相关阅读:
    观察者模式
    饿汉单例模式 and 懒汉单例模式
    解决hash冲突之分离链接法
    bat处理文件
    使用json-org包实现POJO和json的转换
    并发修改异常(ConcurrentModificationException)
    封装特效记录--持续更新
    vue loading组件
    vue授权页面登陆之后返回之前的页面
    vue 路由权限
  • 原文地址:https://www.cnblogs.com/margiex/p/938746.html
Copyright © 2011-2022 走看看