• 使用C# 向记事本窗口发送消息


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport( "User32.dll ")]
            public static extern IntPtr FindWindow(string ClassName, string CaptionName);
            [DllImport( "User32.dll ")]
            public static extern int SendMessage(IntPtr hwad, int wMsg, int lParam, int wParam);

            [DllImport("user32.dll")]
            public static extern IntPtr SetFocus(IntPtr hwnd2);

            [DllImport("user32.dll")]
            public static extern IntPtr FindWindowEx(IntPtr parenthW,IntPtr child,string

    s1,string s2);

            public const int WM_SETTEXT = 0x000C; 
            public const int WM_CHAR = 0x0102;

            static void Main(string[] args)
            {

                string className = "Notepad";


                string captionName = "无标题 - 记事本";

                IntPtr hwnd=FindWindow(className,captionName);//找主窗口.


                IntPtr hwnd2 = FindWindowEx(hwnd,IntPtr.Zero, "Edit", "");  //  找子窗体
                //SendMessage(hwnd22,256,97,0);
                SendMessage(hwnd2, WM_CHAR, (int)'h', 0);
                SendMessage(hwnd2, WM_CHAR, (int)'e', 0);
                SendMessage(hwnd2, WM_CHAR, (int)'l', 0);
                SendMessage(hwnd2, WM_CHAR, (int)'l', 0);
                SendMessage(hwnd2, WM_CHAR, (int)'o', 0); 
                Console.ReadLine();
            }
        }

  • 相关阅读:
    bower使用记录
    前端生成二维码
    删除顽固node_modules
    vue初体验:实现一个增删查改成绩单
    H5常用代码:适配方案5
    H5常用代码:适配方案4
    H5常用代码:适配方案3
    ARFA 教堂的第四次洗礼&斜率优化重学
    CSP考前总结&周二晚+周三晚模拟考总结&洛谷11月月赛 III Div.1总结
    T44253 绝美的挣扎 题解
  • 原文地址:https://www.cnblogs.com/voidobject/p/3975509.html
Copyright © 2020-2023  润新知