关于动态操作另一个系统的问题?
请教一个问题,一个系统已经做好,里面有一个按钮.我在我的系统里面放一个按钮,我按这个按钮,怎样能够进入哪个系统,并执行哪个按钮已经存在的onclick事件,不用打开别人的系统人为操作?谢谢! 问题点数:100、回复次数:14Top
1 楼zzhuz(大件)回复于 2003-07-07 17:53:30 得分 10
过来接分的~Top
2 楼declude(郁闷)回复于 2003-07-07 18:40:32 得分 0
晕!Top
3 楼yohomonkey(思考中的猴)回复于 2003-07-07 18:58:49 得分 50
方法如下:
A页面的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim StrScript As String
StrScript = "<script>var win=null; win=window.open('WebForm2.aspx','MywinName'); win.document.all.item('open').click(); </Script>"
Me.RegisterStartupScript("popchick", StrScript)
End Sub
B页面代码:
html中:<input type="button" name="open" id="open" value="open" οnclick="alert('aaa');">Top
4 楼yohomonkey(思考中的猴)回复于 2003-07-07 19:02:29 得分 10
这是根据脚本的属性改写的,实例如下:
A页:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
var win=null;
function openWin()
{
win=window.open('Bpage.html','MywinName');
win.document.all.item("open").click();
}
</script>
</HEAD>
<BODY>
<input type="button" value="open" οnclick="openWin()">
</BODY>
</HTML>
B页:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<input type="button" name="open" id="open" value="open" οnclick="alert('aaa');">
</BODY>
</HTML>
脚本的使用对于.net也是必不可少的。
希望大家多交流!Top
5 楼Montaque(每天回答两个问题)回复于 2003-07-07 19:25:39 得分 10
shell
Sendkeys.SendTop
6 楼tttzms(乡巴佬)回复于 2003-07-07 19:44:07 得分 0
学习Top
7 楼liduke(天下有雪)回复于 2003-07-07 20:39:52 得分 0
学习中。。。。Top
8 楼lmdhit(封情)回复于 2003-07-07 20:45:38 得分 0
xuexi !Top
9 楼TheAres(班门斧)回复于 2003-07-07 20:47:11 得分 20
下面的程序演示的是启动一个计算器,然后,发送3,*,8,最后在计算器上显示24。
步骤如下:
1.启动计算器,得到handle
2.获得活动窗口的线程号,获得与自己程序的窗口相关的线程号
3.将两个线程的输入联系起来
4,SendKey
5.线程分离.
这是以前作的一个例子,有一些对你的这个问题没有用,自己挑挑吧。在我的计算机上已经运行通过,看到那个24了。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;
namespace activeWindow
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder title, int size);
[ DllImport("user32.dll") ]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("user32.dll")]
private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
[DllImport("user32.dll")]
private static extern IntPtr GetFocus();
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label captionWindowLabel;
private System.Windows.Forms.Label IDWindowLabel;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.IContainer components;
private void GetActiveWindow()
{
Process p = Process.Start("calc.exe");
IntPtr ActiveWindowHandle = p.MainWindowHandle;
//获得活动窗口的线程号
IntPtr handle1 = GetWindowThreadProcessId(this.Handle,IntPtr.Zero);
IntPtr handle2 = GetWindowThreadProcessId(ActiveWindowHandle,IntPtr.Zero);
if (ActiveWindowHandle != this.Handle)
{
//将两个线程的输入联系起来
AttachThreadInput(handle1,handle2,1);
SendKeys.Send("3");
SendKeys.Send("*");
SendKeys.Send("8");
SendKeys.Send("=");
//线程分离
AttachThreadInput(handle1,handle2,0);
}
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.captionWindowLabel = new System.Windows.Forms.Label();
this.IDWindowLabel = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(174, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(143, 19);
this.label1.TabIndex = 0;
this.label1.Text = "Active Window Detail";
//
// label2
//
this.label2.Location = new System.Drawing.Point(20, 46);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(123, 19);
this.label2.TabIndex = 1;
this.label2.Text = "Window Caption : ";
//
// label3
//
this.label3.Location = new System.Drawing.Point(20, 102);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(123, 18);
this.label3.TabIndex = 2;
this.label3.Text = "Window Handle :";
//
// captionWindowLabel
//
this.captionWindowLabel.Location = new System.Drawing.Point(143, 46);
this.captionWindowLabel.Name = "captionWindowLabel";
this.captionWindowLabel.Size = new System.Drawing.Size(287, 47);
this.captionWindowLabel.TabIndex = 3;
//
// IDWindowLabel
//
this.IDWindowLabel.Location = new System.Drawing.Point(143, 102);
this.IDWindowLabel.Name = "IDWindowLabel";
this.IDWindowLabel.Size = new System.Drawing.Size(128, 18);
this.IDWindowLabel.TabIndex = 4;
//
// button1
//
this.button1.Location = new System.Drawing.Point(225, 148);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(62, 28);
this.button1.TabIndex = 5;
this.button1.Text = "EXIT";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// button2
//
this.button2.Location = new System.Drawing.Point(304, 144);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(128, 32);
this.button2.TabIndex = 6;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(512, 200);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.IDWindowLabel,
this.captionWindowLabel,
this.label3,
this.label2,
this.label1});
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Window Information";
this.TopMost = true;
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void timer1_Tick(object sender, System.EventArgs e)
{
//GetActiveWindow();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
GetActiveWindow();
}
}
}
Top
10 楼layerr(new WantToKnow(C#))回复于 2003-07-07 23:36:40 得分 0
如果你那两个系统是单独的两个WinForm应用程序的话,就只有用消息了。
在A系统启动时,用XML文件记录其Handle的值;
在A系统中重载DefWndProc函数,用其来接收用户自定义的消息。如:
先写一个公用类(在A系统和B系统中都要引用)
class WM
{
const int user=0x400;
const int click=user+1;
}
在A系统中重载DefWndProc函数:
protected override void DefWndProc ( ref System.Windows.Forms.Message m )
{
switch(m.Msg)
{
case WM.click:
执行click事件
default:
base.DefWndProc(ref m);
break;
}
}
再在B系统中引入API函数PostMessage()函数,
通过前面A系统启动时保存在XML文件中的Handle来获取A系统的Handle,在B系统中用PostMessage()函数向这个Handle发消息即可。
如果你对消息的使用不够熟悉的话,可以给我邮件:
ly@cqit.com.cn
Top
11 楼lizhenlz(老猫)回复于 2003-07-09 11:56:53 得分 0
请教一个比较棘手的问题,上一次你帮我的哪个问题,我还想加一点,别的都能实现了,现在有一个控件很麻烦,text Field,怎样动态得到一个上传的值呀?其实,现在模拟选择这个过程。别的应该没有问题,现在主要一点,怎样模拟点击“浏览”,这个动作?别的调用API应该没有问题.
Top
12 楼aspnetwuxueyou(SHIP IT)回复于 2003-07-09 12:11:17 得分 0
其实你的问题并不难,就是蠛诳退频拿毒俜ɡ雌平獗鹑说拿苈攵选?
实现方法就是枚举窗口,Windows提供了这样的API,应该是EnumWindows function.
You can see a lot of such software when searching google,
May you good luckTop
13 楼aspnetwuxueyou(SHIP IT)回复于 2003-07-09 12:13:18 得分 0
You have to guess
which is the UserName field,
which is the Password field,
which is the Confirm button.Top
14 楼yohomonkey(思考中的猴)回复于 2003-07-09 13:13:25 得分 0
<INPUT style="Z-INDEX: 101; LEFT: 83px; POSITION: absolute; TOP: 112px" type="file" runat="server" id="load">
用 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.RegisterStartupScript("pop", "<script>document.all.item('load').click();</script>")
End Sub
如果没有控件没有ID就要看实际情况了。Top