请帮助,如何达到其他程序控制. [英] Help please , how to reach other program control.

查看:72
本文介绍了请帮助,如何达到其他程序控制.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#初学者.我想这样做:


-------------------------------------------------- -----------
要了解我想在这里做的是这个示例:我有2个程序:
-------------------------------------------------- ---------------
Program1包含:Textbox(1)
Program2包含:Textbox(2)和Button(2)

因此,当我打开程序1并在textbox(1)中键入文本时,
然后转到程序2并单击按钮(2),文本框(2)获得文本框(1)的文本
-------------------------------------------------- ---------------
请问有人能解释如何解决这样的难题吗?
我已经读了太多东西,所以我发现了有关API和非托管dll方法以及spy ++的信息以及许多其他信息,但是这些信息不是有条理的,我的确感到更加困惑.

因此,如果有人可以为此编写代码并详细解释代码,我将不胜感激.

非常感谢.

解决方案

澄清了您的问题.但是,当将对象从一个程序转移到另一个时,使用会话对象.

 使用系统;
使用 System.Diagnostics;
使用使用System.Runtime.InteropServices;
使用使用System.Windows.Forms;

命名空间 ConsoleApplication1
{
     class 程序
    {
        // 对于Windows Mobile,将user32.dll替换为coredll.dll 
        [DllImport(" )]
        [返回:MarshalAs(UnmanagedType.Bool)]
        静态 外部 布尔 SetForegroundWindow( IntPtr  hWnd);


        静态 无效 Main(字符串 []参数)
        {
            Process myProcess = Process.Start( @" );
            SetForegroundWindow(myProcess.Handle);
            如果(myProcess.Responding)
                SendKeys.SendWait(" );
            Console.ReadLine();
        }
    }
} 


我不知道如何编写代码,但是我将通过以下方式进行研究:
当按下Button(2)时,App(2)应该向App(1)发送一条消息.当App(1)收到此消息时,它应该从Textbox(1)获取文本,然后编写一条包含该文本作为参数的消息,然后将该消息发送给App(2).然后,App(2)处理消息和参数,并在Textbox(2)中显示文本. :)


I''m a c# beginner . and I want to do this :


-------------------------------------------------------------
to understand what I want to do here is this example:I have 2 programs :
-----------------------------------------------------------------
Program1 contains : Textbox(1)
Program2 contains : Textbox(2) and Button(2)

So when I open program 1 and type text in textbox(1)
then go to program 2 and click the button(2) , the textbox(2) gain the text of textbox(1)
-----------------------------------------------------------------
can any one explain how to solve such hard problem, please?
I''ve read too much so I found things about API and unmanaged dll methods and spy++ and many other things but the information is not organized , I really got more confused.

So if any one could Write the code for that and explain the code in details , I''ll really appreciate it.

Thank You very much.

解决方案

clerify your question.but when transfer object from one program to another use session object.


using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        // For Windows Mobile, replace user32.dll with coredll.dll
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetForegroundWindow(IntPtr hWnd);


        static void Main(string[] args)
        {
            Process myProcess = Process.Start(@"c:\windows\notepad.exe");
            SetForegroundWindow(myProcess.Handle);
            if (myProcess.Responding)
                SendKeys.SendWait("This text was entered using the System.Windows.Form=s.SendKeys method.");
            Console.ReadLine();
        }
    }
}


I don''t know how to code this, but I would investigate doing it in the following manner:
When Button(2) is pressed, App(2) should send a message to App(1). When App(1) receives this message, it should get the text from Textbox(1), then compose a message that includes the text as a parameter and then sends that message to App(2). App(2) then processes the message and parameter and displays the text in Textbox(2). :)


这篇关于请帮助,如何达到其他程序控制.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆