闲着无聊,用C#做了一个QQ视频窗口最大化。
原理很简单就是WinApi的调用而已。
/// <summary> /// 查询窗体 /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [DllImport("User32.dll", EntryPoint = "FindWindow")] public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); /// <summary> /// 获取窗体标题 /// </summary> /// <param name="hwnd"></param> /// <param name="text"></param> /// <param name="maxLength"></param> /// <returns></returns> [DllImport("user32.dll")] private static extern int GetWindowText(IntPtr hwnd, StringBuilder text, int maxLength); /// <summary> /// 设置窗体显示 /// </summary> /// <param name="hwnd"></param> /// <param name="nCmdShow">1-常规 2-最小化 3-最大化</param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); /// <summary> /// 设置窗体是否置顶 /// </summary> /// <param name="hWnd"></param> /// <param name="hWndInsertAfter"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="Width"></param> /// <param name="Height"></param> /// <param name="flags"></param> /// <returns></returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);
通过spy工具获取QQ视频窗体的类名是"TXGuiFoundation"
IntPtr maindHwnd = FindWindow("TXGuiFoundation", null); //获得QQ窗体的句柄 if (maindHwnd != IntPtr.Zero) { //StringBuilder sb = new StringBuilder(255); //GetWindowText(maindHwnd, sb, 255); //MessageBox.Show(sb.ToString()); ShowWindow(maindHwnd, 3); SetWindowPos(maindHwnd, -2, 0, 0, 0, 0, 0x001 | 0x002 | 0x040); } else { MessageBox.Show("没有找到窗口"); }
需要双击把视频窗口点击出来,运行代码既可。
源码下载地址
http://files.cnblogs.com/mohc/QQVideoShowWindow.rar