zoukankan      html  css  js  c++  java
  • 【转】调用 开始 运行 直接执行命令

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Diagnostics;

    namespace fasta2011
    {
    public class Cmd
    {
    private const byte VK_LWIN = (byte)Keys.LWin;
    private const byte VK_R = (byte)Keys.R;
    private const int KEYEVENTF_KEYUP = 0x02;
    private const int WM_SETTEXT = 0x000C;
    private const int WM_CLICK = 0x00F5;

    [DllImport("user32")]
    public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

    [DllImport("user32.dll")]
    static extern int FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int parentHandle, int childAfter, string className, string windowTitle);

    [DllImport("user32.dll")]
    static extern IntPtr SendMessage(int hWnd, uint Msg, int wParam, string lParam);


    public static void Run(string CmdText)
    {
    keybd_event(VK_LWIN, 0, 0, 0);
    keybd_event(VK_R, 0, 0, 0);
    keybd_event(VK_R, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);

    System.Threading.Thread.Sleep(50);

    int h1 = 0, h2 = 0, h3;
    h1 = FindWindow(null, "运行"); //这要修改为窗口标题
    if (h1 != 0)
    {
    h2 = FindWindowEx(h1, 0, "ComboBox", null);
    if (h2 != 0)
    {
    SendMessage(h2, WM_SETTEXT, 0, CmdText);
    System.Threading.Thread.Sleep(10);

    h3 = FindWindowEx(h1, 0, null, "确定"); //这要修改为按钮文本
    if (h3 != 0)
    {
    SendMessage(h3, WM_CLICK, 0, null);
    }
    else
    {
    MessageBox.Show("h3==0");
    }
    }
    else
    {
    MessageBox.Show("h2==0");
    }
    }
    else
    {
    MessageBox.Show("h1==0");
    }
    }
    }
    }
  • 相关阅读:
    Unity3D读取assetbundle
    Unity3D 发布成exe之后黑屏
    Unity3D优化总结
    Unity3D中中 rect[2] == rt->GetGLWidth() && rect[3] == rt->GetGLHeight()错误的原因及解决方法
    C# mysql 插入数据,中文乱码的解决方法
    WPF Canvas做自动缩放时获取控件的实际高度
    面向对象
    常用模块介绍
    python异常处理,多线程,多进程
    python生成器,递归调用
  • 原文地址:https://www.cnblogs.com/chusiping/p/2254036.html
Copyright © 2011-2022 走看看