可以获取本地当前登陆的QQ号,在网上看的获取QQ号的例子有很多,我写的这个demo是在大佬的基础上进行修改的。
1.引入命名空间:using System.Runtime.InteropServices;
2.调用如下代码:
//导入库 [DllImport("user32.dll")]
[DllImport("user32.dll", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi)]
private static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(int hwnd, StringBuilder lpString, int cch);
[DllImport("user32.dll", EntryPoint = "GetWindow")]
public static extern int GetWindow(int hwnd, int wCmd);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetClassName(int hWnd, StringBuilder lpClassName, int nMaxCount);
protected void Page_Load(object sender, EventArgs e)
{
int hWin = FindWindow("CTXOPConntion_Class", null);
if (hWin == 0)
{
return;
}
StringBuilder sbf = new StringBuilder(256);
StringBuilder sbfClass = new StringBuilder(256);
while (hWin > 0)
{
GetWindowText(hWin, sbf, sbf.Capacity);
if (sbf.ToString().Contains("OP_"))
{
int index=sbf.ToString().IndexOf('_');
Response.Write("<script>alert('" + sbf.ToString().Substring(index+1,sbf.Length-index-1) + "')</script>");
break;
}
}
}
web就可以获得相关的QQ号了,欢迎各位大佬指点。