用C#winform开发一个全自动操作的一个小程序。

里面架构非常简单,就只有一个webBrowser控件和五六个按钮。这几个按钮是实现操作网页用的。比如向网页的文本框输入,点击,取值等用处。现在我想如何实现,这些按钮在运行... 里面架构非常简单,就只有一个webBrowser控件和五六个按钮。这几个按钮是实现操作网页用的。比如向网页的文本框输入,点击,取值等用处。现在我想如何实现,这些按钮在运行程序时就自动运行下去,不再用人工点击这几个按钮,另外,当网站弹出对话框时我怎么取出网页的对话框并让程序自动点击“是”还是“否”。 展开
 我来答
太阳之子601
2010-11-10 · TA获得超过163个赞
知道小有建树答主
回答量:136
采纳率:0%
帮助的人:83.5万
展开全部
其实你需要的是一个模拟按键和鼠标的操作
为何不直接讲呢?
模拟键盘的给你

//定义
{
[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT {
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
internal struct KEYBDINPUT {
public short wVk;
public short wScan;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Explicit)]
internal struct Input {
[FieldOffset(0)]
public int type;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public KEYBDINPUT ki;
[FieldOffset(4)]
public HARDWAREINPUT hi;
}

[StructLayout(LayoutKind.Sequential)]
internal struct HARDWAREINPUT {
public int uMsg;
public short wParamL;
public short wParamH;
}

internal class INPUT {
public const int MOUSE = 0;
public const int KEYBOARD = 1;
public const int HARDWARE = 2;
}

internal static class NativeMethods {
[DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = false)]
internal static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = false)]
internal static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("User32.dll", EntryPoint = "SendInput", CharSet = CharSet.Auto)]
internal static extern UInt32 SendInput(UInt32 nInputs, Input[] pInputs, Int32 cbSize);

[DllImport("Kernel32.dll", EntryPoint = "GetTickCount", CharSet = CharSet.Auto)]
internal static extern int GetTickCount();

[DllImport("User32.dll", EntryPoint = "GetKeyState", CharSet = CharSet.Auto)]
internal static extern short GetKeyState(int nVirtKey);

[DllImport("User32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
}
}

//模拟过程
private void SendKeyDown(short key)
{
Input[] input = new Input[1];
input[0].type = INPUT.KEYBOARD;
input[0].ki.wVk = key;
input[0].ki.time = NativeMethods.GetTickCount();

if (NativeMethods.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}

private void SendKeyUp(short key)
{
Input[] input = new Input[1];
input[0].type = INPUT.KEYBOARD;
input[0].ki.wVk = key;
input[0].ki.dwFlags = KeyboardConstaint.KEYEVENTF_KEYUP;
input[0].ki.time = NativeMethods.GetTickCount();

if (NativeMethods.SendInput((uint)input.Length, input, Marshal.SizeOf(input[0])) < input.Length)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}

//调用方法
short key = 65;
SendKeyDown(key);
SendKeyUp(key);
MarsCode
2024-08-21 广告
```c#include int main() { int a, b; printf("请输入两个整数: "); scanf("%d %d", &a, &b); int sum = a + b; printf(... 点击进入详情页
本回答由MarsCode提供
16...7@qq.com
2010-11-09 · TA获得超过781个赞
知道小有建树答主
回答量:818
采纳率:0%
帮助的人:380万
展开全部
1楼,这要求还不详细?!
不过你什么都不给,就是楼主你的不对了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
mach369
2010-11-09 · TA获得超过274个赞
知道小有建树答主
回答量:873
采纳率:0%
帮助的人:423万
展开全部
具体啥要求
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式