1. 程式人生 > >User32.dll 中的函式

User32.dll 中的函式

using System;    
using System.Collections.Generic;    
using System.Linq;    
using System.Text;    
using System.Runtime.InteropServices;    
   
namespace WindowsAPI    
{    
    class CSharp_Win32Api    
    {   
        #region User32.dll 函式    
        /// <summary>    
        /// 該函式檢索一指定視窗的客戶區域或整個螢幕的顯示裝置上下文環境的控制代碼,以後可以在GDI函式中使用該控制代碼來在裝置上下文環境中繪圖。hWnd:裝置上下文環境被檢索的視窗的控制代碼    
        /// </summary>    
        [DllImport("user32.dll", CharSet = CharSet.Auto)]    
        public static extern IntPtr GetDC(IntPtr hWnd);    
        /// <summary>    
        /// 函式釋放裝置上下文環境(DC)供其他應用程式使用。    
        /// </summary>    
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);    
        /// <summary>    
        /// 該函式返回桌面視窗的控制代碼。桌面視窗覆蓋整個螢幕。    
        /// </summary>    
        static public extern IntPtr GetDesktopWindow();    
        /// <summary>    
        /// 該函式設定指定視窗的顯示狀態。    
        /// </summary>    
        static public extern bool ShowWindow(IntPtr hWnd, short State);    
        /// <summary>    
        /// 通過傳送重繪訊息 WM_PAINT 給目標窗體來更新目標窗體客戶區的無效區域。    
        /// </summary>    
        static public extern bool UpdateWindow(IntPtr hWnd);    
        /// <summary>    
        /// 該函式將建立指定視窗的執行緒設定到前臺,並且啟用該視窗。鍵盤輸入轉向該視窗,併為使用者改各種可視的記號。系統給建立前臺視窗的執行緒分配的許可權稍高於其他執行緒。    
        /// </summary>    
        static public extern bool SetForegroundWindow(IntPtr hWnd);    
        /// <summary>    
        /// 該函式改變一個子視窗,彈出式視窗式頂層視窗的尺寸,位置和Z序。    
        /// </summary>    
        static public extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int Width, int Height, uint flags);    
        /// <summary>    
        /// 開啟剪下板    
        /// </summary>    
        static public extern bool OpenClipboard(IntPtr hWndNewOwner);    
        /// <summary>    
        /// 關閉剪下板    
        /// </summary>    
        static public extern bool CloseClipboard();    
        /// <summary>    
        /// 開啟清空</summary>    
        static public extern bool EmptyClipboard();    
        /// <summary>    
        /// 將存放有資料的記憶體塊放入剪下板的資源管理中    
        /// </summary>    
        static public extern IntPtr SetClipboardData(uint Format, IntPtr hData);    
        /// <summary>    
        /// 在一個矩形中裝載指定選單條目的螢幕座標資訊     
        /// </summary>    
        static public extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, uint Item, ref RECT rc);    
   
        [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]    
        /// <summary>    
        /// 該函式獲得一個指定子視窗的父視窗控制代碼。    
        /// </summary>    
        public static extern IntPtr GetParent(IntPtr hWnd);    
        /// <summary>    
        /// 該函式將指定的訊息傳送到一個或多個視窗。此函式為指定的視窗呼叫視窗程式,直到視窗程式處理完訊息再返回。     
        /// </summary>    
        /// <param name="hWnd">其視窗程式將接收訊息的視窗的控制代碼</param>    
        /// <param name="msg">指定被髮送的訊息</param>    
        /// <param name="wParam">指定附加的訊息指定資訊</param>    
        /// <param name="lParam">指定附加的訊息指定資訊</param>    
        /// <returns></returns>    
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);    
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);            
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);    
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);           
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTON lParam);            
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTONINFO lParam);          
        public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref REBARBANDINFO lParam);          
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TVITEM lParam);           
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref LVITEM lParam);        
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref HDITEM lParam);       
        public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref HD_HITTESTINFO hti);      
        /// <summary>    
        /// 該函式將一個訊息放入(寄送)到與指定視窗建立的執行緒相聯絡訊息佇列裡    
        /// </summary>    
        public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);    
        public static extern IntPtr SetWindowsHookEx(int hookid, HookProc pfnhook, IntPtr hinst, int threadid);    
   
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]    
        public static extern bool UnhookWindowsHookEx(IntPtr hhook);    
   
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]    
        public static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);    
        /// <summary>    
        /// 該函式對指定的視窗設定鍵盤焦點。    
        /// </summary>    
        public static extern IntPtr SetFocus(IntPtr hWnd);    
        /// <summary>    
        /// 該函式在指定的矩形裡寫入格式化文字,根據指定的方法對文字格式化(擴充套件的製表符,字元對齊、折行等)。    
        /// </summary>    
        public extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, int uFormat);    
        /// <summary>    
        /// 該函式改變指定子視窗的父視窗。    
        /// </summary>    
        public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);    
        /// <summary>    
        /// 獲取對話方塊中子視窗控制元件的控制代碼    
        /// </summary>    
        public extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);    
        /// <summary>    
        /// 該函式獲取視窗客戶區的座標。    
        /// </summary>    
        public extern static int GetClientRect(IntPtr hWnd, ref RECT rc);    
        /// <summary>    
        /// 該函式向指定的窗體新增一個矩形,然後視窗客戶區域的這一部分將被重新繪製。    
        /// </summary>    
        public extern static int InvalidateRect(IntPtr hWnd, IntPtr rect, int bErase);    
        /// <summary>    
        /// 該函式產生對其他執行緒的控制,如果一個執行緒沒有其他訊息在其訊息佇列裡。    
        /// </summary>    
        public static extern bool WaitMessage();    
        /// <summary>    
        /// 該函式為一個訊息檢查執行緒訊息佇列,並將該訊息(如果存在)放於指定的結構。    
        /// </summary>    
        public static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, uint wFlag);    
        /// <summary>    
        /// 該函式從呼叫執行緒的訊息佇列裡取得一個訊息並將其放於指定的結構。此函式可取得與指定視窗聯絡的訊息和由PostThreadMesssge寄送的執行緒訊息。此函式接收一定範圍的訊息值。    
        /// </summary>    
        public static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);    
        /// <summary>    
        /// 該函式將虛擬鍵訊息轉換為字元訊息。    
        /// </summary>    
        public static extern bool TranslateMessage(ref MSG msg);    
        /// <summary>    
        /// 該函式排程一個訊息給視窗程式。    
        /// </summary>    
        public static extern bool DispatchMessage(ref MSG msg);    
        /// <summary>    
        /// 該函式從一個與應用事例相關的可執行檔案(EXE檔案)中載入指定的游標資源.    
        /// </summary>    
        public static extern IntPtr LoadCursor(IntPtr hInstance, uint cursor);    
        /// <summary>    
        /// 該函式確定游標的形狀。    
        /// </summary>    
        public static extern IntPtr SetCursor(IntPtr hCursor);    
        /// <summary>    
        /// 確定當前焦點位於哪個控制元件上。    
        /// </summary>    
        public static extern IntPtr GetFocus();    
        /// <summary>    
        /// 該函式從當前執行緒中的視窗釋放滑鼠捕獲,並恢復通常的滑鼠輸入處理。捕獲滑鼠的視窗接收所有的滑鼠輸入(無論游標的位置在哪裡),除非點選滑鼠鍵時,游標熱點在另一個執行緒的視窗中。    
        /// </summary>    
        public static extern bool ReleaseCapture();    
        /// <summary>    
        /// 準備指定的視窗來重繪並將繪畫相關的資訊放到一個PAINTSTRUCT結構中。    
        /// </summary>    
        public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);    
        /// <summary>    
        /// 標記指定視窗的繪畫過程結束,每次呼叫BeginPaint函式之後被請求    
        /// </summary>    
        public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);    
        /// <summary>    
        /// 半透明窗體    
        /// </summary>    
        public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);    
        /// <summary>    
        /// 該函式返回指定視窗的邊框矩形的尺寸。該尺寸以相對於螢幕座標左上角的螢幕座標給出。    
        /// </summary>    
        public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);    
        /// <summary>    
        /// 該函式將指定點的使用者座標轉換成螢幕座標。    
        /// </summary>    
        public static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);    
        /// <summary>    
        /// 當在指定時間內滑鼠指標離開或盤旋在一個視窗上時,此函式寄送訊息。    
        /// </summary>    
        public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);    
        /// <summary>    
        ///     
        /// </summary>    
        public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);    
        /// <summary>    
        /// 該函式檢取指定虛擬鍵的狀態。    
        /// </summary>    
        public static extern ushort GetKeyState(int virtKey);    
        /// <summary>    
        /// 該函式改變指定視窗的位置和尺寸。對於頂層視窗,位置和尺寸是相對於螢幕的左上角的:對於子視窗,位置和尺寸是相對於父視窗客戶區的左上角座標的。    
        /// </summary>    
        public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);    
        /// <summary>    
        /// 該函式獲得指定視窗所屬的類的類名。    
        /// </summary>    
        public static extern int GetClassName(IntPtr hWnd, out STRINGBUFFER ClassName, int nMaxCount);    
        /// <summary>    
        /// 該函式改變指定視窗的屬性    
        /// </summary>    
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);    
        /// <summary>    
        /// 該函式檢索指定視窗客戶區域或整個螢幕的顯示裝置上下文環境的控制代碼,在隨後的GDI函式中可以使用該控制代碼在裝置上下文環境中繪圖。    
        /// </summary>    
        public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, uint flags);    
        /// <summary>    
        /// 獲取整個視窗(包括邊框、滾動條、標題欄、選單等)的裝置場景 返回值 Long。    
        /// </summary>    
        public static extern IntPtr GetWindowDC(IntPtr hWnd);    
        /// <summary>    
        /// 該函式用指定的畫刷填充矩形,此函式包括矩形的左上邊界,但不包括矩形的右下邊界。    
        /// </summary>    
        public static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);    
        /// <summary>    
        /// 該函式返回指定視窗的顯示狀態以及被恢復的、最大化的和最小化的視窗位置。    
        /// </summary>    
        public static extern int GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT wp);    
        /// <summary>    
        /// 該函式改變指定視窗的標題欄的文字內容    
        /// </summary>    
        public static extern int SetWindowText(IntPtr hWnd, string text);    
        /// <summary>    
        /// 該函式將指定視窗的標題條文字(如果存在)拷貝到一個快取區內。如果指定的視窗是一個控制,則拷貝控制的文字。    
        /// </summary>    
        public static extern int GetWindowText(IntPtr hWnd, out STRINGBUFFER text, int maxCount);    
        /// <summary>    
        /// 用於得到被定義的系統資料或者系統配置資訊.    
        /// </summary>    
        static public extern int GetSystemMetrics(int nIndex);    
        /// <summary>    
        /// 該函式設定滾動條引數,包括滾動位置的最大值和最小值,頁面大小,滾動按鈕的位置。    
        /// </summary>    
        static public extern int SetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw);    
        /// <summary>    
        /// 該函式顯示或隱藏所指定的滾動條。    
        /// </summary>    
        public static extern int ShowScrollBar(IntPtr hWnd, int bar, int show);    
        /// <summary>    
        /// 該函式可以啟用一個或兩個滾動條箭頭或是使其失效。    
        /// </summary>    
        public static extern int EnableScrollBar(IntPtr hWnd, uint flags, uint arrows);    
        /// <summary>    
        /// 該函式將指定的視窗設定到Z序的頂部。    
        /// </summary>    
        public static extern int BringWindowToTop(IntPtr hWnd);    
        /// <summary>    
        /// 該函式滾動指定窗體客戶區域的目錄。    
        /// </summary>    
        static public extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, uint flags);    
        /// <summary>    
        /// 該函式確定給定的視窗控制代碼是否識別一個已存在的視窗。    
        /// </summary>    
        public static extern int IsWindow(IntPtr hWnd);    
        /// <summary>    
        /// 該函式將256個虛擬鍵的狀態拷貝到指定的緩衝區中。    
        /// </summary>    
        public static extern int GetKeyboardState(byte[] pbKeyState);    
        /// <summary>    
        /// 該函式將指定的虛擬鍵碼和鍵盤狀態翻譯為相應的字元或字串。該函式使用由給定的鍵盤佈局控制代碼標識的物理鍵盤佈局和輸入語言來翻譯程式碼。    
        /// </summary>    
        public static extern int ToAscii(int uVirtKey,int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey,int fuState);   
        #endregion    
   
    }    
}