程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> QQ視頻窗口最大化

QQ視頻窗口最大化

編輯:C#入門知識

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved