• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 319, comments - 22, trackbacks - 0, articles - 11
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            Windows 60個常用API

            Posted on 2011-04-19 23:23 RTY 閱讀(1375) 評論(0)  編輯 收藏 引用 所屬分類: C/C++
            Windows 60個常用API

            附錄A 常用的Windows API 調用
            本附錄列出了PowerBuilder 常用Windows API 系統調用同時給出了這些函數的功能
            說明方式以及應用示例下表首先給出常用API 調用的名稱和扼要功能讀者需要詳細了
            解某個函數的聲明格式和示例時可通過序號在本附錄中找到相應說明
            表A 常用的Windows API 系統
            序號 函數 功能
            1 Arc() 在窗口上畫一條弧線
            2 Beep() 讓計算機按指定的頻率和周期發聲
            3 BringWindowToTop() 將窗口放置在最前面
            4 Chord() 繪制弦圖
            5 CloseHandle() 釋放打開對象的句柄
            6 CloseWindow() 最小化窗口
            7 DeleteFileA() 刪除文件
            8 DeleteMenu() 刪除指定菜單的菜單項
            9 DestroyWindow() 關閉窗口
            10 DllRegisterServer() 觸發OCX 控件完成自注冊過程
            11 Ellipse() 繪制橢圓
            12 ExitWindowsEx() 通知Windows 關閉操作系統
            13 FatalExit() 立即退出應用程序
            14 FindWindowA() 根據窗口標題查找窗口
            15 FreeLibrary() 從活動內存中卸載一個DLL
            16 GetBkColor() 得到指定窗口的背景顏色
            17 GetCapture() 得到鼠標所在窗口的句柄
            18 GetComputerNameA() 得到執行應用程序的計算機的名稱
            19 GetClassNameA() 得到指定窗口或對象的類名
            20 GetCurrentDirectoryA() 得到當前工作目錄
            21 GetCurrentThread() 得到當前線程的句柄
            22 GetCursor() 得到光標的句柄
            23 GetCursorPos() 得到光標的位置
            24 GetDC() 得到指定窗口的設備上下文
            25 GetKeyboardState() 得到鍵盤的狀態
            26 GetKeyState() 得到鍵盤上指定按鍵的狀態
            27 GetModuleHandleA() 得到活動內存中指定模塊或動態鏈接庫的句柄
            28 GetPixel() 得到窗口上指定像素的顏色
            29 GetSystemMenu() 得到系統菜單或窗口菜單的句柄
            30 GetSystemTime() 得到系統時間并存放到一個結構中
            31 GetThreadPriority() 得到指定線程的優先級
            32 GetSystemMetrics() 得到屏幕的解析度以像素為單位
            33 GetUserNameA() 得到當前用戶的登錄名稱
            34 GetVolumnInformationA() 得到硬盤的參數信息
            35 GetWindowsDirectoryA() 得到缺省的Windows 目錄
            36 GlobalMemoryStatus() 得到內存的詳細信息
                
            附錄A 常用的774 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            774
            序號 函數 功能
            37 LineTo() 從當前位置到指定位置繪制一條直線
            38 LoadLibraryA() 將32 位DLL 加載到活動內存中
            39 mciSendStringA() 控制和播放.AVI 文件
            40 MessageBoxA() 顯示一個消息對話框
            41 Mouse_Event() 控制和操作鼠標
            42 MoveToEx() 將光標移動到指定位置同時保存移動前的光標位置
            43 MoveWindow() 移動放大或縮小窗口
            44 Pie() 繪制餅圖
            45 Polygon() 繪制多邊形
            46 PostMessageA() 向創建指定窗口的線索發送一條消息但不等待線索處理該消息
            47 Rectangle() 繪制矩形
            48 ReleaseCapture() 解鎖鼠標
            49 SendMessageA() 向創建指定窗口的線索發送一條消息但等待線索處理該消息
            50 SetCapture() 鎖定鼠標
            51 SetComputerNameA() 修改計算機的名稱
            52 SetCurrentDirectoryA() 設置當前目錄
            53 SetCursorPos() 設置光標的位置
            54 SetFocus() 將輸入焦點設置到指定對象或窗口上
            55 SetKeyboardState() 設置鍵盤的狀態
            56 SetPixel() 設置窗口上指定像素的顏色
            57 SetThreadPriority() 設置線程的優先級
            58 Sleep() 睡眠指定的時間
            59 SndPlaySoundA()
            WaveOutGetNumDevs()
            播放.WAV 文件
            60 SwapMouseButton() 交換鼠標的左右按鈕
            61 WinExec() 運行指定的可執行文件
            使用這些函數時首先將它們聲明為外部全局函數然后在腳本中調用在下面的所
            有聲明格式中聲明都應該在一行內書寫由于排版原因本書可能分寫在多行上需
            要注意的是所有引用類參數由關鍵字Ref 指明在傳遞之前都必須分配足夠的內存
            否則可能引發GPF 錯誤參看函數GetComputerNameA()的說明下面分別介紹這些函






            1 Arc()
            功能在窗口上畫一條弧線
            聲明格式FUNCTION boolean Arc(ulong hwnd,long r1,long r2,long r3,long r4,long a1,
            long a2,long a3,long a4) LIBRARY "Gdi32.dll"
            示例 Boolean rtn
            ulong l_handle, l_device
            long lv[8]
            l_handle = handle(w_main) // w_main 是一個示例窗口
            l_device = GetDC(l_handle) //得到窗口的設備上下文
            lv[ ] = {10,40,300,220,0,0,180,0} //數組賦值
            rtn = Arc(l_device, lv[1], lv[2], lv[3], lv[4], lv[5], lv[6], lv[7], lv[8])
            2 Beep()
            功能讓計算機按指定的頻率和周期發聲
                
            附錄A 常用的Windows API 調用 775
            附錄
            A
            常用的
            Windows API調用
            775
            聲明格式FUNCTION boolean Beep(long freq,long dur) LIBRARY "Kernel32.dll"
            示例 Boolean rtn
            Long ll_freq, ll_dur
            ll_freq = 500
            ll_dur = 20
            rtn = Beep(ll_freq, ll_dur)
            3 BringWindowToTop()
            功能將窗口放置在最前面
            聲明格式FUNCTION boolean BringWindowToTop(ulong w_handle) LIBRARY
            "User32.dll"
            示例 Boolean rtn
            ulong l_handle
            l_handle = handle(w_win2) //得到窗口的句柄
            rtn = BringWindowToTop(l_handle)
            4 Chord()
            功能繪制弦圖弦圖由橢圓的一部分和一個線段組成
            聲明格式FUNCTION boolean Chord(ulong hwnd,long x1,long y1,long x2,long y2,long r1,
            long r2, long r3, long r4) LIBRARY "Gdi32.dll"
            示例 boolean rtn
            ulong l_handle, l_device
            long lv[8]
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            l_device = GetDC(handle(w_main))
            lv[ ] = {5,5,200,200,0,0,200,300}
            rtn = Chord(l_device, lv[1], lv[2], lv[3], lv[4], lv[5], lv[6], lv[7], lv[8])
            5 CloseHandle()
            功能釋放打開對象的句柄
            聲明格式FUNCTION boolean CloseHandle(ulong w_handle) LIBRARY "Kernel32.dll"
            示例 boolean rtn
            ulong l_handle
            rtn = CloseHandle(l_handle) //l_handle 為窗口或對象的句柄
            6 CloseWindow()
            功能最小化窗口
            聲明格式FUNCTION boolean CloseWindow(ulong w_handle) LIBRARY "User32.dll"
            示例 boolean rtn
            ulong l_handle
            string ls_wname
            ls_wname = "<窗口標題>" //請替換為要最小化的窗口的準確標題
            l_handle = FindWindowA(0, ls_wname) //由窗口標題找到窗口句柄
            rtn = CloseWindow(l_handle)
            7 DeleteFileA()
                
            附錄A 常用的776 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            776
            功能刪除文件
            聲明格式FUNCTION boolean DeleteFileA(ref string filename) LIBRARY "Kernel32.dll"
            示例 下例中用戶在單行編輯框中輸入一個文件名后代碼將該文件刪除
            string l_file
            boolean rtn
            l_file = string(sle_deletefile.text)
            rtn = DeleteFileA(l_file)
            MessageBox("刪除文件", string(rtn))
            8 DeleteMenu()
            功能刪除指定菜單的菜單項如果該菜單項下還有子菜單則函數刪除指向子菜單
            的句柄并釋放子菜單所占用的內存
            聲明格式FUNCTION boolean DeleteMenu(ulong mhand, uint upos, uint flag) LIBRARY
            "user32.dll"
            示例 ulong m_handle
            boolean rtn
            m_handle = GetSystemMenu(handle(w_main), false) // 首先得到系統菜單的句柄
            rtn = DeleteMenu(m_handle, 1, 0) // 第二個參數這里為1 指定要刪除菜
            //單項在菜單中的位置
            Messagebox("菜單句柄", string(m_handle))
            Messagebox("菜單刪除結果", string(rtn))
            9 DestroyWindow()
            功能關閉窗口該函數向指定窗口發送一條刪除窗口的消息
            聲明格式FUNCTION boolean DestroyWindow(ulong w_handle) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            ulong l_handle
            open(w_win2) // 打開一個測試窗口
            l_handle = handle(w_win2) //得到窗口的句柄
            rtn = DestroyWindow(l_handle) //關閉窗口
            10 DllRegisterServer()
            功能觸發OCX 控件完成自注冊過程實際使用時將聲明格式中ocxname 替換為
            真實的OCX 的名稱
            聲明格式FUNCTION long DllRegisterServer() LIBRARY "c:\windows\ocxname.ocx"
            示例 Long ll_rtn
            ll_rtn = DllRegisterServer() //通常返回0 表示OCX 已經注冊
            11 Ellipse()
            功能繪制橢圓
            聲明格式FUNCTION boolean Ellipse(ulong hwnd,long x1,long y1,long x2,long y2)
            LIBRARY "Gdi32.dll"
            示例 Boolean rtn
            ulong l_handle, l_device
            long lv[4]
                
            附錄A 常用的Windows API 調用 777
            附錄
            A
            常用的
            Windows API調用
            777
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            lv[ ] = {5,5,300,300}
            rtn = Ellipse(l_device, lv[1], lv[2], lv[3], lv[4])
            12 ExitWindowsEx()
            功能通知Windows 關閉操作系統
            聲明格式FUNCTION boolean ExitWindowsEx(uint dwReserved, uint uReserved)
            LIBRARY "User32.dll"
            示例 boolean rtn
            rtn = ExitWindowsEx(0,0) // 兩個參數0 告訴Windows 立即關閉系統
            13 FatalExit()
            功能立即退出應用程序不做任何清理工作各種對象依然保留在內存中調用該
            函數時通常會導致GPF 錯誤一般在調試應用程序時使用
            聲明格式SUBROUTINE FatalExit(int exitcode) LIBRARY "Kernel32.dll"
            示例 int rtn
            rtn = MessageBox("該API 調用將產生GPF 錯誤!","一定要做嗎", Exclamation!, YesNo!,2)
            If rtn = 1 Then
            MessageBox("再次警告!","執行該API 調用后必須重新啟動系統")
            FatalExit(1)
            End If
            14 FindWindowA()
            功能根據窗口標題查找窗口
            聲明格式FUNCTION ulong FindWindowA(ulong classname,string windowname)
            LIBRARY "User32.dll"
            示例 ulong l_handle
            string ls_wname
            ls_wname = "<窗口標題>" //比如無標題 - 記事本
            l_handle = FindWindowA(0, ls_wname)
            15 FreeLibrary()
            功能從活動內存中卸載一個DLL 警告卸載正在使用的DLL 時將引發GPF
            聲明格式SUBROUTINE FreeLibrary(ulong libhandle) LIBRARY "Kernel32.dll"
            示例 ulong modhandle
            modhandle = LoadLibrary("<32 位dll 文件名>") //通常在另一個事件過程中加載庫
            FreeLibrary(modhandle)
            16 GetBkColor()
            功能得到指定窗口的背景顏色
            聲明格式FUNCTION ulong GetBkColor (ulong hwnd) LIBRARY "Gdi32.dll"
            示例 ulong l_handle, l_device, l_color
            l_handle = handle(w_main)
            l_device = GetDC(l_handle) //得到設備上下文
            l_color = GetBkColor(l_device) //得到背景顏色
            17 GetCapture()
                
            附錄A 常用的778 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            778
            功能得到鼠標所在窗口的句柄
            聲明格式FUNCTION ulong GetCapture( ) LIBRARY "User32.dll"
            示例 ulong l_handle
            l_handle = GetCapture( )
            18 GetComputerNameA()
            功能得到執行應用程序的計算機的名稱需要注意的是名稱參數cname 必須分配
            足夠的內存否則在退出應用程序時可能會引發GPF 錯誤實際上所有外部函數的引用
            類參數都必須分配足夠的內存
            聲明格式FUNCTION boolean GetComputerNameA(ref string cname,ref long nbuf)
            LIBRARY "Kernel32.dll"
            示例 string ls_compname
            long ll_buf
            ll_buf = 25 //設置cname 參數的長度
            ls_compname = space(ll_buf) //為ls_compname 參數分配空間
            GetComputerNameA(ls_compname, ll_buf)
            MessageBox("計算機名稱", ls_compname)
            19 GetClassNameA()
            功能得到指定窗口或對象的類名
            聲明格式Function long GetClassNameA(ulong hwnd, ref string cname, int buf) Library
            "User32.dll"
            示例 string l_class
            long rtn
            ulong l_handle
            l_handle = handle(w_main)
            l_class = space(50)
            rtn = GetClassNameA(l_handle,l_class,50)
            Messagebox("類名", l_class)
            20 GetCurrentDirectoryA()
            功能得到當前工作目錄
            聲明格式FUNCTION ulong GetCurrentDirectoryA(ulong BufferLen, ref string currentdir)
            LIBRARY "Kernel32.dll"
            示例 string ls_curdir
            ulong l_buf
            l_buf = 100
            ls_curdir = space(l_buf) //為參數分配空間
            GetCurrentDirectoryA(l_buf, ls_curdir)
            MessageBox("當前目錄", ls_curdir)
            21 GetCurrentThread()
            功能得到當前線程的句柄
            聲明格式FUNCTION ulong GetCurrentThread() LIBRARY "Kernel32.dll"
            示例 ulong rtn
            rtn = GetCurrentThread()
                
            附錄A 常用的Windows API 調用 779
            附錄
            A
            常用的
            Windows API調用
            779
            MessageBox("當前線程句柄", string(rtn))
            22 GetCursor()
            功能得到光標的句柄
            聲明格式FUNCTION ulong GetCursor( ) LIBRARY "User32.dll8
            示例 ulong l_cursor
            l_cursor = GetCursor( )
            23 GetCursorPos()
            功能得到光標的位置參數mousepos 是一個結構它包括兩個分量long xpos, long
            ypos
            聲明格式FUNCTION boolean GetCursorPos(ref mousepos) LIBRARY "User32.dll"
            示例 mousepos mouseloc
            GetCursorPos(mouseloc)
            Messagebox("光標位置", "X="+string(mouseloc.xpos)+"Y="+string(mouseloc.ypos))
            24 GetDC()
            功能得到指定窗口的設備上下文如果想執行圖形外部函數調用必須得到設備上
            下文
            聲明格式Function ulong GetDC(ulong hwnd) library "user32.dll"
            示例 ulong l_handle, l_device
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            MessageBox("設備上下文", string(l_device))
            25 GetKeyboardState()
            功能得到鍵盤的狀態該函數按照字符的ASCII 碼表示將鍵盤上每個鍵的狀態保
            存到包含256 個整數元素的數組中值0 表示相應鍵沒有被按下
            聲明格式FUNCTION boolean GetKeyboardState(ref integer kbarray[256]) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            integer ipkey[256]
            rtn = GetKeyboardState(ipkey)
            26 GetKeyState()
            功能得到鍵盤上指定按鍵的狀態值0 表示相應鍵沒有被按下
            聲明格式Function int GetKeyState(integer VirtualKeycode) Library "User32.dll"
            示例 int rtn
            rtn = GetKeyState(65) // 65 = A
            if rtn = 0 then
            MessageBox("按鍵狀態","字母A 沒有按下")
            else
            MessageBox("按鍵狀態","字母A 被按下")
            end if
            27 GetModuleHandleA()
            功能得到活動內存中指定模塊或動態鏈接庫的句柄可以使用FreeLibrary()函數釋
                
            附錄A 常用的780 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            780
            放該函數得到其句柄的模塊或動態鏈接庫
            聲明格式Function long GetModuleHandleA(string modname) Library "Kernel32.dll"
            示例 ulong rtn
            rtn = GetModuleHandleA("User32.dll")
            MessageBox("返回代碼", string(rtn))
            28 GetPixel()
            功能得到窗口上指定像素的顏色
            聲明格式FUNCTION ulong GetPixel(ulong hwnd, long xpos, long ypos) LIBRARY
            "Gdi32.dll"
            示例 請參看SetPixel()函數
            29 GetSystemMenu()
            功能得到系統菜單或窗口菜單的句柄
            聲明格式FUNCTION boolean GetSystemMenu(ulong mhandle, boolean flag) LIBRARY
            "user32.dll"
            示例 boolean flag
            ulong l_handle, m_handle
            l_handle = handle(w_main)
            flag = false
            m_handle = GetSystemMenu(l_handle, flag)
            Messagebox("返回值", string(m_handle))
            30 GetSystemTime()
            功能得到系統時間并存放到一個結構中SystemTime 結構的分量為uint year
            uint month uint dayofweek uint day uint hour uint minute uint second uint millisecond
            聲明格式SUBROUTINE GetSystemTime(ref systemtime systimeptr) Library
            "Kernel32.dll"
            示例 systemtime s_systime
            string l_day, l_date, l_time
            GetSystemTime(s_systime)
            l_date = string(s_systime.year) +"/"+ string(s_systime.day) &
            +"/"+string(s_systime.month) //日期年/月/日
            l_time = string(s_systime.hour) +":"+ string(s_systime.minute) &
            +":"+ string(s_systime.second) +":"+ string(s_systime.millisecond) //時分秒毫秒
            CHOOSE CASE s_systime.dayofweek
            CASE 1
            l_day = "星期日"
            CASE 2
            l_day = "星期一"
            CASE 3
            l_day = "星期二"
            CASE 4
            l_day = "星期三"
            CASE 5
            l_day = "星期四"
                
            附錄A 常用的Windows API 調用 781
            附錄
            A
            常用的
            Windows API調用
            781
            CASE 6
            l_day = "星期五"
            CASE 7
            l_day = "星期六"
            END CHOOSE
            Messagebox("系統時間",l_date + " " + l_day + " " + l_time)
            31 GetThreadPriority()
            功能得到指定線程的優先級線程的缺省優先級為0 大于0 的值優先級更高因
            而線程將得到更多的CPU 時間
            聲明格式FUNCTION int GetThreadPriority(ulong hthread) LIBRARY "Kernel32.dll"
            示例 ulong l_handle
            integer rtn
            l_handle = GetCurrentThread()
            rtn = GetThreadPriority(l_handle)
            MessageBox("當前線程的優先級", string(rtn))
            32 GetSystemMetrics()
            功能得到屏幕的解析度以像素為單位請注意該函數區分大小寫函數名稱要
            嚴格按照書上的式樣書寫
            聲明格式FUNCTION int GetSystemMetrics(int indexnum) LIBRARY "user32.dll"
            示例 int l_xx, l_yy
            l_xx = GetSystemMetrics(0) //得到X 方向解析度
            l_yy = GetSystemMetrics(1) //得到Y 方向解析度
            Messagebox("屏幕解析度", string(l_xx) + " , " + string(l_yy))
            33 GetUserNameA()
            功能得到當前用戶的登錄名稱
            聲明格式FUNCTION boolean GetUserNameA(ref string uname, ref ulong slength)
            LIBRARY "ADVAPI32.DLL"
            示例 string ls_username
            string ls_var
            ulong lu_val
            boolean rtn
            lu_val = 255
            ls_username = Space( 255 ) //分配足夠的空間
            rtn = GetUserNameA(ls_username, lu_val)
            Messagebox("GetUserNameA", "用戶名為" + string(ls_username))
            34 GetVolumnInformationA()
            功能得到硬盤的參數信息
            聲明格式FUNCTION boolean GetVolumeInformation(ref string lpRootPathName,ref
            string lpVolumeNameBuffer,ulong nVolumeNameSize,ref ulong lpVolumeSerialNumber,ref
            ulong lpMaximumComponentLength,ref ulong lpFileSystemFlags,ref string
            lpFileSystemNameBuffer, ulong nFileSystemNameSize) Library "kernel32.dll"
            示例 boolean rtn
                
            附錄A 常用的782 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            782
            string lprootpathname = "c:" //驅動器
            string lpVolumeNameBuffer = space(256) //分配足夠的空間
            ulong nVolumeNameSize = 256
            ulong lpVolumeSerialNumber
            ulong lpMaximumComponentLength
            setnull(lpVolumeSerialNumber)
            lpMaximumComponentLength = 256
            ulong lpFileSystemFlags
            setnull(lpFileSystemFlags)
            string lpFileSystemNameBuffer = space(256) //分配足夠的空間
            ulong nFileSystemNameSize = 256
            rtn = GetVolumeInformationA(lpRootPathName, lpVolumeNameBuffer, &
            nVolumeNameSize,lpVolumeSerialNumber, lpMaximumComponentLength, &
            lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize)
            sle_1.text = lprootpathname //路徑名
            sle_2.text = lpVolumeNameBuffer
            sle_3.text = string(nVolumeNameSize)
            sle_4.text = string(lpVolumeSerialNumber)
            sle_5.text = string(lpMaximumComponentLength)
            sle_6.text = string(lpFileSystemFlags)
            sle_7.text = string(lpFileSystemNameBuffer)
            sle_8.text = string(nFileSystemNameSize)
            35 GetWindowsDirectoryA()
            功能得到缺省的Windows 目錄
            聲明格式FUNCTION ulong GetWindowsDirectoryA(ref string wdir, ulong buf)
            LIBRARY "kernel32.dll"
            示例 ulong l_buf
            string windir
            l_buf = 144
            windir = space(144)
            GetWindowsDirectoryA(windir, l_buf)
            MessageBox("當前目錄", windir)
            36 GlobalMemoryStatus()
            功能得到內存的詳細信息該函數使用的Memory 結構包括下述分量ulong m_length
            ulong m_loaded ulong m_totalphys ulong m_availphys ulong m_totalpagefile ulong
            m_availpagefile ulong m_totalvirtual ulong m_availvirtual
            聲明格式SUBROUTINE GlobalMemoryStatus(ref memory mem2) LIBRARY
            "Kernel32.dll"
            示例 memory sysmem
            GlobalMemoryStatus(sysmem)
            Messagebox("內存大小", string(sysmem.m_length))
            Messagebox("已加載內存", string(sysmem.m_loaded))
            Messagebox("總的物理內存", string(sysmem.m_totalphys))
            Messagebox("總的可用內存", string(sysmem.m_availphys))
                
            附錄A 常用的Windows API 調用 783
            附錄
            A
            常用的
            Windows API調用
            783
            Messagebox("總的頁面數", string(sysmem.m_totalpagefile))
            Messagebox("可用頁面數", string(sysmem.m_availpagefile))
            Messagebox("總的虛擬內存", string(sysmem.m_totalvirtual))
            Messagebox("可用虛擬內存", string(sysmem.m_availvirtual))
            37 LineTo()
            功能從當前位置到指定位置繪制一條直線
            聲明格式FUNCTION boolean LineTo(ulong hwnd,long wx, long wy) LIBRARY
            "Gdi32.dll"
            示例 請參看MoveToEx()函數
            38 LoadLibraryA()
            功能將32 位DLL 加載到活動內存中
            聲明格式FUNCTION ulong LoadLibraryA(string modname) LIBRARY "Kernel32.dll"
            示例 ulong modhandle
            //當DLL 庫在DOS 搜索路徑上時可以不指定路徑
            modhandle = LoadLibraryA("c:\windows\mydll.dll")
            If modhandle > 0 Then
            MessageBox("返回值", "加載成功句柄 = " + string(modhandle))
            else
            MessageBox("函數執行結果","不能加載指定模塊")
            end if
            39 mciSendStringA()
            功能控制和播放.AVI 文件
            聲明格式FUNCTION long mciSendStringA(string cmd, REF string rtn, long size, long
            wnd) LIBRARY "winmm.dll"
            示例 string s_errortext
            string filename
            filename ="c:\spin.avi"
            mciSendStringA ("open "+Filename+" type AVIVideo alias test wait",s_errortext, 0,0)
            mciSendStringA ("Window test handle " + string(handle(w_main)) + " wait",s_errortext, 0, 0)
            mciSendStringA ("Put test destination wait",s_errortext, 0, 0)
            mciSendStringA ("Play test wait", s_errortext, 0, 0)
            mciSendStringA ("Close test", s_errortext, 0, 0)
            40 MessageBoxA()
            功能顯示一個消息對話框
            聲明格式FUNCTION long MessageBoxA(ulong hwnd, ref string text, ref string title,
            ulong style) LIBRARY "User32.dll"
            示例 long rtn
            ulong handle1, style1
            string text1
            string title1
            handle1 = handle(parent)
            text1 = "這是一個API Messagebox"
            title1 = "API MessageBox"
                
            附錄A 常用的784 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            784
            style1 = 0
            rtn = MessageBoxA(handle1,text1,title1,style1)
            41 Mouse_Event()
            功能控制和操作鼠標該函數能夠移動鼠標指針按下鼠標按鈕并且能夠完成用
            戶使用鼠標能夠完成的一切任務下面的示例將鼠標指針左移100 個像素上移70 個像素
            聲明格式SUBROUTINE Mouse_Event(ulong dwflag,ulong dx,ulong dy,ulong
            cbutton,ulong dwextra) LIBRARY "User32.dll"
            示例 int lflag
            lflag = 1 //1 = 移動鼠標指針, 7 = 按下左按鈕, 25 = 按下右按鈕
            mouse_event(lflag,-80,-50,0,0)
            42 MoveToEx()
            功能將光標移動到指定位置同時保存移動前的光標位置函數使用的prepos 結構
            包含下述分量long xpos, long ypos
            聲明格式FUNCTION boolean MoveToEx(ulong hwnd,long wx, long wy,ref prepos
            prepos2) LIBRARY "Gdi32.dll"
            示例 ulong l_handle, l_device
            prepos previouspos //用于保存光標移動前的位置
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            MoveToEx(l_device,200,200,previouspos) //將光標移動到200,200 處
            LineTo(l_device,300,300) //在當前位置和300,300 之間畫一條直線
            43 MoveWindow()
            功能移動放大或縮小窗口
            聲明格式FUNCTION boolean MoveWindow(ulong whand,int wx,int wy,int ww,int
            wh,boolean wflag) LIBRARY "user32.dll"
            示例 boolean rtn
            ulong l_handle, l_device
            l_handle = handle(w_main)
            //10-X 位置20-Y 位置100-寬度200-高度
            rtn = MoveWindow(l_handle,10,20,100,200,true)
            MessageBox("返回值",string(rtn))
            44 Pie()
            功能繪制餅圖
            聲明格式FUNCTION boolean Pie(ulong hwnd,long x1,long y1,long x2,long y2,long
            x3,long y3,long x4,long y4) LIBRARY "Gdi32.dll"
            示例 Boolean rtn
            ulong l_handle,l_device
            long lv[8]
            lv[ ] = {10,50,290,220,0,0,80,0}
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            rtn = Pie(l_device,lv[1],lv[2],lv[3],lv[4],lv[5],lv[6],lv[7],lv[8])
                
            附錄A 常用的Windows API 調用 785
            附錄
            A
            常用的
            Windows API調用
            785
            45 Polygon()
            功能繪制多邊形該函數使用的結構poly 包含下述分量long xpos[5], long ypos[5]
            數組的大小與多邊形邊的條數相關示例中邊的條數為5
            聲明格式FUNCTION boolean Polygon(hdc, ref struct poly poly2, int cnt) LIBRARY
            "Gdi32.dll"
            示例 ulong l_handle, l_device
            int pcnt
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            pcnt = 5
            poly poly3
            poly3.xpos[ ] = {50,100,150,200,250}
            poly3.ypos[ ] = {50,100,150,200,250}
            Polygon(l_device,poly3,pcnt)
            46 PostMessageA()
            功能向創建指定窗口的線索發送一條消息但不等待線索處理該消息
            聲明格式FUNCTION boolean PostMessageA(ulong hwndle,UINT wmsg,ulong
            wParam,ulong lParam) Library "User32.dll"
            示例 ulong l_handle
            boolean rtn
            l_handle = handle(w_main)
            // 61472 = 最小化窗口61488 = 最大化窗口61728 = 正常窗口
            rtn = PostMessageA(l_handle,274,61472,0)
            47 Rectangle()
            功能繪制矩形
            聲明格式FUNCTION boolean Rectangle(ulong hwnd,long x1,long y1,long x2,long y2)
            LIBRARY "Gdi32.dll"
            示例 Boolean rtn
            ulong l_handle,l_device
            long lv[4]
            lv[ ] = { 10,10,275,215} //矩形的四個頂點
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            rtn = Rectangle(l_device,lv[1],lv[2],lv[3],lv[4])
            48 ReleaseCapture()
            功能解鎖鼠標
            聲明格式FUNCTION boolean ReleaseCapture( ) LIBRARY "User32.dll"
            示例 請參看SetCapture()函數
            49 SendMessageA()
            功能向創建指定窗口的線索發送一條消息但等待線索處理該消息
            聲明格式FUNCTION long SendMessageA(ulong hwndle,UINT wmsg,ulong
            wParam,ulong lParam) Library "User32.dll"
                
            附錄A 常用的786 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            786
            示例 ulong l_handle
            long rtn
            l_handle = handle(w_main)
            rtn = SendMessageA(l_handle,274,61728,0)
            50 SetCapture()
            功能鎖定鼠標鼠標鎖定后使用ReleaseCapture()解鎖鼠標
            聲明格式FUNCTION ulong SetCapture(ulong a) LIBRARY "User32.dll"
            示例 boolean rtn
            ulong l_loop, u_test, u_long
            u_test = handle(parent)
            u_long = SetCapture(u_test) //鎖定鼠標
            SetPointer(SizeNWSE!)
            for l_loop = 1 to 150000 //循環等待
            next
            rtn = ReleaseCapture( ) //解鎖鼠標
            51 SetComputerNameA()
            功能修改計算機的名稱
            聲明格式FUNCTION boolean SetComputerNameA(ref string cname) LIBRARY
            "kernel32.dll"
            示例 boolean rtn
            string l_name
            l_name = "ZCF 計算機"
            rtn = SetComputerNameA(l_name)
            if rtn then
            MessageBox("計算機的名稱已經修改為ZCF 計算機", &
            "重新啟動計算機后該名稱發揮作用")
            else
            MessageBox("設置計算機名稱", "咳失敗了")
            end if
            52 SetCurrentDirectoryA()
            功能設置當前目錄
            聲明格式FUNCTION boolean SetCurrentDirectoryA(ref string cdir) LIBRARY
            "kernel32.dll"
            示例 boolean rtn
            string l_dir
            l_dir = "C:\My Documents"
            rtn = SetCurrentDirectoryA(l_dir)
            MessageBox("SetCurrentDirectory", string(rtn))
            53 SetCursorPos()
            功能設置光標的位置
            聲明格式FUNCTION boolean SetCursorPos(int cx, int cy) LIBRARY "User32.dll"
            示例 SetCursorPos(300,350)
            Messagebox("光標位置","X =" +string(mouseloc.xpos) + "Y =" &
                
            附錄A 常用的Windows API 調用 787
            附錄
            A
            常用的
            Windows API調用
            787
            + string(mouseloc.ypos))
            54 SetFocus()
            功能將輸入焦點設置到指定對象或窗口上.
            聲明格式SUBROUTINE SetFocus(long objhandle) LIBRARY "User32.dll"
            示例 SetFocus(handle(sle_1)) // handle 函數得到單行編輯框控件sle_1 的句柄
            55 SetKeyboardState()
            功能設置鍵盤的狀態值0 表示相應鍵沒有被按下
            聲明格式FUNCTION boolean SetKeyboardState(ref integer kbarray[256]) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            rtn = SetKeyboardState(ipkey)
            if rtn = false then
            Messagebox("操作失敗","加載鍵盤狀態時出錯")
            else
            Messagebox("操作成功","成功完成鍵盤狀態加載工作")
            end if
            56 SetPixel()
            功能設置窗口上指定像素的顏色
            聲明格式FUNCTION ulong SetPixel(ulong hwnd, long xpos, long ypos, ulong pcol)
            LIBRARY "Gdi32.dll"
            示例 long lx, ly
            ulong rtn
            ulong l_handle, l_device
            lx = 200
            ly = 200
            l_handle = handle(w_main)
            l_device = GetDC(l_handle) //得到設備上下文
            rtn = GetPixel(l_device, lx, ly) //得到指定位置的像素顏色
            MessageBox("顏色","位置x="+string(lx)+",y="+ string(ly)+"的顏色值="+ string(rtn))
            SetPixel(l_device, lx, ly, 0) //將指定位置像素的顏色設置為黑色0
            57 SetThreadPriority()
            功能設置線程的優先級線程的缺省優先級為0 大于0 的優先級擁有更高的優先
            權優先級越大得到的CPU 時間越多但是不應該把優先級設置得過大否則將導致
            鼠標停止工作
            聲明格式FUNCTION boolean SetThreadPriority(ulong hthread, int npriority) LIBRARY
            "Kernel32.dll"
            示例 ulong l_handle
            boolean rtn
            l_handle = GetCurrentThread() //得到當前的優先級
            rtn = SetThreadPriority(l_handle, 2) // 將線程的優先級設置為2
            MessageBox("將線程的當前優先級修改為", string(rtn))
            58 Sleep()
                
            附錄A 常用的788 Windows API 調用
            附錄
            A
            常用的
            Windows API調用
            788
            功能睡眠指定的時間該函數執行過程中系統將不重繪屏幕該函數的作用相當
            于在PowerBuilder 執行了一個For ... Next 循環
            聲明格式SUBROUTINE Sleep(ulong milli) LIBRARY "Kernel32.dll"
            示例 ulong l_delay
            l_delay = 5000 //5000 毫秒5 秒
            Sleep(l_delay) //睡眠5 秒鐘
            59 SndPlaySoundA()和WaveOutGetNumDevs()
            功能這兩個函數結合起來使用用于播放.WAV 格式的文件
            聲明格式FUNCTION boolean SndPlaySoundA(string wavfile, uint flag) LIBRARY
            "WINMM.DLL"
            FUNCTION uint WaveOutGetNumDevs() LIBRARY "WINMM.DLL"
            示例 uint lui_NumDevs, l_mode
            string ls_file
            l_mode = 0
            ls_file = string(c:\windows\media\chimes.wav)
            lui_NumDevs = WaveOutGetNumDevs()
            IF lui_NumDevs > 0 THEN
            SndPlaySoundA(ls_file, l_mode)
            END IF
            60 SwapMouseButton()
            功能交換鼠標的左右按鈕讓鼠標按鈕返回正常狀態時需要再次調用該函數
            聲明格式FUNCTION boolean SwapMouseButton(boolean var) LIBRARY "User32.dll"
            示例 boolean rtn, l_mouse
            rtn = SwapMouseButton(l_mouse)
            If l_mouse = true Then
            MessageBox("交換鼠標按鈕","左邊的按鈕發揮右按鈕的作用")
            Else
            MessageBox("交換鼠標按鈕","右邊的按鈕發揮左按鈕的作用")
            End If
            61 WinExec()
            功能運行指定的可執行文件
            聲明格式FUNCTION uint WinExec(ref string filename, uint wstyle) LIBRARY
            "kernel32.dll"
            示例 string ls_filename
            uint rtn, wstyle
            ls_filename = "c:\windows\calc.exe" //程序名稱
            wstyle = 1
            rtn = WinExec(ls_filename, wstyle) //運行指定程序
            Messagebox("返回值", string(rtn))
            久久这里都是精品| 狠狠综合久久综合88亚洲| 亚洲伊人久久成综合人影院| 99久久中文字幕| 久久亚洲私人国产精品vA| 中文字幕日本人妻久久久免费| 亚洲精品乱码久久久久久不卡| 亚洲精品97久久中文字幕无码| 国产精品一区二区久久精品无码| 久久国产精品成人免费| 免费精品99久久国产综合精品| 国产亚洲欧美成人久久片| 伊人久久大香线蕉精品| 国产亚洲精午夜久久久久久| 国产精品欧美久久久久无广告| 久久996热精品xxxx| 久久久精品国产亚洲成人满18免费网站 | 久久国产三级无码一区二区| 国产三级观看久久| 无码国内精品久久人妻麻豆按摩| 久久这里只有精品视频99| 久久人人爽人人爽人人爽| 久久综合狠狠综合久久综合88 | 国产99精品久久| 国产激情久久久久影院小草| 久久综合久久鬼色| 亚洲精品无码久久久久| 99麻豆久久久国产精品免费| 精品国产青草久久久久福利| 久久久久久亚洲精品影院| 国产成人久久精品激情| 99久久人人爽亚洲精品美女| 精品久久久久久久久免费影院| 亚洲精品乱码久久久久久蜜桃不卡 | 久久av无码专区亚洲av桃花岛| 99久久综合国产精品二区| 伊人久久大香线蕉综合Av| 97久久精品人人做人人爽| 狠狠色丁香久久婷婷综合| 久久成人精品| 97久久精品人妻人人搡人人玩|