给游戏做自动登录时的代码
![](/Images/OutliningIndicators/ContractedBlock.gif)
代码
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Text;
7
using System.Windows.Forms;
8![](/Images/OutliningIndicators/None.gif)
9
namespace test
10![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
11
public partial class Form1 : Form
12![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
13
API ai = new API();
14
int WM_KEYDOWN = 0X100; //按键按下时
15
int WM_KEYUP = 0X101; //按键放开时
16
int WM_SYSCHAR = 0X106;
17
int WM_SYSKEYUP = 0X105;
18
int WM_SYSKEYDOWN = 0X104; //按键按下时,且ALT键也被按着
19
int WM_CHAR = 0X102; //按键按下时
20![](/Images/OutliningIndicators/InBlock.gif)
21
public Form1()
22![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
23
InitializeComponent();
24
}
25![](/Images/OutliningIndicators/InBlock.gif)
26
private void button4_Click(object sender, EventArgs e)
27![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
28
System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
29
MyProcess.StartInfo.FileName = @"F:\OF\Launcher.exe";//外部程序路径
30
MyProcess.StartInfo.Verb = "Open";
31
MyProcess.StartInfo.CreateNoWindow = true;
32
MyProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
33
MyProcess.Start();
34![](/Images/OutliningIndicators/InBlock.gif)
35
//WinList();
36
API.GetGameProcess("World of Warcraft");
37
this.timer1.Interval = 8000;
38
this.timer1.Start();
39
}
40![](/Images/OutliningIndicators/InBlock.gif)
41
private void Form1_Load(object sender, EventArgs e)
42![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
43
WinList();
44
}
45![](/Images/OutliningIndicators/InBlock.gif)
46
private void WinList()
47![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
48
this.listBox1.Items.Clear();
49![](/Images/OutliningIndicators/InBlock.gif)
50
API.WindowInfo[] wndList = new API.WindowInfo[100];
51
wndList = ai.GetAllDesktopWindows();
52
for (int i = 0; i < wndList.Length; i++)
53![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
54
if (wndList[i].szWindowName != "")
55
this.listBox1.Items.Add(wndList[i].szWindowName);
56
}
57
}
58![](/Images/OutliningIndicators/InBlock.gif)
59
private IntPtr WinList(string wname)
60![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
61
IntPtr Wnd = new IntPtr(0);
62
API.WindowInfo[] wndList = new API.WindowInfo[100];
63
wndList = ai.GetAllDesktopWindows();
64
for (int i = 0; i < wndList.Length; i++)
65![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
66
if (wndList[i].szWindowName == wname)
67
return wndList[i].hWnd;
68
}
69
return Wnd;
70
}
71![](/Images/OutliningIndicators/InBlock.gif)
72
private void button1_Click(object sender, EventArgs e)
73![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
74
//MessageBox.Show(this.listBox1.SelectedItem.ToString());
75
//API.GetGameProcess(this.listBox1.SelectedItem.ToString());
76![](/Images/OutliningIndicators/InBlock.gif)
77
IntPtr ip = new IntPtr();
78
ip = WinList(this.listBox1.SelectedItem.ToString());
79
ai.SetWPos(ip);
80
}
81![](/Images/OutliningIndicators/InBlock.gif)
82
private void button2_Click(object sender, EventArgs e)
83![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
84
string lpszParentWindow = "World of Warcraft"; //窗口标题
85![](/Images/OutliningIndicators/InBlock.gif)
86
IntPtr ParenthWnd = new IntPtr(0);
87
IntPtr EdithWnd = new IntPtr(0);
88![](/Images/OutliningIndicators/InBlock.gif)
89
//查到窗体,得到整个窗体
90
ParenthWnd = FindWindow(null, lpszParentWindow);
91![](/Images/OutliningIndicators/InBlock.gif)
92
//判断这个窗体是否有效
93
if (!ParenthWnd.Equals(IntPtr.Zero))
94![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
95
SetWindowPos(ParenthWnd);
96
}
97
}
98![](/Images/OutliningIndicators/InBlock.gif)
99
[System.Runtime.InteropServices.DllImport("user32.dll")]
100
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
101![](/Images/OutliningIndicators/InBlock.gif)
102
[System.Runtime.InteropServices.DllImport("User32.dll", EntryPoint = "FindWindow")]
103
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
104![](/Images/OutliningIndicators/InBlock.gif)
105
[System.Runtime.InteropServices.DllImport("user32.dll")]
106
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
107![](/Images/OutliningIndicators/InBlock.gif)
108
public static void SetWindowPos(IntPtr hWnd)
109![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
110
SetWindowPos(hWnd, -1, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0020);
111
}
112![](/Images/OutliningIndicators/InBlock.gif)
113
private void timer1_Tick(object sender, EventArgs e)
114![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
115
string lpszParentWindow = "World of Warcraft"; //窗口标题
116![](/Images/OutliningIndicators/InBlock.gif)
117
IntPtr ParenthWnd = new IntPtr(0);
118
IntPtr EdithWnd = new IntPtr(0);
119![](/Images/OutliningIndicators/InBlock.gif)
120
//查到窗体,得到整个窗体
121
ParenthWnd = FindWindow(null, lpszParentWindow);
122![](/Images/OutliningIndicators/InBlock.gif)
123
//判断这个窗体是否有效
124
if (!ParenthWnd.Equals(IntPtr.Zero))
125![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
126
SetWindowPos(ParenthWnd);
127
}
128
InputStr(ParenthWnd, "zhaanm");
129
SendMessage(ParenthWnd, WM_KEYDOWN, 0X09, 0x201E0001);
130
SendMessage(ParenthWnd, WM_KEYUP, 0X09, 0x201E0001);
131
}
132![](/Images/OutliningIndicators/InBlock.gif)
133
public void InputStr(IntPtr ParenthWnd, string input)
134![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
135
byte[] aa = (ASCIIEncoding.ASCII.GetBytes(input));
136
for (int i = 0; i < aa.Length; i++)
137![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
138
int cr = aa[i];
139
SendMessage(ParenthWnd, WM_CHAR, cr, 0x201E0001);
140
}
141
}
142![](/Images/OutliningIndicators/InBlock.gif)
143
}
144
}
145![](/Images/OutliningIndicators/None.gif)
posted @
2007-10-09 10:41
凬月
阅读(
584)
评论()
编辑
收藏
举报