说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

通用对话框专辑(全) -VB资料

HTML文档下载 WORD文档下载 PDF文档下载
通用对话框专辑(全) -VB资料
使用API调用Winodws各种通用对话框(Common Diaglog)的方法(一)

1.文件属性对话框
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long '可选参数
lpClass As String '可选参数
hkeyClass As Long '可选参数
dwHotKey As Long '可选参数
hIcon As Long '可选参数
hProcess As Long '可选参数
End Type

Const SEE_MASK_INVOKEIDLIST = &HC
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400

Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" _
(SEI As SHELLEXECUTEINFO) As Long
Public Function ShowProperties(filename As String, OwnerhWnd As Long) As Long
'打开指定文件的属性对话框,如果返回值<=32则出错
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
.hInstApp = 0
.lpIDList = 0
End With
r = ShellExecuteEX(SEI)
ShowProperties = SEI.hInstApp
End Function

新建一个工程,添加一个按钮和名为Text1的文本框
把以下代码置入CommandbButton_Click 中
Dim r As Long
Dim fname As String
'从Text1 中获取文件名及路径
fname = (Text1)
r = ShowProperties(fname, Me.hwnd)
If r <= 32 Then MsgBox "Error"

2.使用Win95的关于对话框
Private Declare Function ShellAbout Lib "shell32.dll" _
Alias "ShellAboutA" (ByVal hwnd As Long, ByVal szApp As String, _
ByVal szOtherStuff As String, ByVal hIcon As Long) As Long
示例:
Dim x As Long
x = shellabout (Form1.hwnd, "Visual Basic 6.0", _
"Alp Studio MouseTracker Ver 1.0", Form1.icon)

2.调用"捕获打印机端口"对话框
Private Declare Function WNetConnectionDialog Lib "mpr.dll" _
(ByVal hwnd As Long, ByVal dwType As Long) As Long
示例:
Dim x As Long
x = WNetConnectionDialog(Me.hwnd, 2)

3.调用颜色对话框
Private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long

将以下代码置入某一事件中:
Dim cc As ChooseColor
Dim CustColor(16) As Long
cc.lStructSize = Len(cc)
cc.hwndOwner = Form1.hWnd
cc.hInstance = App.hInstance
cc.flags = 0
cc.lpCustColors = String$(16 * 4, 0)
Dim a
Dim x
Dim c1
Dim c2
Dim c3
Dim c4
a = ChooseColor(cc)
Cls
If (a) Then
MsgBox "Color chosen:" & Str$(cc.rgbResult)

For x = 1 To Len(cc.lpCustColors) Step 4
c1 = Asc(Mid$(cc.lpCustColors, x, 1))
c2 = Asc(Mid$(cc.lpCustColors, x + 1, 1))
c3 = Asc(Mid$(cc.lpCustColors, x + 2, 1))
c4 = Asc(Mid$(cc.lpCustColors, x + 3, 1))
CustColor(x / 4) = (c1) + (c2 * 256) + (c3 * 65536) + (c4 * 16777216)
MsgBox "Custom Color " & Int(x / 4) & " = " & CustColor(x / 4)
Next x
Else
MsgBox "Cancel was pressed"
End If

4.调用复制磁盘对话框
Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwnd As Long, ByVal Drive As Long, ByVal fmtID As Long, ByVal options As Long) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

示例:
向窗体中添加一个名为Drive1的DriveListBox,将以下代码置入某一事件中
Dim DriveLetter$, DriveNumber&, DriveType&
Dim RetVal&, RetFromMsg&
DriveLetter = UCase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - 65)
DriveType = GetDriveType(DriveLetter)
If DriveType = 2 Then 'Floppies, etc
RetVal = Shell("rundll32.exe diskcopy.dll,DiskCopyRunDll " _
& DriveNumber & "," & DriveNumber, 1) 'Notice space after
Else ' Just in case 'DiskCopyRunDll
RetFromMsg = MsgBox("Only floppies can" & vbCrLf & _
"be diskcopied!", 64, "DiskCopy Example")
End If

5.调用格式化软盘对话框
Private Declare Function SHFormatDrive Lib "shell32" (ByVal hwnd As Long, ByVal Drive As Long, ByVal fmtID As Long, ByVal options As Long) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
参数设置:
fmtID-
3.5" 5.25"
-------------------------
0 1.44M 1.2M
1 1.44M 1.2M
2 1.44M 1.2M
3 1.44M 360K
4 1.44M 1.2M
5 720K 1.2M
6 1.44M 1.2M
7 1.44M 1.2M
8 1.44M 1.2M
9 1.44M 1.2M

选项
0 快速
1 完全
2 只复制系统文件
3 只复制系统文件
4 快速
5 完全
6 只复制系统文件
7 只复制系统文件
8 快速
9 完全
示例:要求同上
Dim DriveLetter$, DriveNumber&, DriveType&
Dim RetVal&, RetFromMsg%
DriveLetter = UCase(Drive1.Drive)
DriveNumber = (Asc(DriveLetter) - 65) ' Change letter to Number: A=0
DriveType = GetDriveType(DriveLetter)
If DriveType = 2 Then 'Floppies, etc
RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
Else
RetFromMsg = MsgBox("This drive is NOT a removeable" & vbCrLf & _
"drive! Format this drive?", 276, "SHFormatDrive Example")
Select Case RetFromMsg
Case 6 'Yes
' UnComment to do it...
'RetVal = SHFormatDrive(Me.hwnd, DriveNumber, 0&, 0&)
Case 7 'No
' Do nothing
End Select
End If
-----------------------------------------------------------------------------
使用API调用Winodws各种通用对话框(Common Diaglog)的方法(二)

1.选择目录/文件夹对话框
将以下代码置于一模块中
Option Explicit
' 调用方式:: string = BrowseForFolders(Hwnd,TitleOfDialog)
' 例如:String1 = BrowseForFolders(Hwnd, "Select target folder...")
Public Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const MAX_PATH = 260
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
'初始化变量
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'调用 API
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If
'如果选择取消, sPath = ""
BrowseForFolder = sPath
End Function
2.调用"映射网络驱动器"对话框
Private/Public Declare Function WNetConnectionDialog Lib "mpr.dll" _
(ByVal hwnd As Long, ByVal dwType As Long) As Long
x% = WNetConnectionDialog(Me.hwnd, 1)
3.调用"打开文件"对话框
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
将以下代码置于某一事件中
Dim ofn As OPENFILENAME
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Form1.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "Rich Text Files (*.rtf)" + Chr$(0) + "*.rtf" + Chr$(0)
ofn.lpstrFile = Space$(254)
ofn.nMaxFile = 255
ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = curdir
ofn.lpstrTitle = "Our File Open Title"
ofn.flags = 0
Dim a
a = GetOpenFileName(ofn)
If (a) Then
MsgBox "File to Open: " + Trim$(ofn.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
4.调用"打印"对话框
Private Type PrintDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
hdc As Long
flags As Long
nFromPage As Integer
nToPage As Integer
nMinPage As Integer
nMaxPage As Integer
nCopies As Integer
hInstance As Long
lCustData As Long
lpfnPrintHook As Long
lpfnSetupHook As Long
lpPrintTemplateName As String
lpSetupTemplateName As String
hPrintTemplate As Long
hSetupTemplate As Long
End Type
Private Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PrintDlg) As Long
'将以下代码置于某一事件中
Dim tPrintDlg As PrintDlg
tPrintDlg.lStructSize = Len(tPrintDlg)
tPrintDlg.hwndOwner = Me.hwnd
tPrintDlg.hdc = hdc
tPrintDlg.flags = 0
tPrintDlg.nFromPage = 0
tPrintDlg.nToPage = 0
tPrintDlg.nMinPage = 0
tPrintDlg.nMaxPage = 0
tPrintDlg.nCopies = 1
tPrintDlg.hInstance = App.hInstance
lpPrintTemplateName = "Print Page"
Dim a
a = PrintDlg(tPrintDlg)
If a Then
lFromPage = tPrintDlg.nFromPage
lToPage = tPrintDlg.nToPage
lMin = tPrintDlg.nMinPage
lMax = tPrintDlg.nMaxPage
lCopies = tPrintDlg.nCopies
PrintMyPage 'Custom printing Subroutine
End If
Vungle工程副总裁Wayne Chan:移动视频广告的未来 友盟副总裁焦岳:2014移动互联网行业趋势&amp;大数据的行业价值与运营支持 联发科技创意实验室副总裁Marc Naddell:以小博大的可穿戴方案 用友软件股份有限公司高级副总裁谢志华:企业互联网移动化触手可及 【MDCC 2014】英雄会晚宴——厉兵秣马,再上征程 移动开发技术与平台峰会(上):流量优化、数据管理、IM、LBS与跨平台开发 【推广、盈利与投资论坛】探寻推广与盈利新趋势 【企业移动化论坛】翻山越岭,创新突围企业移动化 解读微信与开发者双赢的开放能力 2014年10月操作系统份额:Windows 8.1份额喜人,Linux跌惨了 智能硬件峰会(下):苹果、微信、小米带给移动医疗产品开发的启示 移动游戏峰会(下):从端游转型手游、如何做一款不一样的游戏 移动游戏峰会(上):小团队如何做出大制作、游戏防作弊攻防战 深圳微信开发者大会:拒绝概念 这次只谈“怎么做” AMD应邀出席HPC China 2014,重磅推出新一代Firepro-S系列高性能显卡 你就是主角,MDCC 2014交流对接活动回顾(组图) 解读最具O2O属性—哈根达斯微信企业号的成功之道 值得Java开发者参与贡献的十个开源项目 LokiJS:纯JavaScript实现的轻量级数据库 OpenStack第七次北京Meet Up:谈私有云现状 中国电信携手电商打造跨界O2O联盟 【MDCC 2014】移动开发技术与平台峰会(下):系统演进、应用数据泄露风险 惊喜太多 IntelliJ IDEA 14正式发布 欧派、南航、招行、哈根达斯等加盟 深圳微信大会第二批讲师议题公布 【MDCC】用友高级副总裁谢志华:企业移动化的变革与挑战 HTML5定稿了,为什么原生App世界将被颠覆 走苹果的路子!Jawbone推低端健身追踪设备 专访POWER 8编程挑战赛选手吴亮:集众家之长, 激发算法性能极限 微信沟通接口上线,开启移动应用与公众号的连接 【特惠最后1天】参加深圳微信开发者大会赠书及全套讲师讲义(附大会最新日程) 编码运行两不误!KZPlayground,Objective-C中的Playgrounds DOS程序后台运行问题? 高手请指教->多个Form间怎么互通消息? 菜问题....D3D的 谁知道怎么做oicq,分全部归他。 各位兄台:如何激活一个窗口! 我发送Microsoft.XMLHTTP怎样获得验证??? 高分相送:有没有能察看一个dll文件中包含哪些函数的工具??????? help!!!! 怎样发送Microsoft.XMLHTTP获得验证???????? 请问,ASP中,能使用类似VB中的“On Error GoTo XXXX”这样的语句吗? foxpro怎样倒入sql server? 我现在有foxpro的dbf文件?应该怎样做? 多谢 mediaplayer的问题。 告诉我tostring 函数什么用途我们感到阿!谢谢了一个初学者! 请问VB6如何才能认到access2000的数据库文件? 关于对象序列化问题 怎样让返回值为自定义结构? 怎么在对话框上面话线? 请解释一下跃点数 小问题一个,但是需要高手................. 我想把公司的网站改放到公司,该怎么办? ——如需要还有很多分送 请帮忙,我自己觉得问题很难(特急)!!!!!!!!!!!!!!!!!!!! 明天我哥结婚,我很开心啊!!! 我想把公司的网站改放到公司,该怎么办? ——如需要还有很多分送 关于存储过程和触发器的问题?(高分求助) WIN2000机器上ADSL,另一台linux下如何做ADSL的代理让局域网中机器上网! 为什么新生成一个session对象后,jsp page中的scope=session的bean会不正常? ★★oracle中ora-04031错误 请问:在安装MSSQL2000 时(因为公司的电脑是对等网的原因)我装完后出现以下错误: 我应该去东软吗? 请您帮我诊断一下! 如何共享已打开的设备 rs.open sql,conn,3,2参数含义? 我应该去东软吗?? 求救~~~~安装完WINXP,进入系统前会出现错误窗 怎么现在没法用search了? 一个菜鸟的问题,关于事件的加载 求救~~~安装完WINXP,进入系统前会出现错误窗 关于速度,效率,VB IIS ASP COM高手请进 我用extracticon将图标从exe文件中提取出来了,请问高手们,如何保存为ICO文件。 急急急,如何解决多窗口关联及激活问题!高分相送 请教一下,如何刷新ie浏览器,我用postmessage模拟按键F5,没成功,谢谢 怎么样把多个程序打包到一个文件中,然后怎么样释放出来!高分求答案(分两次给100分)! 为什么计算字段不能排序 我是新手,高手教教我吧!!! 如何激活oracle8.16的监听??? Domino Administrator 中的“配置”->“消息处理”->“网络域” C#究竟是什么东东?象C++还是象JAVA? 求dxdbtreeview 1.2 for d5 有人知道天津英业达吗? vb6如何结合DirectX编程? 帮忙“圣诞节快乐”和“平安夜幸福”写成英文. 皇后 皇太后 太后 太皇太后区别?或者说皇帝分别给她们叫什么的? 快乐的一天(300字) 请问这文章的读后感该怎么写“老计生”赞张宇敏等一批老同志为我省计生事业做出很大贡献,观之巍巍如对以山岳,给人坚实感,促人奋发.当他们即将离开计生协会位置时,特撰文赞之.我省各 皇上的母亲称“太后”,皇上的祖母称“太皇太后”,那太皇太后的母亲称什么啊? 哪个皇帝的女人最多? 爱牙护齿的名言 感想作文六百字以上 中国历史哪个皇帝干过的女人最多?连宫内带宫外的. 我要三篇(每篇至少150字)爱牙护齿日记!急(明天之前给我答复,明天之前一定要! 读后感作文? 中国历史上最迷 皇帝的女人北齐高纬宠冯小怜,北齐亡后,冯小怜嫁给了北周的一个五十多的老王爷,老王爷一生简朴,曾说,人不要贪财贪色,要修养自己.可收了冯小怜判若两人.冯小怜要算一个 古代怎么称呼日本 爱牙日的由来合爱牙日要干什么?不要太长 也别太短 读日寇侵略中国的文章有感最好是写日寇侵略沙家浜有感其他的嘛,也可以 请问日本古代怎样的女性才可以称为"姬"?是不是公主的意思?例如人称"战国三姐妹"的茶茶、阿初、阿江与,在婚前都被称作"姬样",但是她们仅仅是近江北部大名浅井长政的女儿,就算把她们看 爱牙日的起源 历史上有哪些皇帝只娶了一个女人? 日本在古代的称谓是? 皇上怎么称呼皇太后的亲姐姐 跟牙有关的作文 谁知道平安夜的英语怎么说? 想问问皇帝的奶奶是不是太皇太后啊?有几个问题:1,那皇帝怎么称呼她?皇奶奶?好像不是.2,皇帝的妃子怎么称呼她?3,她有没有权利命令皇帝做事情? 中华儿女报效祖国的文章的读后感~ 古代的时候,公主说怎么称呼自己?皇后的女儿,还有:公主说“我要去吃饭了”、“我要去睡觉了”怎么说要练成句子的. 《建设幸福的中国》读后感作文评语 关于中华儿女报效祖国的文章读后感 爱牙护齿日记 作文:《我是中国人》读后感 写中华儿女报效祖国的文章或书籍的读后感 写父爱的作文写一篇关于父爱的作文一定要是新的 中国古名著作文读后感600字以内,但不要太短.急! 求关于父爱、母爱和友爱的作文要600多字``不能太多``谢谢各位 父爱的作文怎么写 作文:写一件体现 “母爱”或“父爱” 的事这个时候我刚从医院回来,我还在伤心流眼泪,我的孩子摔了,我非常的心疼,他一周岁,才出了八颗牙,可就在刚才,一个不小心,太自从车里摔倒了地上, 作文快乐的一天600字 怎么写父爱的作文 体现父爱母爱的事的作文yao xie ju ji de shi要写具体的事情, 怎样保护牙齿我早晚都刷牙...可是现在还有5个蛀牙. 爱是什么 写父爱的作文 关于父爱或母爱的作文,专门写一件事 作文初三随想600字 电影观后感作文 关于爱的作文,通过一件事,写父爱或母爱 成长随想的作文.600字左右 电影《舟舟》观后感作文继续电影“《舟舟》观后感”的作文啊,600字左右速度 牙齿英文怎么说 中华经典诵读 读后感、体验、和感悟等……急 求英文王子和公主的个性网名 建国大业电影观后感作文 一段关于保护牙齿的英语作文,题目为“How to keep our teeth healthy".短文不少于50词. 父爱作文 400字 男生贾里新传(电影)观后感作文要联系生活实际 作文快乐的一天300字 父爱作文400字 皇帝的妈叫皇太后,他爸叫太上皇,他奶奶叫太皇太后,那他爷爷叫什么呀? 三年级作文“快乐的一天”300字左右 初一作文 关于父爱 400字或者500字的 护齿作文怎么写,明天接该交了 快乐的一天作文300字
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn