通用对话框专辑(全)

摘要:
通用对话框专辑(全)使用API调用Winodws各种通用对话框(CommonDiaglog)的方法(一)1.文件属性对话框TypeSHELLEXECUTEINFOcbSizeAsLongfMaskAsLonghwndAsLonglpVerbAsStringlpFileAsStringlpParametersAsStringlpDirectoryAsStringnShowAsLonghInstApp

通用对话框专辑(全)
使用API调用Winodws各种通用对话框(CommonDiaglog)的方法(一)
1.文件属性对话框

Type SHELLEXECUTEINFO
cbSize As LongfMask As Longhwnd As LonglpVerb As StringlpFile As StringlpParameters As StringlpDirectory As StringnShow As LonghInstApp As LonglpIDList As Long '可选参数
lpClass As String '可选参数
hkeyClass As Long '可选参数
dwHotKey As Long '可选参数
hIcon As Long '可选参数
hProcess As Long '可选参数
EndType

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 AsSHELLEXECUTEINFO
Dim r As Long
WithSEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST OrSEE_MASK_FLAG_NO_UI
.hwnd =OwnerhWnd
.lpVerb = "properties".lpFile =filename
.lpParameters =vbNullChar
.lpDirectory =vbNullChar
.nShow = 0.hInstApp = 0.lpIDList = 0
End Withr =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 Longx = 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 Longx = WNetConnectionDialog(Me.hwnd, 2)

3.调用颜色对话框

PrivateType ChooseColor
lStructSize As LonghwndOwner As LonghInstance As LongrgbResult As LonglpCustColors As Stringflags As LonglCustData As LonglpfnHook As LonglpTemplateName As String
EndType
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As ChooseColor) As Long

将以下代码置入某一事件中:

Dim cc AsChooseColor
Dim CustColor(16) As Longcc.lStructSize = Len(cc)
cc.hwndOwner =Form1.hWnd
cc.hInstance =App.hInstance
cc.flags = 0cc.lpCustColors = String$(16 * 4, 0)
Dima
Dimx
Dimc1
Dimc2
Dimc3
Dimc4
a =ChooseColor(cc)
Cls
If (a) Then
    MsgBox "Color chosen:" & Str$(cc.rgbResult)

For x = 1 To Len(cc.lpCustColors) Step 4c1 = 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)
Nextx
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"
-------------------------
01.44M1.2M
11.44M1.2M
21.44M1.2M
31.44M360K
41.44M1.2M
5720K1.2M
61.44M1.2M
71.44M1.2M
81.44M1.2M
91.44M1.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&)
ElseRetFromMsg = MsgBox("This drive is NOT a removeable" & vbCrLf &_
"drive! Format this drive?", 276, "SHFormatDrive Example")
Select CaseRetFromMsg
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各种通用对话框(CommonDiaglog)的方法(二)
1.选择目录/文件夹对话框
将以下代码置于一模块中

Option Explicit
'调用方式:: string = BrowseForFolders(Hwnd,TitleOfDialog)'例如:String1 = BrowseForFolders(Hwnd, "Select target folder...")
PublicType BrowseInfo
hwndOwner As LongpIDLRoot As LongpszDisplayName As LonglpszTitle As LongulFlags As LonglpfnCallback As LonglParam As LongiImage As Long
EndType
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 AsBrowseInfo
'初始化变量
WithudtBI
.hwndOwner =hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags =BIF_RETURNONLYFSDIRS
End With
'调用 API
lpIDList =SHBrowseForFolder(udtBI)
If lpIDList ThensPath = String$(MAX_PATH, 0)
lResult =SHGetPathFromIDList(lpIDList, sPath)
CallCoTaskMemFree(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 Longx% = WNetConnectionDialog(Me.hwnd, 1)

3.调用"打开文件"对话框

PrivateType OPENFILENAME
lStructSize As LonghwndOwner As LonghInstance As LonglpstrFilter As StringlpstrCustomFilter As StringnMaxCustFilter As LongnFilterIndex As LonglpstrFile As StringnMaxFile As LonglpstrFileTitle As StringnMaxFileTitle As LonglpstrInitialDir As StringlpstrTitle As Stringflags As LongnFileOffset As IntegernFileExtension As IntegerlpstrDefExt As StringlCustData As LonglpfnHook As LonglpTemplateName As String
EndType
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long将以下代码置于某一事件中
Dim ofn AsOPENFILENAME
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 = 255ofn.lpstrFileTitle = Space$(254)
ofn.nMaxFileTitle = 255ofn.lpstrInitialDir = curdirofn.lpstrTitle = "Our File Open Title"ofn.flags = 0
Dima
a =GetOpenFileName(ofn)
If (a) Then
MsgBox "File to Open: " + Trim$(ofn.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If

4.调用"打印"对话框

PrivateType PrintDlg
lStructSize As LonghwndOwner As LonghDevMode As LonghDevNames As Longhdc As Longflags As LongnFromPage As IntegernToPage As IntegernMinPage As IntegernMaxPage As IntegernCopies As IntegerhInstance As LonglCustData As LonglpfnPrintHook As LonglpfnSetupHook As LonglpPrintTemplateName As StringlpSetupTemplateName As StringhPrintTemplate As LonghSetupTemplate As Long
EndType
Private Declare Function PrintDlg Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PrintDlg) As Long
'将以下代码置于某一事件中
Dim tPrintDlg AsPrintDlg
tPrintDlg.lStructSize = Len(tPrintDlg)
tPrintDlg.hwndOwner = Me.hwnd
tPrintDlg.hdc =hdc
tPrintDlg.flags = 0tPrintDlg.nFromPage = 0tPrintDlg.nToPage = 0tPrintDlg.nMinPage = 0tPrintDlg.nMaxPage = 0tPrintDlg.nCopies = 1tPrintDlg.hInstance =App.hInstance
lpPrintTemplateName = "Print Page"
Dima
a =PrintDlg(tPrintDlg)
If a ThenlFromPage =tPrintDlg.nFromPage
lToPage =tPrintDlg.nToPage
lMin =tPrintDlg.nMinPage
lMax =tPrintDlg.nMaxPage
lCopies =tPrintDlg.nCopies
PrintMyPage 'Custom printing Subroutine 
End If 

免责声明:文章转载自《通用对话框专辑(全)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇QQ会员AMS平台PHP7升级实践bat命令批处理判断32位还是64位系统的多种方法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C#System.Text.RegularExpressions.Regex使用(二)

string x = "\\";Regex r1 = new Regex("^\\\\$");Console.WriteLine("r1 match count:" + r1.Matches(x).Count);//1Regex r2 = new Regex(@"^\\$");Console.WriteLine("r2 match count:" + r...

Arcgis python geometry

Geometry 描述 来自:https://pro.arcgis.com/zh-cn/pro-app/arcpy/classes/geometry.htm 几何对象定义空间位置和关联几何形状。 说明 在许多地理处理工作流中,您可能需要使用坐标和几何信息运行特定操作,但不一定想经历创建新(临时)要素类、使用光标填充要素类、使用要素类,然后删除临时要素...

OHC Java堆外缓存详解与应用

1、背景   在当前微服务体系架构中,有很多服务例如,在 特征组装 与 排序等场景都需要有大量的数据支撑,快速读取这些数据对提升整个服务于的性能起着至关重要的作用。   缓存在各大系统中应用非常广泛。尤其是业务程序所依赖的数据可能在各种类型的数据库上(mysql、hive 等),那么如果想要获取到这些数据需要通过网络来访问。再加上往往数据量又很庞大,网络传...

Google Map 根据坐标 获取地址信息

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Xml; 6 using System.Net; 7 8 namespace Utility 9 { 10 pu...

thinkphp 常见问题

0.写在最前面的不断更新 (1)trace不起作用 A:必须要输出到模板,才会有trace信息 (2)提示“您浏览的页面暂时发生了错误!请稍后再试~” A:检查控制器(看看能进到控制器没有,设断点输出一下。如果没有。检查控制器名字,路径对了没有?) (3)Model:relation您所请求的方法不存在! A:这没什么好说的了,检查方法。 (4)神马都检查...

Android学习——移植tr069程序到Android平台

原创作品,转载请注明出处,严禁非法转载。如有错误,请留言! email:40879506@qq.com 声明:本系列涉及的开源程序代码学习和研究,严禁用于商业目的。 如有任何问题,欢迎和我交流。(企鹅号:408797506)  淘宝店:https://shop484606081.taobao.com 本篇用到的代码下载路径:http://download....