我想做一个QQ自动登陆,使用的QQ是2009.现在先模拟打开QQ,然后通过api调用回调函数。回调函数为一个委托方法,但是在方法中整个参数乱码,请问如何解决?
具体流程为,启动QQ,获取当前启动QQ的句柄,通过EnumChildWindows方法回调方法,但是在EnumWindowsProc中,account和pwd乱码。请问如何解决?
public delegate bool CallBack(IntPtr hwnd, int lParam, string account, string pwd ); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr EnumChildWindows(IntPtr hWndParent, CallBack lpEnumFunc, int lParam); /// <summary>
/// QQ登录
/// </summary>
public static void LoginIn(string account = "123456", string pwd = "123456")
{
//启动QQ程序
StartCmd(); IntPtr h;
string strName = "QQ2009";
h = FindWindow(null, strName);
if (h.ToInt32() != 0)
{
MoveWindow(h, 0, 0, 350, 300, true);
CallBack myCallBack = new CallBack(EnumWindowsProc);
EnumChildWindows(h, myCallBack, 0);
}
} /// <summary>
///将鼠标移动到登陆按钮
/// </summary>
/// <param name="h"></param>
/// <param name="lParam"></param>
/// <returns></returns>
private static bool EnumWindowsProc(IntPtr h, int lParam, string account, string pwd)
{
//改变账号
SetCursorPos(900, 530);
SetForegroundWindow(h);
SendMessage(h, 0x000C, IntPtr.Zero, account.ToString()); //移动鼠标到登陆按钮
SetCursorPos(1090, 645);
SetForegroundWindow(h);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
return false;
}