• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Windows 60個(gè)常用API

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

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





            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 是一個(gè)示例窗口
            l_device = GetDC(l_handle) //得到窗口的設(shè)備上下文
            lv[ ] = {10,40,300,220,0,0,180,0} //數(shù)組賦值
            rtn = Arc(l_device, lv[1], lv[2], lv[3], lv[4], lv[5], lv[6], lv[7], lv[8])
            2 Beep()
            功能讓計(jì)算機(jī)按指定的頻率和周期發(fā)聲
                
            附錄A 常用的Windows API 調(diào)用 775
            附錄
            A
            常用的
            Windows API調(diào)用
            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()
            功能繪制弦圖弦圖由橢圓的一部分和一個(gè)線段組成
            聲明格式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()
            功能釋放打開對(duì)象的句柄
            聲明格式FUNCTION boolean CloseHandle(ulong w_handle) LIBRARY "Kernel32.dll"
            示例 boolean rtn
            ulong l_handle
            rtn = CloseHandle(l_handle) //l_handle 為窗口或?qū)ο蟮木浔?br style="LINE-HEIGHT: 22px; FONT-FAMILY: 'comic sans ms', fantasy !important">6 CloseWindow()
            功能最小化窗口
            聲明格式FUNCTION boolean CloseWindow(ulong w_handle) LIBRARY "User32.dll"
            示例 boolean rtn
            ulong l_handle
            string ls_wname
            ls_wname = "<窗口標(biāo)題>" //請(qǐng)?zhí)鎿Q為要最小化的窗口的準(zhǔn)確標(biāo)題
            l_handle = FindWindowA(0, ls_wname) //由窗口標(biāo)題找到窗口句柄
            rtn = CloseWindow(l_handle)
            7 DeleteFileA()
                
            附錄A 常用的776 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            776
            功能刪除文件
            聲明格式FUNCTION boolean DeleteFileA(ref string filename) LIBRARY "Kernel32.dll"
            示例 下例中用戶在單行編輯框中輸入一個(gè)文件名后代碼將該文件刪除
            string l_file
            boolean rtn
            l_file = string(sle_deletefile.text)
            rtn = DeleteFileA(l_file)
            MessageBox("刪除文件", string(rtn))
            8 DeleteMenu()
            功能刪除指定菜單的菜單項(xiàng)如果該菜單項(xiàng)下還有子菜單則函數(shù)刪除指向子菜單
            的句柄并釋放子菜單所占用的內(nèi)存
            聲明格式FUNCTION boolean DeleteMenu(ulong mhand, uint upos, uint flag) LIBRARY
            "user32.dll"
            示例 ulong m_handle
            boolean rtn
            m_handle = GetSystemMenu(handle(w_main), false) // 首先得到系統(tǒng)菜單的句柄
            rtn = DeleteMenu(m_handle, 1, 0) // 第二個(gè)參數(shù)這里為1 指定要?jiǎng)h除菜
            //單項(xiàng)在菜單中的位置
            Messagebox("菜單句柄", string(m_handle))
            Messagebox("菜單刪除結(jié)果", string(rtn))
            9 DestroyWindow()
            功能關(guān)閉窗口該函數(shù)向指定窗口發(fā)送一條刪除窗口的消息
            聲明格式FUNCTION boolean DestroyWindow(ulong w_handle) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            ulong l_handle
            open(w_win2) // 打開一個(gè)測(cè)試窗口
            l_handle = handle(w_win2) //得到窗口的句柄
            rtn = DestroyWindow(l_handle) //關(guān)閉窗口
            10 DllRegisterServer()
            功能觸發(fā)OCX 控件完成自注冊(cè)過程實(shí)際使用時(shí)將聲明格式中ocxname 替換為
            真實(shí)的OCX 的名稱
            聲明格式FUNCTION long DllRegisterServer() LIBRARY "c:\windows\ocxname.ocx"
            示例 Long ll_rtn
            ll_rtn = DllRegisterServer() //通常返回0 表示OCX 已經(jīng)注冊(cè)
            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 調(diào)用 777
            附錄
            A
            常用的
            Windows API調(diào)用
            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 關(guān)閉操作系統(tǒng)
            聲明格式FUNCTION boolean ExitWindowsEx(uint dwReserved, uint uReserved)
            LIBRARY "User32.dll"
            示例 boolean rtn
            rtn = ExitWindowsEx(0,0) // 兩個(gè)參數(shù)0 告訴Windows 立即關(guān)閉系統(tǒng)
            13 FatalExit()
            功能立即退出應(yīng)用程序不做任何清理工作各種對(duì)象依然保留在內(nèi)存中調(diào)用該
            函數(shù)時(shí)通常會(huì)導(dǎo)致GPF 錯(cuò)誤一般在調(diào)試應(yīng)用程序時(shí)使用
            聲明格式SUBROUTINE FatalExit(int exitcode) LIBRARY "Kernel32.dll"
            示例 int rtn
            rtn = MessageBox("該API 調(diào)用將產(chǎn)生GPF 錯(cuò)誤!","一定要做嗎", Exclamation!, YesNo!,2)
            If rtn = 1 Then
            MessageBox("再次警告!","執(zhí)行該API 調(diào)用后必須重新啟動(dòng)系統(tǒng)")
            FatalExit(1)
            End If
            14 FindWindowA()
            功能根據(jù)窗口標(biāo)題查找窗口
            聲明格式FUNCTION ulong FindWindowA(ulong classname,string windowname)
            LIBRARY "User32.dll"
            示例 ulong l_handle
            string ls_wname
            ls_wname = "<窗口標(biāo)題>" //比如無標(biāo)題 - 記事本
            l_handle = FindWindowA(0, ls_wname)
            15 FreeLibrary()
            功能從活動(dòng)內(nèi)存中卸載一個(gè)DLL 警告卸載正在使用的DLL 時(shí)將引發(fā)GPF
            聲明格式SUBROUTINE FreeLibrary(ulong libhandle) LIBRARY "Kernel32.dll"
            示例 ulong modhandle
            modhandle = LoadLibrary("<32 位dll 文件名>") //通常在另一個(gè)事件過程中加載庫
            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) //得到設(shè)備上下文
            l_color = GetBkColor(l_device) //得到背景顏色
            17 GetCapture()
                
            附錄A 常用的778 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            778
            功能得到鼠標(biāo)所在窗口的句柄
            聲明格式FUNCTION ulong GetCapture( ) LIBRARY "User32.dll"
            示例 ulong l_handle
            l_handle = GetCapture( )
            18 GetComputerNameA()
            功能得到執(zhí)行應(yīng)用程序的計(jì)算機(jī)的名稱需要注意的是名稱參數(shù)cname 必須分配
            足夠的內(nèi)存否則在退出應(yīng)用程序時(shí)可能會(huì)引發(fā)GPF 錯(cuò)誤實(shí)際上所有外部函數(shù)的引用
            類參數(shù)都必須分配足夠的內(nèi)存
            聲明格式FUNCTION boolean GetComputerNameA(ref string cname,ref long nbuf)
            LIBRARY "Kernel32.dll"
            示例 string ls_compname
            long ll_buf
            ll_buf = 25 //設(shè)置cname 參數(shù)的長(zhǎng)度
            ls_compname = space(ll_buf) //為ls_compname 參數(shù)分配空間
            GetComputerNameA(ls_compname, ll_buf)
            MessageBox("計(jì)算機(jī)名稱", ls_compname)
            19 GetClassNameA()
            功能得到指定窗口或?qū)ο蟮念惷?br style="LINE-HEIGHT: 22px; FONT-FAMILY: 'comic sans ms', fantasy !important">聲明格式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()
            功能得到當(dāng)前工作目錄
            聲明格式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) //為參數(shù)分配空間
            GetCurrentDirectoryA(l_buf, ls_curdir)
            MessageBox("當(dāng)前目錄", ls_curdir)
            21 GetCurrentThread()
            功能得到當(dāng)前線程的句柄
            聲明格式FUNCTION ulong GetCurrentThread() LIBRARY "Kernel32.dll"
            示例 ulong rtn
            rtn = GetCurrentThread()
                
            附錄A 常用的Windows API 調(diào)用 779
            附錄
            A
            常用的
            Windows API調(diào)用
            779
            MessageBox("當(dāng)前線程句柄", string(rtn))
            22 GetCursor()
            功能得到光標(biāo)的句柄
            聲明格式FUNCTION ulong GetCursor( ) LIBRARY "User32.dll8
            示例 ulong l_cursor
            l_cursor = GetCursor( )
            23 GetCursorPos()
            功能得到光標(biāo)的位置參數(shù)mousepos 是一個(gè)結(jié)構(gòu)它包括兩個(gè)分量long xpos, long
            ypos
            聲明格式FUNCTION boolean GetCursorPos(ref mousepos) LIBRARY "User32.dll"
            示例 mousepos mouseloc
            GetCursorPos(mouseloc)
            Messagebox("光標(biāo)位置", "X="+string(mouseloc.xpos)+"Y="+string(mouseloc.ypos))
            24 GetDC()
            功能得到指定窗口的設(shè)備上下文如果想執(zhí)行圖形外部函數(shù)調(diào)用必須得到設(shè)備上
            下文
            聲明格式Function ulong GetDC(ulong hwnd) library "user32.dll"
            示例 ulong l_handle, l_device
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            MessageBox("設(shè)備上下文", string(l_device))
            25 GetKeyboardState()
            功能得到鍵盤的狀態(tài)該函數(shù)按照字符的ASCII 碼表示將鍵盤上每個(gè)鍵的狀態(tài)保
            存到包含256 個(gè)整數(shù)元素的數(shù)組中值0 表示相應(yīng)鍵沒有被按下
            聲明格式FUNCTION boolean GetKeyboardState(ref integer kbarray[256]) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            integer ipkey[256]
            rtn = GetKeyboardState(ipkey)
            26 GetKeyState()
            功能得到鍵盤上指定按鍵的狀態(tài)值0 表示相應(yīng)鍵沒有被按下
            聲明格式Function int GetKeyState(integer VirtualKeycode) Library "User32.dll"
            示例 int rtn
            rtn = GetKeyState(65) // 65 = A
            if rtn = 0 then
            MessageBox("按鍵狀態(tài)","字母A 沒有按下")
            else
            MessageBox("按鍵狀態(tài)","字母A 被按下")
            end if
            27 GetModuleHandleA()
            功能得到活動(dòng)內(nèi)存中指定模塊或動(dòng)態(tài)鏈接庫的句柄可以使用FreeLibrary()函數(shù)釋
                
            附錄A 常用的780 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            780
            放該函數(shù)得到其句柄的模塊或動(dòng)態(tài)鏈接庫
            聲明格式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"
            示例 請(qǐng)參看SetPixel()函數(shù)
            29 GetSystemMenu()
            功能得到系統(tǒng)菜單或窗口菜單的句柄
            聲明格式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()
            功能得到系統(tǒng)時(shí)間并存放到一個(gè)結(jié)構(gòu)中SystemTime 結(jié)構(gòu)的分量為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) //時(shí)分秒毫秒
            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 調(diào)用 781
            附錄
            A
            常用的
            Windows API調(diào)用
            781
            CASE 6
            l_day = "星期五"
            CASE 7
            l_day = "星期六"
            END CHOOSE
            Messagebox("系統(tǒng)時(shí)間",l_date + " " + l_day + " " + l_time)
            31 GetThreadPriority()
            功能得到指定線程的優(yōu)先級(jí)線程的缺省優(yōu)先級(jí)為0 大于0 的值優(yōu)先級(jí)更高因
            而線程將得到更多的CPU 時(shí)間
            聲明格式FUNCTION int GetThreadPriority(ulong hthread) LIBRARY "Kernel32.dll"
            示例 ulong l_handle
            integer rtn
            l_handle = GetCurrentThread()
            rtn = GetThreadPriority(l_handle)
            MessageBox("當(dāng)前線程的優(yōu)先級(jí)", string(rtn))
            32 GetSystemMetrics()
            功能得到屏幕的解析度以像素為單位請(qǐng)注意該函數(shù)區(qū)分大小寫函數(shù)名稱要
            嚴(yán)格按照書上的式樣書寫
            聲明格式FUNCTION int GetSystemMetrics(int indexnum) LIBRARY "user32.dll"
            示例 int l_xx, l_yy
            l_xx = GetSystemMetrics(0) //得到X 方向解析度
            l_yy = GetSystemMetrics(1) //得到Y(jié) 方向解析度
            Messagebox("屏幕解析度", string(l_xx) + " , " + string(l_yy))
            33 GetUserNameA()
            功能得到當(dāng)前用戶的登錄名稱
            聲明格式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()
            功能得到硬盤的參數(shù)信息
            聲明格式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 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            782
            string lprootpathname = "c:" //驅(qū)動(dòng)器
            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("當(dāng)前目錄", windir)
            36 GlobalMemoryStatus()
            功能得到內(nèi)存的詳細(xì)信息該函數(shù)使用的Memory 結(jié)構(gòu)包括下述分量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("內(nèi)存大小", string(sysmem.m_length))
            Messagebox("已加載內(nèi)存", string(sysmem.m_loaded))
            Messagebox("總的物理內(nèi)存", string(sysmem.m_totalphys))
            Messagebox("總的可用內(nèi)存", string(sysmem.m_availphys))
                
            附錄A 常用的Windows API 調(diào)用 783
            附錄
            A
            常用的
            Windows API調(diào)用
            783
            Messagebox("總的頁面數(shù)", string(sysmem.m_totalpagefile))
            Messagebox("可用頁面數(shù)", string(sysmem.m_availpagefile))
            Messagebox("總的虛擬內(nèi)存", string(sysmem.m_totalvirtual))
            Messagebox("可用虛擬內(nèi)存", string(sysmem.m_availvirtual))
            37 LineTo()
            功能從當(dāng)前位置到指定位置繪制一條直線
            聲明格式FUNCTION boolean LineTo(ulong hwnd,long wx, long wy) LIBRARY
            "Gdi32.dll"
            示例 請(qǐng)參看MoveToEx()函數(shù)
            38 LoadLibraryA()
            功能將32 位DLL 加載到活動(dòng)內(nèi)存中
            聲明格式FUNCTION ulong LoadLibraryA(string modname) LIBRARY "Kernel32.dll"
            示例 ulong modhandle
            //當(dāng)DLL 庫在DOS 搜索路徑上時(shí)可以不指定路徑
            modhandle = LoadLibraryA("c:\windows\mydll.dll")
            If modhandle > 0 Then
            MessageBox("返回值", "加載成功句柄 = " + string(modhandle))
            else
            MessageBox("函數(shù)執(zhí)行結(jié)果","不能加載指定模塊")
            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()
            功能顯示一個(gè)消息對(duì)話框
            聲明格式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 = "這是一個(gè)API Messagebox"
            title1 = "API MessageBox"
                
            附錄A 常用的784 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            784
            style1 = 0
            rtn = MessageBoxA(handle1,text1,title1,style1)
            41 Mouse_Event()
            功能控制和操作鼠標(biāo)該函數(shù)能夠移動(dòng)鼠標(biāo)指針按下鼠標(biāo)按鈕并且能夠完成用
            戶使用鼠標(biāo)能夠完成的一切任務(wù)下面的示例將鼠標(biāo)指針左移100 個(gè)像素上移70 個(gè)像素
            聲明格式SUBROUTINE Mouse_Event(ulong dwflag,ulong dx,ulong dy,ulong
            cbutton,ulong dwextra) LIBRARY "User32.dll"
            示例 int lflag
            lflag = 1 //1 = 移動(dòng)鼠標(biāo)指針, 7 = 按下左按鈕, 25 = 按下右按鈕
            mouse_event(lflag,-80,-50,0,0)
            42 MoveToEx()
            功能將光標(biāo)移動(dòng)到指定位置同時(shí)保存移動(dòng)前的光標(biāo)位置函數(shù)使用的prepos 結(jié)構(gòu)
            包含下述分量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 //用于保存光標(biāo)移動(dòng)前的位置
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            MoveToEx(l_device,200,200,previouspos) //將光標(biāo)移動(dòng)到200,200 處
            LineTo(l_device,300,300) //在當(dāng)前位置和300,300 之間畫一條直線
            43 MoveWindow()
            功能移動(dòng)放大或縮小窗口
            聲明格式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 調(diào)用 785
            附錄
            A
            常用的
            Windows API調(diào)用
            785
            45 Polygon()
            功能繪制多邊形該函數(shù)使用的結(jié)構(gòu)poly 包含下述分量long xpos[5], long ypos[5]
            數(shù)組的大小與多邊形邊的條數(shù)相關(guān)示例中邊的條數(shù)為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()
            功能向創(chuàng)建指定窗口的線索發(fā)送一條消息但不等待線索處理該消息
            聲明格式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} //矩形的四個(gè)頂點(diǎn)
            l_handle = handle(w_main)
            l_device = GetDC(l_handle)
            rtn = Rectangle(l_device,lv[1],lv[2],lv[3],lv[4])
            48 ReleaseCapture()
            功能解鎖鼠標(biāo)
            聲明格式FUNCTION boolean ReleaseCapture( ) LIBRARY "User32.dll"
            示例 請(qǐng)參看SetCapture()函數(shù)
            49 SendMessageA()
            功能向創(chuàng)建指定窗口的線索發(fā)送一條消息但等待線索處理該消息
            聲明格式FUNCTION long SendMessageA(ulong hwndle,UINT wmsg,ulong
            wParam,ulong lParam) Library "User32.dll"
                
            附錄A 常用的786 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            786
            示例 ulong l_handle
            long rtn
            l_handle = handle(w_main)
            rtn = SendMessageA(l_handle,274,61728,0)
            50 SetCapture()
            功能鎖定鼠標(biāo)鼠標(biāo)鎖定后使用ReleaseCapture()解鎖鼠標(biāo)
            聲明格式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) //鎖定鼠標(biāo)
            SetPointer(SizeNWSE!)
            for l_loop = 1 to 150000 //循環(huán)等待
            next
            rtn = ReleaseCapture( ) //解鎖鼠標(biāo)
            51 SetComputerNameA()
            功能修改計(jì)算機(jī)的名稱
            聲明格式FUNCTION boolean SetComputerNameA(ref string cname) LIBRARY
            "kernel32.dll"
            示例 boolean rtn
            string l_name
            l_name = "ZCF 計(jì)算機(jī)"
            rtn = SetComputerNameA(l_name)
            if rtn then
            MessageBox("計(jì)算機(jī)的名稱已經(jīng)修改為ZCF 計(jì)算機(jī)", &
            "重新啟動(dòng)計(jì)算機(jī)后該名稱發(fā)揮作用")
            else
            MessageBox("設(shè)置計(jì)算機(jī)名稱", "咳失敗了")
            end if
            52 SetCurrentDirectoryA()
            功能設(shè)置當(dāng)前目錄
            聲明格式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()
            功能設(shè)置光標(biāo)的位置
            聲明格式FUNCTION boolean SetCursorPos(int cx, int cy) LIBRARY "User32.dll"
            示例 SetCursorPos(300,350)
            Messagebox("光標(biāo)位置","X =" +string(mouseloc.xpos) + "Y =" &
                
            附錄A 常用的Windows API 調(diào)用 787
            附錄
            A
            常用的
            Windows API調(diào)用
            787
            + string(mouseloc.ypos))
            54 SetFocus()
            功能將輸入焦點(diǎn)設(shè)置到指定對(duì)象或窗口上.
            聲明格式SUBROUTINE SetFocus(long objhandle) LIBRARY "User32.dll"
            示例 SetFocus(handle(sle_1)) // handle 函數(shù)得到單行編輯框控件sle_1 的句柄
            55 SetKeyboardState()
            功能設(shè)置鍵盤的狀態(tài)值0 表示相應(yīng)鍵沒有被按下
            聲明格式FUNCTION boolean SetKeyboardState(ref integer kbarray[256]) LIBRARY
            "USER32.DLL"
            示例 boolean rtn
            rtn = SetKeyboardState(ipkey)
            if rtn = false then
            Messagebox("操作失敗","加載鍵盤狀態(tài)時(shí)出錯(cuò)")
            else
            Messagebox("操作成功","成功完成鍵盤狀態(tài)加載工作")
            end if
            56 SetPixel()
            功能設(shè)置窗口上指定像素的顏色
            聲明格式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) //得到設(shè)備上下文
            rtn = GetPixel(l_device, lx, ly) //得到指定位置的像素顏色
            MessageBox("顏色","位置x="+string(lx)+",y="+ string(ly)+"的顏色值="+ string(rtn))
            SetPixel(l_device, lx, ly, 0) //將指定位置像素的顏色設(shè)置為黑色0
            57 SetThreadPriority()
            功能設(shè)置線程的優(yōu)先級(jí)線程的缺省優(yōu)先級(jí)為0 大于0 的優(yōu)先級(jí)擁有更高的優(yōu)先
            權(quán)優(yōu)先級(jí)越大得到的CPU 時(shí)間越多但是不應(yīng)該把優(yōu)先級(jí)設(shè)置得過大否則將導(dǎo)致
            鼠標(biāo)停止工作
            聲明格式FUNCTION boolean SetThreadPriority(ulong hthread, int npriority) LIBRARY
            "Kernel32.dll"
            示例 ulong l_handle
            boolean rtn
            l_handle = GetCurrentThread() //得到當(dāng)前的優(yōu)先級(jí)
            rtn = SetThreadPriority(l_handle, 2) // 將線程的優(yōu)先級(jí)設(shè)置為2
            MessageBox("將線程的當(dāng)前優(yōu)先級(jí)修改為", string(rtn))
            58 Sleep()
                
            附錄A 常用的788 Windows API 調(diào)用
            附錄
            A
            常用的
            Windows API調(diào)用
            788
            功能睡眠指定的時(shí)間該函數(shù)執(zhí)行過程中系統(tǒng)將不重繪屏幕該函數(shù)的作用相當(dāng)
            于在PowerBuilder 執(zhí)行了一個(gè)For ... Next 循環(huán)
            聲明格式SUBROUTINE Sleep(ulong milli) LIBRARY "Kernel32.dll"
            示例 ulong l_delay
            l_delay = 5000 //5000 毫秒5 秒
            Sleep(l_delay) //睡眠5 秒鐘
            59 SndPlaySoundA()和WaveOutGetNumDevs()
            功能這兩個(gè)函數(shù)結(jié)合起來使用用于播放.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()
            功能交換鼠標(biāo)的左右按鈕讓鼠標(biāo)按鈕返回正常狀態(tài)時(shí)需要再次調(diào)用該函數(shù)
            聲明格式FUNCTION boolean SwapMouseButton(boolean var) LIBRARY "User32.dll"
            示例 boolean rtn, l_mouse
            rtn = SwapMouseButton(l_mouse)
            If l_mouse = true Then
            MessageBox("交換鼠標(biāo)按鈕","左邊的按鈕發(fā)揮右按鈕的作用")
            Else
            MessageBox("交換鼠標(biāo)按鈕","右邊的按鈕發(fā)揮左按鈕的作用")
            End If
            61 WinExec()
            功能運(yùn)行指定的可執(zhí)行文件
            聲明格式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) //運(yùn)行指定程序
            Messagebox("返回值", string(rtn))
            久久青青草原精品国产| 欧美黑人激情性久久| 国产精品禁18久久久夂久| 久久99精品国产麻豆宅宅| 久久久久久久亚洲精品 | 午夜精品久久久久久99热| 亚洲AV无码久久精品蜜桃| 99久久精品国产一区二区三区| 久久伊人五月天论坛| 久久精品九九亚洲精品天堂| 伊人久久五月天| 国产 亚洲 欧美 另类 久久| 久久精品亚洲一区二区三区浴池| 国产女人aaa级久久久级| 色综合久久无码中文字幕| 亚洲国产成人久久笫一页| 韩国无遮挡三级久久| 亚洲AV无码久久精品色欲| 久久久久99精品成人片三人毛片| 久久国产亚洲高清观看| 久久国内免费视频| 久久精品国产精品亚洲下载| 1000部精品久久久久久久久| 久久久久青草线蕉综合超碰| 久久青青草原精品国产软件| 欧美久久综合性欧美| 伊人久久综合成人网| 精品伊人久久久| 少妇无套内谢久久久久| 久久久久亚洲AV成人网| 精品久久久久久国产| 久久精品午夜一区二区福利 | 久久91精品国产91久久麻豆| 久久精品国产精品亚洲下载| 久久久精品一区二区三区| 久久久久亚洲AV片无码下载蜜桃 | a级毛片无码兔费真人久久| 久久99精品国产自在现线小黄鸭| 久久综合亚洲鲁鲁五月天| 久久人人爽人人爽人人片av麻烦| 亚洲精品成人久久久|