一、概述
在 vb 程式設計中有許多呼叫視窗和對話方塊的操作,但是 vb 自已內建的卻非常的少,這裡所說的"不常用"也就是說通過 api 函式來實現各類呼叫視窗的操作。
二、通過 api 函式呼叫視窗的實用技巧如下:
(1)開啟檔案的屬性視窗
圖1,是乙個檔案的屬性視窗,但是在vb中沒提供"開啟檔案屬性視窗"的函式,不過可以通過呼叫 api 函式"shellexecuteex "來完成。
module1.bas
注釋:宣告 api 函式
type shellexecuteinfo 注釋:這可以vb自代的api幫助中找到
cbsize as long
fmask as long
hwnd as long
lpverb as string
lpfile as string
lpparameters as string
lpdirectory as string
nshow as long
lpidlist as long
lpclass as string
hkeyclass as long
dwhotkey as long
hicon as long
hprocess as long
end type
public const see_mask_invokeidlist = &hc
public const see_mask_nocloseprocess = &h40
public const see_mask_flag_no_ui = &h400
declare function shellexecuteex lib "shell32.dll" alias _
"shellexecuteex" (sei as shellexecuteinfo) as long
注釋:定義子程式
public sub showprops(filename as string, ownerhwnd as long)
dim sei as shellexecuteinfo
dim r as long
with sei
.cbsize = len(sei)
.fmask = see_mask_nocloseprocess or _
see_mask_invokeidlist or see_mask_flag_no_ui
.hwnd = ownerhwnd
.lpverb = "properties"
.lpfile = filename
.lpparameters = vbnullchar
.lpdirectory = vbnullchar
.nshow = 0
.lpidlist = 0
end with
r = shellexecuteex(sei)
end sub
注釋:呼叫視窗
showprops "c:command.com", me.hwnd
(2)啟用檔案目錄對話視窗
圖2,是檔案目錄對話方塊,這個對話方塊在 vb 編中經常用到,可是 vb 卻沒有呼叫它的函式,只有通過下面 api 函式來完成相關操作。
宣告 api 函式
declare function shbrowseforfolder lib "shell32.dll" alias "shbrowseforfoldera" (lpbrowseinfo as browseinfo) as long 注釋:itemidlist
declare function shgetpathfromidlist lib "shell32.dll" alias "shgetpathfromidlista" (byval pidl as long, byval pszpath as string) as long
public type browseinfo
howner as long
pidlroot as long
pszdisplayname as string
lpsztitle as string
ulflags as long
lpfn as long
lparam as long
iimage as long
end type
注釋:定義子程式
sub browdir()
dim bi as browseinfo
dim pidl&, rtn&, path$, pos%
pidl& = shbrowseforfolder(bi)
path$ = space$(512)
rtn& = shgetpathfromidlist(byval pidl&, byval path$)
if rtn& then
pos% = instr(path$, chr$(0))
mypath = left(path$, pos - 1)
end if
end sub
注釋:呼叫該對話方塊
browdir 注釋:返回 mypath 的值就是所選的目錄
(3)如何呼叫系統的【查詢】、【替換】的對話方塊?
如圖3、圖4,大家在編寫記事本程式時,都會去編寫這兩個對話方塊的功能,其時 microsoft 提供了乙個控制項文件,就是 comdlg32.dll,它可以方便的呼叫這兩個對話方塊
注釋:宣告 type findreplace
private type findreplace
lstructsize as long
hwndowner as long
hinstance as long
flags as long
lpstrfindwhat as string
lpstrreplacewith as string
wfindwhatlen as integer
wreplacewithlen as integer
lcustdata as long
lpfnhook as long
lptemplatename as string
end type
注釋:呼叫 common dialog dll
private declare function findtext lib "comdlg32.dll" alias "findtexta" _
(pfindreplace as findreplace) as long
private declare function replacetext lib "comdlg32.dll" alias "replacetexta" _
(pfindreplace as findreplace) as long
dim frtext as findreplace
在表單中加入二個 command button,並命名為 cmdfind, cmdreplace,加入以下程式**:
private sub cmdfind_click()
findtext frtext 注釋:呼叫查詢對話方塊
end sub
private sub cmdreplace_click()
replacetext frtext 注釋:呼叫替換對話方塊
end sub
private sub form_load()
with frtext
.lpstrreplacewith = "replace text"
.lpstrfindwhat = "find text"
.wfindwhatlen = 9
.wreplacewithlen = 12
.hwndowner = me.hwnd
.lstructsize = lenb(frtext)
end with
end sub
(4)在程式中呼叫關閉windows對話方塊
這個對話方塊比較簡單只用一句話就搞定。
private declare function shshutdowndialog lib "shell32" alias "#60" (byval yourguess as long) as long
注釋:呼叫
shshutdowndialog 0
vc 對話方塊 圓角視窗
為了實現圓角的對話方塊視窗,這裡主要用兩個函式,createroundrectrgn,和setwindowrgn 程式先通過getwindowrgn函式得到視窗矩形,然後通過createroundrectrgn函式建立乙個圓角矩形,最後通過setwindowrgn函式改變視窗的形狀。具體操作如下 1...
selenium對話方塊視窗API
有些web應用程式有多個框架或多個視窗。webdriver支援使用 switchto 方法在命名視窗之間移動 1,switch to.frame 進入到指定的frame或ifrmae,操作完後,通常要用switch to.parent frame 退到父frmae 2,switch to.alert...
對話方塊的使用
1 對話方塊的特性 對話總是依賴父視窗 jframe 當父視窗關閉,對話方塊也被關閉,父視窗最小化,對話方塊隨之最小化。對話方塊分模態和非模態兩類。2 使用joptionpane建立對話方塊 通過該類的show dialog方法,如果是在jinternalframe中使用,用相應的showinter...