




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、api 在 vb 中應(yīng)用之技巧集錦api 函數(shù)在 vb 中得到了充分的運(yùn)用,同時(shí)也讓無(wú)數(shù)vb 愛好者沉溺于其中。以下是筆者幾年來(lái)收集整理的幾十個(gè)api 函數(shù)在 vb 中應(yīng)用的實(shí)例,現(xiàn)在寫出來(lái)與大伙分享,希望能對(duì)大伙有所幫助。1、如何讓窗體總在最前面?*api 函數(shù)聲明declare function setwindowpos lib user32 ( byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, by
2、val wflags as long) as long 注釋:常量聲明private const swp_nosize = &h1 private const swp_nomove = &h2 private const hwnd_topmost = -1 private const hwnd_notopmost = -2 注釋:在某個(gè) form 里寫:setwindowpos me.hwnd,wnd_topmost,0,0,0,0, swp_nomove 注釋:或下面setwindowpos me.hwnd,wnd_topmost,0,0,0,0, swp_nosize 2、
3、使用 api 函數(shù) sendmessage ,獲得光標(biāo)所在行和列。sub getcaretpos(byval texthwnd&,lineno&,colno&) 注釋: texthwnd 為 textbox 的 hwnd 屬性值,lineno 為所在行數(shù), colno 為列數(shù)dim i&,j&,k& 注 釋 : 獲 取 起 始 位 置 到 光 標(biāo) 所 在 位 置 字 節(jié) 數(shù)i=sendmessage(texthwnd,&hb0&,0,0) j=i/216 注釋:確定所在行l(wèi)ineno=sendmessage(texthwnd,&a
4、mp;hc9&,j,0)+1 注釋:確定所在列k=sendmessage(texthwnd,&hbb&,-1,0) colno=j-k+1 end sub 3、如何以某種顏色填充某區(qū)域?*api 函數(shù)聲明private declare sub floodfill lib gdi32 _ (byval hdc as long, byval x as long, byval y as _ long, byval crcolor as long 注釋:設(shè) (fillx,filly) 為此區(qū)域內(nèi)任一點(diǎn)注釋: color 為某種顏色floodfill picture1.hdc,
5、fillx, filly,color 4、如何關(guān)閉計(jì)算機(jī)?*api 函數(shù)聲明declare function exitwindows lib user (byval dwreturncode as long, byval wreserved as integer) as integer 注釋:執(zhí)行dim dummy dummy=exitwindows(0,0) 5、如何獲取windows 目錄和 system目錄?注釋:復(fù)制以下代碼到一模塊中public declare function getwindowsdirectory lib kernel32 alias getwindowsdire
6、ctorya (byval lpbuffer as string, byval nsize as long) as long public declare function getsystemdirectory lib kernel32 alias getsystemdirectorya (byval lpbuffer as string, byval nsize as long) as long 注釋:在程序中調(diào)用dim windowsdirectory as string, systemdirectory as string, x as long windowsdirectory = sp
7、ace(255) systemdirectory = space(255) x = getwindowsdirectory(windowsdirectory, 255) x = getsystemdirectory(systemdirectory, 255) msgbox windows的 安 裝 目 錄 是 : + windowsdirectory+,系 統(tǒng) 目 錄 是 : + systemdirectory 6、如何建立簡(jiǎn)單的超級(jí)連接?*api 函數(shù)聲明private declare function shellexecute lib shell32.dll alias shellexec
8、ute a (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd a s long) as long 注釋:打開某個(gè)網(wǎng)址shellexecute 0, open, http:/, vbnullstring, vbnullstring, 3 注釋:給某個(gè)信箱發(fā)電子郵件shellexecute hwnd, open, mailto:14100659qq.com
9、, vbnullstring, vbnullstring, 0 7、如何得知textbox 中文字所有的行數(shù)?*api 函數(shù)聲明declare function sendmessage lib user32 alias sendmessagea (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long public const em_getlinecount = &hba 注釋:在程序中調(diào)用linecnt = sendmessage(ctl.hwnd, em_getline
10、count, 0, 0) 注釋: linecnt 即為此 textbox 的行數(shù)。8、如何設(shè)置listbox 的水平卷動(dòng)軸的寬度?*api 函數(shù)聲明const lb_sethorizontalextent = &h194 private declare function sendmessage lib user32 alias sendmessagea _ (byval hwnd as long, byval wmsg as long, byval wparam as long, _ lparam as any) as long 注釋:調(diào)用call sendmessage(list1.
11、hwnd, lb_sethorizontalextent, 400, byval 0&) 注釋:注意400 是以象素為單位,你可以根據(jù)情況自行設(shè)定。9、如何交換鼠標(biāo)按鍵?*api 函數(shù)聲明declare function swapmousebutton& lib user32 _ (byval bswap as long) 要交換鼠標(biāo)按鍵, 將 bswap 參數(shù)設(shè)置為true。 要恢復(fù)正常設(shè)置, 將 bswap 設(shè)置為 false。然后調(diào)用函數(shù)就可以交換和恢復(fù)鼠標(biāo)按鍵了。10、如何讓窗體的標(biāo)題條閃爍以引起用戶注意?在窗體中放一個(gè)timer 控件 timer1, 設(shè)置其 inte
12、val=200 *api 函數(shù)聲明private declare function flashwindow lib user32 (byval hwnd as long, byval binvert as long) as long 注釋:在窗體中寫下如下代碼: private sub timer1_timer() flashwindow me.hwnd, true end sub 11、怎樣找到鼠標(biāo)指針的xy 坐標(biāo)?*api 函數(shù)聲明type pointapi x as long y as long end type declare function getcursorpos lib use
13、r32 (lppoint as pointapi) as long 調(diào)用:getcursorpos z print z.x print z.y 12、怎樣獲得和改變雙擊鼠標(biāo)的時(shí)間間隔?獲得鼠標(biāo)雙擊間隔時(shí)間:public declare function getdoubleclicktime lib user32 alias _ getdoubleclicktime () as long 獲得鼠標(biāo)雙擊間隔時(shí)間:declare function setdoubleclicktime lib user32 alias setdoubleclicktime (byval wcount as long)
14、 as long 注釋:注意:這種改變將影響到整個(gè)操作系統(tǒng)以上兩個(gè)函數(shù)都可精確到毫秒級(jí)。13、在程序中如何打開和關(guān)閉光驅(qū)門?*api 函數(shù)聲明如下 : private declare function mcisendstring lib winmm.dll alias mcisendstringa (byval lpstrcommand as string, byval lpstrreturnstring as string, byval ureturnlength as long, byval hwndcallback as long) as long 注釋:調(diào)用時(shí)的代碼如下dim ret
15、as long dim retstr as string 注釋:打開光驅(qū)門ret = mcisendstring(set cdaudio door open, retstr, 0, 0) 注釋:關(guān)閉光驅(qū)門ret = mcisendstring(set cdaudio door closed, retstr, 0, 0) 14、如何獲得windows 啟動(dòng)方式 ? 在 form1 中加入一個(gè)commandbutton 、一個(gè) label 并加入如下代碼: private declare function getsystemmetrics lib user32 (byval nindex as l
16、ong) as long const sm_cleanboot = 67 private sub command1_click() select case getsystemmetrics(sm_cleanboot) case 1 label1 = 安全模式 . case 2 label1 = 支持網(wǎng)絡(luò)的安全模式. case else label1 = windows 運(yùn)行在普通模式. end select end sub 15、怎樣使ctrl-alt-delete無(wú)效?*api 函數(shù)聲明private declare function systemparametersinfo lib use
17、r32 alias systemparametersinfoa (byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long) as long 編寫如下函數(shù):sub disablectrlaltdelete(bdisabled as boolean) dim x as long x = systemparametersinfo(97, bdisabled, cstr(1), 0) end sub 使 ctrl-alt-delete無(wú)效:call disablectrlalt
18、delete(true) 恢復(fù) ctrl-alt-delete :call disablectrlaltdelete(false) 16、如何移動(dòng)沒有標(biāo)題欄的窗口?我們一般是用鼠標(biāo)按住窗口的標(biāo)題欄,然后移動(dòng)窗口,當(dāng)窗口沒有標(biāo)題欄時(shí),我們可以用下面的方法來(lái)移動(dòng)窗口:*api 函數(shù)聲明:declare function releasecapture lib user32 () as long declare function sendmessage lib user32 alias sendmessagea (byval hwnd as long, byval wmsg as long, byva
19、l wparam as long, lparam as any) as long public const htcaption = 2 public const wm_nclbuttondown = &ha1 在 form_mousedown 事件中:private sub form_mousedown(button as integer, shift as integer, x as single, y as single) releasecapture sendmessage hwnd, wm_nclbuttondown, htcaption,0& end sub 17、v
20、b 中如何使用延時(shí)函數(shù)?*api 函數(shù)聲明:declare sub sleep lib kernel32 (byval dwmilliseconds as long) 調(diào)用:注釋:延時(shí)1 秒call sleep(1000) 18、調(diào)用修改屏幕保護(hù)口令的窗口:private declare function pwdchangepassword lib mpr alias pwdchangepassworda (byval lpcregkeyname as string, byval hwnd as long, byval uireserved1 as long, byval uireserved
21、2 as long) as long 調(diào)用:call pwdchangepassword(scrsa ve, me.hwnd, 0, 0) 19、使 windows 開始屏幕保護(hù):*api 函數(shù)聲明private declare function sendmessage lib user32 alias sendmessagea (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long const wm_syscommand = &h112& cons
22、t sc_screensa ve = &hf140& 注釋:調(diào)用dim result as long result = sendmessage(form1.hwnd, wm_syscommand, sc_screensave, 0&) 20、如何改變windows 桌面背景?*api 函數(shù)聲明const spi_setdeskw allpaper = 20 const spif_updateinifile = &h1 declare function systemparametersinfo lib user32 alias systemparametersin
23、foa (byval uaction as long, byval uparam as long, byval lpvparam as any, byval fuwinini as long) as long 注釋:調(diào)用call systemparametersinfo(spi_setdeskwallpaper, 0, c:windowsclouds.bmp, spif_updateinifile) 21、怎樣確定系統(tǒng)是否安裝了聲卡?*api 函數(shù)聲明:declare function waveoutgetnumdevs lib winmm.dll alias waveoutgetnumdev
24、s () as long 代碼如下:dim i as integer i = waveoutgetnumdevs() if i 0 then msgbox 你的系統(tǒng)可以播放聲音。, vbinformation, 聲卡檢測(cè) else msgbox 你的系統(tǒng)不能播放聲音。, vbinformation, 聲卡檢測(cè) end if 22、如何找到cd-rom驅(qū)動(dòng)器的盤號(hào)?下面的函數(shù)將檢查你計(jì)算機(jī)所有的驅(qū)動(dòng)器看是否是cd-rom ,如果是就返回驅(qū)動(dòng)器號(hào),如果沒有就返回空字符public function getcdromdrive() as string dim ltype as long,i as i
25、nteger,tmpdrive as string,found as boolean on error goto errl for i = 0 to 25 tmpdrive = chr(65 + i) & : ltype = getdrivetype(tmpdrive) 注釋: win32 api 函數(shù)if (ltype = drive_cdrom) then 注釋: win32 api 常數(shù)found = true exit for end if next if not found then tmpdrive = bi_getcdromdrive = tmpdrive exit fu
26、nction errl: msgbox error$ end function 23、如何將文件放入回收站?*api函數(shù)聲明public type shfileopstruct hwnd as long wfunc as long pfrom as string pto as string fflags as integer fanyoperationsaborted as long hnamemappings as long lpszprogresstitle as long end type public declare function shfileoperation lib _ she
27、ll32.dll alias shfileoperationa (lpfileop as shfileopstruct) as long public const fo_delete = &h3 public const fof_allowundo = &h40 注釋:調(diào)用dim shop as shfileopstruct, strfile as string with shop .wfunc = fo_delete .pfrom = strfile + chr(0) .fflags = fof_allowundo end with 24、vb 中如何使用未安裝的字體?dec
28、lare function addfontresource lib gdi32 alias addfontresourcea (byval lpfilename as string) as long declare function removefontresource lib gdi32 alias removefontresourcea (byval lpfilename as string) as long 增加字體:dim lresult as long lresult = addfontresource(c:myappmyfont.ttf) 刪除字體:dim lresult as l
29、ong lresult = removefontresource(c:myappmyfont.ttf) / 如何用 vb 建立快捷方式private declare function fcreateshelllink lib stkit432.dll (byval lpstrfoldername as string, byval lpstrlinkname as string, byval lpstrlinkpath as string, byval lpstrlinkargs as string) as long sub command1_click() dim lreturn as lon
30、g 添加到桌面lreturn = fcreateshelllink(.desktop, shortcut to calculator, c:windowscalc.exe, ) 添加到程序組lreturn = fcreateshelllink(, shortcut to calculator, c:windowscalc.exe, ) 添加到啟動(dòng)組lreturn = fcreateshelllink(startup, shortcut to calculator, c:windowscalc.exe, ) end sub / 如何讓程序在windows 啟動(dòng)時(shí)自動(dòng)執(zhí)行?有以下二個(gè)方法:方法 1
31、: 直接將快捷方式放到啟動(dòng)群組中。方法 2: 在注冊(cè)檔hkey_local_machine 中找到以下機(jī)碼softwaremicrosoftwindowscurrentversionrun 新增一個(gè)字串值,包括二個(gè)部份1. 名稱部份:自己取名,可設(shè)定為ap 名稱。2. 資料部份:則是包含全路徑檔案名稱 及 執(zhí)行參數(shù) 例如:value name = notepad value data = c:windowsnotepad.exe / 在 textbox 中如何限制只能輸入數(shù)字?參考下列程序:sub text1_keypress(keyascii as integer) if keyascii
32、57 then keyascii = 0 end if end sub / 我希望textbox 中能不接受某些特定字符,例如#$% ,有沒有簡(jiǎn)單一點(diǎn)的寫法?方法有好幾種, 以下列舉二種:方法 1: 可以使用if 或 select case 一個(gè)個(gè)判斷 , 但如果不接受的字符多時(shí), 較麻煩 ! 方法 2: 將要剔除的字符統(tǒng)統(tǒng)放在一個(gè)字串中,只要一個(gè)if 判斷即可! 如下:private sub text1_keypress(keyascii as integer) dim stemplate as string stemplate = !#$%&*()_+-= 用來(lái)存放不接受的字符if
33、 instr(1, stemplate, chr(keyascii) 0 then keyascii = 0 end if end sub / 如何讓鼠標(biāo)進(jìn)入textbox 時(shí)自動(dòng)選定textbox 中之整串文字?這個(gè)自動(dòng)選定反白整串文字的動(dòng)作,會(huì)使得輸入的資料完全取代之前在textbox 中的所有字符。private sub text1_gotfocus() text1.selstart = 0 text1.sellength = len(text1) end sub / 如何檢查軟盤驅(qū)動(dòng)器里是否有軟盤?使用:dim flag as boolean flag = fun_floppydriv
34、e(a:) if flag = false then msgbox a: 驅(qū)沒有準(zhǔn)備好,請(qǐng)將磁盤插入驅(qū)動(dòng)器!, vbcritical - 函數(shù) :檢查軟驅(qū)中是否有盤的存在- private function fun_floppydrive(sdrive as string) as boolean on error resume next fun_floppydrive = dir(sdrive) end function / 如何彈出和關(guān)閉光驅(qū)托盤?option explicit private declare function mcisendstring lib winmm.dll alia
35、s mcisendstringa (byval lpstrcommand as string, byval lpstrreturnstring as string, byval ureturnlength as long, byval hwndcallback as long) as long private sub command1_click() mciexecute set cdaudio door open 彈出光驅(qū)label2.caption = 彈 出 end sub private sub command2_click() label2.caption = 關(guān) 閉 mciexec
36、ute set cdaudio door closed 合上光驅(qū)unload me end end sub / 如何讓你的程序在任務(wù)列表隱藏private declare function registerserviceprocess lib kernel32 (byval processid as long, byval serviceflags as long) as long private declare function getcurrentprocessid lib kernel32 () as long 請(qǐng)你試試ctrl+alt+del 是不是你的程序隱藏了private sub
37、 command1_click() i = registerserviceprocess(getcurrentprocessid, 1) end sub / 如何用程序控制滑鼠游標(biāo)(mouse cursor) 到指定位置?以下這個(gè)例子, 當(dāng) user 在 text1 中按下enter 鍵后, 滑鼠游標(biāo)會(huì)自動(dòng)移到command2 按鈕上方請(qǐng)?jiān)诼暶鲄^(qū)中加入以下聲明:16 位版本:( sub 無(wú)傳回值) declare sub setcursorpos lib user (byval x as integer, byval y as integer) 32 位版本:( function 有傳回值,
38、integer 改成long ) declare function setcursorpos lib user32 (byval x as long, byval y as long) as long 在 form1 中加入以下程序碼:private sub text1_keypress(keyascii as integer) if keyascii = 13 then x% = (form1.left + command2.left + command2.width / 2 + 60) / screen.twipsperpixelx y% = (form1.top + command2.t
39、op + command2.height / 2 + 360) / screen.twipsperpixely setcursorpos x%, y% end if end sub / 如何用鼠標(biāo)移動(dòng)沒有標(biāo)題的form,或移動(dòng)form 中的控制項(xiàng)?在聲明區(qū)中放入以下聲明:16 位版本:( sub 無(wú)返回值) private declare sub releasecapture lib user () private declare sub sendmessage lib user (byval hwnd as integer, byval wmsg as integer, byval wpar
40、am as integer, lparam as long) 32 位版本:( function 有返回值, integer 改成long ) private declare function releasecapture lib user32 () as long private declare function sendmessage lib user32 alias sendmessagea (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long 共用常數(shù):const wm
41、_syscommand = &h112 const sc_move = &hf012 若要移動(dòng)form ,程序碼如下:private sub form_mousedown(button as integer, shift as integer, x as single, y as single) dim i as long i = releasecapture i = sendmessage(form1.hwnd, wm_syscommand, sc_move, 0) end sub 以上功能也適用于用鼠標(biāo)在form 中移動(dòng)控制項(xiàng),程序碼如下:private sub comma
42、nd1_mousedown(button as integer, shift as integer, x as single, y as single) dim i as long i = releasecapture i = sendmessage(command1.hwnd, wm_syscommand, sc_move, 0) end sub /檢 查 文 件 是 否 存 在 ? function fileexists(filename as string) as integerdim i as integeron error resume nexti = len(dir$(filena
43、me)if err or i = 0 then fileexists = false else fileexists = trueend function/如何設(shè)置對(duì)vb 數(shù)據(jù)庫(kù)連接的動(dòng)態(tài)路徑我個(gè)人因?yàn)榻?jīng)常作一些數(shù)據(jù)庫(kù)方面的程序,對(duì)于程序間如何與數(shù)據(jù)庫(kù)進(jìn)行接口的問題之煩是深有體會(huì),因?yàn)?vb 在數(shù)據(jù)庫(kù)鏈接的時(shí)候,一般是靜態(tài),即數(shù)據(jù)庫(kù)存放的路徑是固定的, 如用 vb 的 data,adodc,dataenvironment 等到作數(shù)據(jù)庫(kù)鏈接時(shí),如果存放數(shù)據(jù)庫(kù)的路徑被改變的話,就會(huì)找不到路經(jīng),真是一個(gè)特別煩的事。筆者的解決方法是利用app.path 來(lái)解決這個(gè)問題。一、用 data 控件進(jìn)行數(shù)據(jù)庫(kù)
44、鏈接,可以這樣: 在 form_load() 過程中放入:private form_load()dim str as string 定義 str = app.pathif right(str, 1) thenstr = str + end ifdata1.databasename=str & 數(shù)據(jù)庫(kù)名 data1.recordsource=數(shù)據(jù)表名 data1.refreshsub end這幾句話的意為,打開當(dāng)前程序運(yùn)行的目錄下的數(shù)據(jù)庫(kù)。你只要保證你的數(shù)據(jù)庫(kù)在你程序所在的目錄之下就行了。二、利用adodc(ado data control) 進(jìn)行數(shù)據(jù)庫(kù)鏈接:private form_l
45、oad ()dim str as string 定義 str = app.pathif right(str, 1) thenstr = str + end ifstr = provider=microsoft.jet.oledb.3.51;persist security info=false;data source= & str & tsl.mdbadodc1.connectionstring = stradodc1.commandtype = adcmdtextadodc1.recordsource = select * from table3adodc1.refreshe
46、nd sub 三、利用dataenvironment進(jìn) 行 數(shù) 據(jù) 庫(kù) 鏈 接 可 在 過 程 中 放 入 : on error resume nextif dataenvironment1.rscommand1.state adstateclosed thendataenvironment1.rscommand1.close 如果打開,則關(guān)閉end ifi = inputbox(請(qǐng)輸入友人編號(hào) :, 輸入 )if i = then exit subdataenvironment1.connection1.open app.path & userdatabasetsl.mdbdatae
47、nvironment1.rscommand1.open select * from table3 where 編號(hào)= & i & set datareport2.datasource = dataenvironment1datareport2.datamember = command1datareport2.showend sub 四、利用ado(activex data objects)進(jìn)行編程:建立連接: dim conn as new adodb.connectiondim rs as new adodb.recordsetdim strstr = app.pathif
48、right(str, 1) thenstr = str + end ifstr = provider=microsoft.jet.oledb.3.51;persist security info=false;data source= & str & tsl.mdbconn.open strrs.cursorlocation=aduseclientrs.open 數(shù)據(jù)表名 ,conn,adopenkeyset.adlockpessimistic 用完之后關(guān)閉數(shù)據(jù)庫(kù):conn.closeset conn=nothing/如何讓用戶自行輸入方程式, 并計(jì)算其結(jié)果?假設(shè)我們要讓使用者在
49、“ 方程式 ” 欄位中自由輸入方程式,然后利用方程式進(jìn)行計(jì)算, 則引用 scriptcontrol 控件可以很方便地做到。( scriptcontrol 控件附屬于vb 6.0,如果安裝后沒有看到此一控件,可在光盤的commontoolsvbscript 目錄底下找此一控件,其 .文件名為msscript.ocx 。 ) 假設(shè)放在窗體上的scriptcontrol控件名稱為scriptcontrol1 ,則在 “ 計(jì)算 ” 按鈕的click事件中編寫如下代碼:dim statement as string statement = x= + text1.text + vbcrlf + _ y=
50、+ text2.text + vbcrlf + _ msgbox 計(jì)算結(jié)果= & y scriptcontrol1.executestatement( statement /如何讓一個(gè)app 永遠(yuǎn)保持在最上層( always on top )請(qǐng)?jiān)诼暶鲄^(qū)中加入以下聲明private declare function setwindowpos lib user32 (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy a
51、s long, byval wflags as long) as longconst swp_nomove = &h2 不更動(dòng)目前視窗位置const swp_nosize = &h1 不更動(dòng)目前視窗大小 const hwnd_topmost = -1 設(shè)定為最上層const hwnd_notopmost = -2 取消最上層設(shè)定 const flags = swp_nomove or swp_nosize將 app 視窗設(shè)定成永遠(yuǎn)保持在最上層setwindowpos me.hwnd, hwnd_topmost, 0, 0, 0, 0, flags 取消最上層設(shè)定setwindo
52、wpos me.hwnd, hwnd_notopmost, 0, 0, 0, 0, flags/我要如何在程序中開啟網(wǎng)頁(yè)?在聲明區(qū)中聲明如下(在.bas 檔中用public, 在form 中用private)private declare function shellexecute lib shell32.dll alias shellexecutea (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory
53、as string, byval nshowcmd as long) as long 在程序中 intranet:shellexecute me.hwnd, open, 主 機(jī) / 目 錄 , , , 5internet : shellexecute me.hwnd, open, , , , 5/vb可以產(chǎn)生四角形以外其他形狀的form 嗎?這個(gè)問題,您一定無(wú)法想像有多容易,您可以產(chǎn)生任何形狀的form,但必須借助createellipticrgn 及setwindowrgn 二 個(gè)api , 例 如 : private declare function createellipticrgn l
54、ib gdi32 (byval x1 as long, byval y1 as long, byval x2 as long, byval y2 as long) as longprivate declare function setwindowrgn lib user32 (byval hwnd as long, byval hrgn as long, byval bredraw as boolean) as longprivate sub form_load()dim lreturn as longme.showlreturn = setwindowrgn(hwnd, createelli
55、pticrgn(10, 10, 340, 150), true)end sub執(zhí)行結(jié)果圖片createellipticrgn 之四個(gè)參數(shù)說明如下: x1:橢圓中心點(diǎn)之x 軸位置,但以form 的實(shí) 邊界為限。 y1:橢圓中心點(diǎn)之y 軸位置,但以form 的實(shí) 邊界為限。x2:橢圓長(zhǎng)邊的長(zhǎng)度y2:橢圓短邊的長(zhǎng)度的/如何移除form 右上方之 x 按鈕?其實(shí)form 右上方之三個(gè)按鈕分別對(duì)應(yīng)到form 左上方控制盒(controlbox) 中的幾個(gè)選項(xiàng) (縮到最小/ 放到最大/ 關(guān)閉 ),而其中的最大化(maxbutton) 及最小化(minbutton) 都可以直接在form 的屬性中設(shè)定,但是
56、vb 并沒有提供設(shè)定x按鈕的功能!要達(dá)到這個(gè)功能,必須借助api :由于 x按鈕對(duì)應(yīng)到controlbox 的關(guān)閉選項(xiàng),所以我們只要移除系統(tǒng)menu ( 就是 controlbox) 的關(guān)閉選項(xiàng)即可! 您自己可以先看看您現(xiàn)在使用的browser 左上方的系統(tǒng)menu, 【關(guān)閉】選項(xiàng)是在第幾個(gè),不是第6 個(gè)!是第7 個(gè),分隔線也算一個(gè)!分隔線才是第6 個(gè)!當(dāng)我們移除了關(guān)閉選項(xiàng)之後,會(huì)留下一條很奇怪的分隔線,所以最好連分隔線也一并移除。而 menu 的 index 是從 0 開始,分隔線是第6 個(gè),所以index = 5。修正:為了讓程序碼在windows nt 也能運(yùn)作正常,將各integer
57、型態(tài)改成long。89.05.04抓取系統(tǒng)menu 的 hwndprivate declare function getsystemmenu lib user32 alias getsystemmenu (byval hwnd as long, byval brevert as long) as long移除系統(tǒng)menu 的apiprivate declare function removemenu lib user32 alias removemenu (byval hmenu as long, byval nposition as long, byval wflags as long) a
58、s long第一個(gè)參數(shù)是系統(tǒng)menu 的hwnd第二個(gè)參數(shù)是要移除選項(xiàng)的index/如何制作透明的表單(form) ?請(qǐng)?jiān)诼暶鲄^(qū)中放入以下聲明const gwl_exstyle = (-20)const ws_ex_transparent = &h20&const swp_framechanged = &h20const swp_nomove = &h2const swp_nosize = &h1const swp_showme = swp_framechanged or swp_nomove or swp_nosizeconst hwnd_notopm
59、ost = -2private declare function setwindowlong lib user32 alias setwindowlonga (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as longprivate declare function setwindowpos lib user32 (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as
60、 long, byval cy as long, byval wflags as long) as long在 form_load 使用的范例如下:private sub form_load()setwindowlong me.hwnd, gwl_exstyle, ws_ex_transparentsetwindowpos me.hwnd, hwnd_notopmost, 0&, 0&, 0&, 0&, swp_showmeme.refreshend sub/如何在menu 中加入 mm 的圖案?在模組中加入以下程序碼:declare function getmenu lib user32 (byval hwnd as long) as longdeclare function getsubmenu lib user32 (byval hmenu as long, byval npos as long) as longdeclare function getmenuitemid lib user32 (byval hmenu as long, byval npos as long) as longdeclare func
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 燃料整改報(bào)告范文
- 請(qǐng)求贊助報(bào)告范文
- 浙江國(guó)企招聘2024溫州市國(guó)有資本投資運(yùn)營(yíng)有限公司招聘3人筆試參考題庫(kù)附帶答案詳解
- 二零二五年度獨(dú)立財(cái)務(wù)顧問代理記賬免責(zé)條款
- 二零二五年度股權(quán)激勵(lì)與股東利益共享協(xié)議
- 二零二五年度藥房藥品質(zhì)量管理員聘用合同
- 二零二五年度鋁合金門窗工程綠色施工與材料供應(yīng)合同
- 2025年茶山茶葉品牌授權(quán)合作承包協(xié)議
- 2025年度集體合同簽訂前的準(zhǔn)備工作規(guī)范
- 2025年度物流企業(yè)貨車司機(jī)勞動(dòng)爭(zhēng)議處理與仲裁協(xié)議
- 2025年深圳市高三一模英語(yǔ)試卷答案詳解講評(píng)課件
- 2025年江西青年職業(yè)學(xué)院高職單招職業(yè)技能測(cè)試近5年常考版參考題庫(kù)含答案解析
- 全套教學(xué)課件《工程倫理學(xué)》
- 江蘇省建筑與裝飾工程計(jì)價(jià)定額(2014)電子表格版
- 2024年山東經(jīng)貿(mào)職業(yè)學(xué)院高職單招(英語(yǔ)/數(shù)學(xué)/語(yǔ)文)筆試歷年參考題庫(kù)含答案解析
- 清華大學(xué)考生自述
- 五年級(jí)下冊(cè)英語(yǔ)課件--Lesson--7《Arriving-in-Beijing-》|冀教版-(三起)-(共21張PPT)
- 武發(fā)[2004]13關(guān)于積極推進(jìn)“ 城中村”綜合改造工作的意見
- 體溫單(三測(cè)單)
- 2019福建省物業(yè)管理?xiàng)l例
- 江戶時(shí)代以后的戰(zhàn)國(guó)家族們
評(píng)論
0/150
提交評(píng)論