none
如何在一个程序中调用另一个程序 RRS feed

  • 问题

  • 如何在一个程序中间调用另一个程序,使得在点击本程序中按钮的同时就间接的点击了另一个程序的按钮,使得本程序调用了另一个程序,但是又不显示另一个程序的窗口
    2016年5月29日 10:11

答案

全部回复

  • 可以参考一下这个,但是如果被调程序有界面的话,不知道怎么隐藏

    http://blog.csdn.net/zzzxxbird/article/details/6418197

    2016年5月30日 1:49
  • Hi,
    你可以用Win32 APi中的'SendMessage','FindWindows','FindWindowsEx'来实现你的需求(不过需要先捕获到对应按钮的句柄)

            //消息常量
            private const int WM_LBUTTONUP = 0x202;
            private const int WM_LBUTTONDOWN 0x201 ;

    //寻找窗口句柄 [DllImport("User32.dll", EntryPoint = "FindWindow")] public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); //寻找子窗口句柄(控件句柄) [DllImport("User32.dll", EntryPoint = "FindWindowEx")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName); //发送Message [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

    Regards,
    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    2016年5月30日 5:53
  • 调用另一个进程并隐藏该进程的窗体是可以做到的,但“执行当前按钮操作,目的进程也需要被操作”有些难度

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = true;  //不显示另一个程序的窗口
    startInfo.UseShellExecute = false;
    startInfo.FileName = "dcm2jpg.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

    // Call WaitForExit and then the using-statement will close.

    using (Process exeProcess = Process.Start(startInfo))
     {
         exeProcess.WaitForExit();
     }
     

    若是.NET程序,考虑用反射技术直接调用目的程序中的方法。

    若是非.NET程序,目的程序要公布SDK接口才可以这样做,比如Outlook二次开发

    或是hook,code inject技术,将代码注入到目的进程中,参考下面

    http://www.codeproject.com/Articles/5038/Using-Hooks-from-C

    http://www.codeproject.com/Articles/20565/Assembly-Manipulation-and-C-VB-NET-Code-Injection


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2016年5月30日 12:14
  • 你说的对我很有用,给的参考我看了,谢谢
    2016年5月31日 3:32