閒著無聊,用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);
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