您的位置:首页 > 其它

windows API 自动登录

2011-12-30 12:14 113 查看
private void button2_Click(object sender, EventArgs e)

{

System.Diagnostics.Process myProcess = System.Diagnostics.Process.Start(@"E:\网店管家(企业版)2.1\cc.exe");

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

myProcess.WaitForInputIdle(10000);

SearchWindow();

// SendKeys.SendWait("{Enter}");

}

private void SearchWindow()

{

IntPtr ParenthWnd = new IntPtr(0);

IntPtr EdithWnd = new IntPtr(0);

IntPtr Con = new IntPtr(0);

IntPtr pw = new IntPtr(0);

//查到窗体,得到整个窗体

ParenthWnd = FindWindow("TForm_login", "电话服务平台【登陆】");//用spy++这个软件可以得到(TForm_login)类名和电话服务平台【登陆】下载地址http://download.csdn.net/detail/bychentufeiyang/3984135

//判断这个窗体是否有效

if (!ParenthWnd.Equals(IntPtr.Zero))

{

//得到User Name这个子窗体,并设置其内容

EdithWnd = FindWindowEx(ParenthWnd, IntPtr.Zero, "TPanel", "");

IntPtr EdithWnd1 = FindWindowEx(EdithWnd, IntPtr.Zero, "TsuiComboBox", "");

SendMessage(EdithWnd1, WM_SETTEXT, (IntPtr)0, "wangw");

IntPtr EdithWnd2 = FindWindowEx(EdithWnd, IntPtr.Zero, "TsuiMaskEdit", "");

IntPtr EdithWnd3 = FindWindow("TForm_TelReg", "来电受理");

SendMessage(EdithWnd2, WM_SETTEXT, (IntPtr)0, "123456");

SendKeys.SendWait("{Enter}");

}

}

const int WM_GETTEXT = 0x000D;

const int WM_SETTEXT = 0x000C;

const int WM_CLICK = 0x00F5;

const int WM_SYSCOMMAND = 0x0112;

const int SC_MAXIMIZE = 0xF030;

[DllImport("user32.dll", EntryPoint = "FindWindow")]

private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]

private static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

private static extern IntPtr GetForegroundWindow(); //WINAPI 获取当前活动窗体的句柄

[DllImport("User32.dll", EntryPoint = "SendMessage")]

private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

[DllImport("user32.dll")]

private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll", EntryPoint = "FindWindow")]

private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]

private static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]

static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

private static extern IntPtr GetForegroundWindow(); //WINAPI 获取当前活动窗体的句柄

[DllImport("User32.dll", EntryPoint = "SendMessage")]

private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

[DllImport("user32.dll")]

private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: