Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for comdlg32.vbs

(view source code of comdlg32.vbs as plain text)

  1. ' A script to demonstrate some of the features available in COMDLG32.OCX
  2. ' Written/Googled/assembled by Rob van der Woude
  3. ' http://www.robvanderwoude.com
  4.  
  5. Option Explicit
  6.  
  7. Dim blnBold, blnItal, blnStrk, blnUndl
  8. Dim intColor, intSize
  9. Dim objDialog, wshShell
  10. Dim strAttrib, strFile, strFont, strPrint
  11.  
  12. Const OFN_HIDEREADONLY = &H4
  13. Const OFN_CREATEPROMPT = &H2000
  14. Const OFN_EXPLORER = &H80000
  15. Const OFN_LONGNAMES = &H200000
  16.  
  17. On Error Resume Next
  18. Set objDialog = CreateObject( "MSComDlg.CommonDialog" )
  19. If Err Then
  20. 	MsgBox Err.Description & vbCrLf & vbCrLf & "This script requires COMDLG32.OCX." & vbCrLf & vbCrLf & "Please make sure it is installed and registered.", , "COMDLG32 not registered"
  21. End If
  22.  
  23. ' COMDLG32 About box
  24. objDialog.AboutBox
  25.  
  26. ' Color Picker dialog
  27. objDialog.ShowColor
  28. intColor = objDialog.Color
  29. If Err Then
  30. 	WScript.Echo "Selected color   : -- " & Err.Description & " --"
  31. Else
  32. 	WScript.Echo "Selected color   : " & CStr( intColor )
  33. End If
  34.  
  35.  
  36. ' Font Select dialog
  37. objDialog.ShowFont
  38. strFont = objDialog.FontName
  39. intSize = objDialog.FontSize
  40. blnBold = objDialog.FontBold
  41. blnItal = objDialog.FontItalic
  42. blnStrk = objDialog.FontStrikeThru
  43. blnUndl = objDialog.FontUnderLine
  44.  
  45. strAttrib = ""
  46. If blnBold Then strAttrib = " bold"
  47. If blnItal Then strAttrib = strAttrib & " italic"
  48. If blnStrk Then strAttrib = strAttrib & " strikethrough"
  49. If blnUndl Then strAttrib = strAttrib & " underlined"
  50.  
  51. If strFont = "" Then
  52. 	If Err Then
  53. 		WScript.Echo "Selected font    : -- " & Err.Description & " --"
  54. 	Else
  55. 		WScript.Echo "Selected font    : -- None selected --"
  56. 	End If
  57. Else
  58. 	WScript.Echo "Selected font    : " & strFont & " " & intSize & "pt" & strAttrib
  59. End If
  60.  
  61. ' Help dialog
  62. ' Handles .HLP files only
  63. ' May require downloading/installing WinHlp32.exe on Vista and later Windows versions
  64. ' http://support.microsoft.com/kb/917607
  65. ' The help file, path and keyword used in this sample may not be available on your computer
  66. objDialog.HelpFile = "C:\Program Files (x86)\Common Files\Borland Shared\BDE\BDEADMIN.HLP"
  67. objDialog.HelpKey = "ODBC"
  68. objDialog.HelpCommand = 3
  69. objDialog.ShowHelp
  70.  
  71. ' Open File dialog
  72. Set wshShell = WScript.CreateObject( "Wscript.Shell" )
  73. strFile = String( 260, Chr(0) )
  74. objDialog.MaxFileSize = 260
  75. objDialog.Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_HIDEREADONLY
  76. objDialog.InitDir = wshShell.CurrentDirectory
  77. objDialog.DefaultExt = "vbs"
  78. objDialog.Filter = "VBScript files|*.vbs"
  79. objDialog.ShowOpen
  80. strFile = objDialog.FileName
  81. If strFile = "" Then
  82. 	If Err Then
  83. 		WScript.Echo "Selected file    : -- " & Err.Description & " --"
  84. 	Else
  85. 		WScript.Echo "Selected file    : -- None selected --"
  86. 	End If
  87. Else
  88. 	WScript.Echo "Selected file    : " & strFile
  89. End If
  90. Set wshShell = Nothing
  91.  
  92. ' Print dialog
  93. ' There aren't many properties we can read this way
  94. objDialog.ShowPrinter
  95. If objDialog.Orientation = 0 Then
  96. 	WScript.Echo "Page orientation : Landscape"
  97. Else
  98. 	WScript.Echo "Page orientation : Portrait"
  99. End If
  100.  
  101. ' File Save dialog
  102. objDialog.ShowSave
  103. strFile = objDialog.FileName
  104. If strFile = "" Then
  105. 	If Err Then
  106. 		WScript.Echo "File saved as    : -- " & Err.Description & " --"
  107. 	Else
  108. 		WScript.Echo "File saved as    : -- Cancelled --"
  109. 	End If
  110. Else
  111. 	WScript.Echo "File saved as    : " & strFile
  112. End If
  113.  
  114. ' Done
  115. Set objDialog = Nothing
  116.  

page last uploaded: 2016-12-15, 11:20