自动打开登录游戏的代码
给游戏做自动登录时的代码
代码
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8
9namespace test
10{
11 public partial class Form1 : Form
12 {
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
21 public Form1()
22 {
23 InitializeComponent();
24 }
25
26 private void button4_Click(object sender, EventArgs e)
27 {
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
35 //WinList();
36 API.GetGameProcess("World of Warcraft");
37 this.timer1.Interval = 8000;
38 this.timer1.Start();
39 }
40
41 private void Form1_Load(object sender, EventArgs e)
42 {
43 WinList();
44 }
45
46 private void WinList()
47 {
48 this.listBox1.Items.Clear();
49
50 API.WindowInfo[] wndList = new API.WindowInfo[100];
51 wndList = ai.GetAllDesktopWindows();
52 for (int i = 0; i < wndList.Length; i++)
53 {
54 if (wndList[i].szWindowName != "")
55 this.listBox1.Items.Add(wndList[i].szWindowName);
56 }
57 }
58
59 private IntPtr WinList(string wname)
60 {
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 {
66 if (wndList[i].szWindowName == wname)
67 return wndList[i].hWnd;
68 }
69 return Wnd;
70 }
71
72 private void button1_Click(object sender, EventArgs e)
73 {
74 //MessageBox.Show(this.listBox1.SelectedItem.ToString());
75 //API.GetGameProcess(this.listBox1.SelectedItem.ToString());
76
77 IntPtr ip = new IntPtr();
78 ip = WinList(this.listBox1.SelectedItem.ToString());
79 ai.SetWPos(ip);
80 }
81
82 private void button2_Click(object sender, EventArgs e)
83 {
84 string lpszParentWindow = "World of Warcraft"; //窗口标题
85
86 IntPtr ParenthWnd = new IntPtr(0);
87 IntPtr EdithWnd = new IntPtr(0);
88
89 //查到窗体,得到整个窗体
90 ParenthWnd = FindWindow(null, lpszParentWindow);
91
92 //判断这个窗体是否有效
93 if (!ParenthWnd.Equals(IntPtr.Zero))
94 {
95 SetWindowPos(ParenthWnd);
96 }
97 }
98
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
102 [System.Runtime.InteropServices.DllImport("User32.dll", EntryPoint = "FindWindow")]
103 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
104
105 [System.Runtime.InteropServices.DllImport("user32.dll")]
106 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
107
108 public static void SetWindowPos(IntPtr hWnd)
109 {
110 SetWindowPos(hWnd, -1, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0020);
111 }
112
113 private void timer1_Tick(object sender, EventArgs e)
114 {
115 string lpszParentWindow = "World of Warcraft"; //窗口标题
116
117 IntPtr ParenthWnd = new IntPtr(0);
118 IntPtr EdithWnd = new IntPtr(0);
119
120 //查到窗体,得到整个窗体
121 ParenthWnd = FindWindow(null, lpszParentWindow);
122
123 //判断这个窗体是否有效
124 if (!ParenthWnd.Equals(IntPtr.Zero))
125 {
126 SetWindowPos(ParenthWnd);
127 }
128 InputStr(ParenthWnd, "zhaanm");
129 SendMessage(ParenthWnd, WM_KEYDOWN, 0X09, 0x201E0001);
130 SendMessage(ParenthWnd, WM_KEYUP, 0X09, 0x201E0001);
131 }
132
133 public void InputStr(IntPtr ParenthWnd, string input)
134 {
135 byte[] aa = (ASCIIEncoding.ASCII.GetBytes(input));
136 for (int i = 0; i < aa.Length; i++)
137 {
138 int cr = aa[i];
139 SendMessage(ParenthWnd, WM_CHAR, cr, 0x201E0001);
140 }
141 }
142
143 }
144}
145
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8
9namespace test
10{
11 public partial class Form1 : Form
12 {
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
21 public Form1()
22 {
23 InitializeComponent();
24 }
25
26 private void button4_Click(object sender, EventArgs e)
27 {
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
35 //WinList();
36 API.GetGameProcess("World of Warcraft");
37 this.timer1.Interval = 8000;
38 this.timer1.Start();
39 }
40
41 private void Form1_Load(object sender, EventArgs e)
42 {
43 WinList();
44 }
45
46 private void WinList()
47 {
48 this.listBox1.Items.Clear();
49
50 API.WindowInfo[] wndList = new API.WindowInfo[100];
51 wndList = ai.GetAllDesktopWindows();
52 for (int i = 0; i < wndList.Length; i++)
53 {
54 if (wndList[i].szWindowName != "")
55 this.listBox1.Items.Add(wndList[i].szWindowName);
56 }
57 }
58
59 private IntPtr WinList(string wname)
60 {
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 {
66 if (wndList[i].szWindowName == wname)
67 return wndList[i].hWnd;
68 }
69 return Wnd;
70 }
71
72 private void button1_Click(object sender, EventArgs e)
73 {
74 //MessageBox.Show(this.listBox1.SelectedItem.ToString());
75 //API.GetGameProcess(this.listBox1.SelectedItem.ToString());
76
77 IntPtr ip = new IntPtr();
78 ip = WinList(this.listBox1.SelectedItem.ToString());
79 ai.SetWPos(ip);
80 }
81
82 private void button2_Click(object sender, EventArgs e)
83 {
84 string lpszParentWindow = "World of Warcraft"; //窗口标题
85
86 IntPtr ParenthWnd = new IntPtr(0);
87 IntPtr EdithWnd = new IntPtr(0);
88
89 //查到窗体,得到整个窗体
90 ParenthWnd = FindWindow(null, lpszParentWindow);
91
92 //判断这个窗体是否有效
93 if (!ParenthWnd.Equals(IntPtr.Zero))
94 {
95 SetWindowPos(ParenthWnd);
96 }
97 }
98
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
102 [System.Runtime.InteropServices.DllImport("User32.dll", EntryPoint = "FindWindow")]
103 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
104
105 [System.Runtime.InteropServices.DllImport("user32.dll")]
106 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
107
108 public static void SetWindowPos(IntPtr hWnd)
109 {
110 SetWindowPos(hWnd, -1, 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0020);
111 }
112
113 private void timer1_Tick(object sender, EventArgs e)
114 {
115 string lpszParentWindow = "World of Warcraft"; //窗口标题
116
117 IntPtr ParenthWnd = new IntPtr(0);
118 IntPtr EdithWnd = new IntPtr(0);
119
120 //查到窗体,得到整个窗体
121 ParenthWnd = FindWindow(null, lpszParentWindow);
122
123 //判断这个窗体是否有效
124 if (!ParenthWnd.Equals(IntPtr.Zero))
125 {
126 SetWindowPos(ParenthWnd);
127 }
128 InputStr(ParenthWnd, "zhaanm");
129 SendMessage(ParenthWnd, WM_KEYDOWN, 0X09, 0x201E0001);
130 SendMessage(ParenthWnd, WM_KEYUP, 0X09, 0x201E0001);
131 }
132
133 public void InputStr(IntPtr ParenthWnd, string input)
134 {
135 byte[] aa = (ASCIIEncoding.ASCII.GetBytes(input));
136 for (int i = 0; i < aa.Length; i++)
137 {
138 int cr = aa[i];
139 SendMessage(ParenthWnd, WM_CHAR, cr, 0x201E0001);
140 }
141 }
142
143 }
144}
145