home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / SQL_Genera1975452222006.psc / modDialog.bas < prev    next >
BASIC Source File  |  2004-04-01  |  6KB  |  185 lines

  1. Attribute VB_Name = "modDialog"
  2. Option Explicit
  3. Option Base 0
  4.  
  5. Public Const HH_CLOSE_ALL As Integer = &H12
  6. Public Const HH_HELP_CONTEXT As Integer = &HF
  7. Public Const OFN_FILEMUSTEXIST = &H1000
  8.  
  9. Public g_intFormLoadCount As Integer        'Count of forms loaded - used for controlling auto-signoff
  10.  
  11. Private Declare Function HtmlHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
  12. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
  13.  
  14. Private m_blnHelp As Boolean                'Flag indicating if help was called on the current form
  15. Private m_blnHtmlHelpLoaded As Boolean      'Flag indicating that ocx has been loaded
  16. Private m_lngResult As Long                 'Working result
  17.  
  18. Public Function DialogColor(ctlDialog As CommonDialog, strTitle As String, lngColorDefault As Long) As Long
  19.     On Error Resume Next
  20.     If App.TaskVisible Then
  21.         With ctlDialog
  22.             .CancelError = True
  23.             .ShowColor
  24.             If Err.Number = 0 Then
  25.                 DialogColor = .Color
  26.             Else
  27.                 DialogColor = lngColorDefault
  28.             End If
  29.         End With
  30.         Err.Clear
  31.     End If
  32. End Function
  33.  
  34. Public Function DialogFileOpen(ctlDialog As CommonDialog, strTitle As String, strFileName As String, strPath As String, strFilter As String, Optional lngFlags As Long = 0) As String
  35. '
  36. '   Performs a common dialog file open function
  37. '
  38.     On Error Resume Next
  39.     If App.TaskVisible Then
  40.         With ctlDialog
  41.             .CancelError = True
  42.             .DialogTitle = strTitle
  43.             .DefaultExt = ""
  44.             .Filename = strFileName
  45.             .InitDir = strPath
  46.             .Filter = strFilter
  47.             .Flags = cdlOFNExplorer Or lngFlags
  48.             .ShowOpen
  49.             If Err.Number = 0 Then
  50.                 DialogFileOpen = .Filename
  51.             Else
  52.                 DialogFileOpen = ""
  53.             End If
  54.         End With
  55.         Err.Clear
  56.     End If
  57. End Function
  58.  
  59. Public Function DialogFileSave(ctlDialog As CommonDialog, strTitle As String, strFileName As String, strPath As String, strFilter As String, Optional lngFlags As Long = 0) As String
  60. '
  61. '   Performs a common dialog file save function
  62. '
  63.     On Error Resume Next
  64.     If App.TaskVisible Then
  65.         With ctlDialog
  66.             .CancelError = True
  67.             .DialogTitle = strTitle
  68.             .DefaultExt = ""
  69.             .Filename = strFileName
  70.             .InitDir = strPath
  71.             .Filter = strFilter
  72.             .Flags = cdlOFNExplorer Or lngFlags
  73.             .ShowSave
  74.             If Err.Number = 0 Then
  75.                 DialogFileSave = .Filename
  76.             Else
  77.                 DialogFileSave = ""
  78.             End If
  79.         End With
  80.         Err.Clear
  81.     End If
  82. End Function
  83.  
  84. Public Function DialogFont(ctlDialog As CommonDialog) As Boolean
  85. '
  86. '   Displays the common dialog font selection window
  87. '
  88.     On Error Resume Next
  89.     If App.TaskVisible Then
  90.         With ctlDialog
  91.             .CancelError = True
  92.             .Flags = cdlCFBoth Or cdlCFEffects
  93.             .ShowFont
  94.             If Err.Number = 0 Then
  95.                 DialogFont = True
  96.             Else
  97.                 DialogFont = False
  98.             End If
  99.         End With
  100.         Err.Clear
  101.     End If
  102. End Function
  103.  
  104. Public Function DialogPrinterSetup(ctlDialog As CommonDialog, lngFlags As Long, intOrientation As Integer, intCopies As Integer, intFromPage As Integer, intToPage As Integer) As Boolean
  105. '
  106. '   Performs the common dialog printer setup function
  107. '
  108.     On Error Resume Next
  109.     If App.TaskVisible Then
  110.         With ctlDialog
  111.             .CancelError = True
  112.             .Flags = lngFlags
  113.             .ShowPrinter
  114.         End With
  115.         If Err.Number = 0 Then
  116.             With ctlDialog
  117.                 lngFlags = .Flags
  118.                 intOrientation = .Orientation
  119.                 intCopies = .Copies
  120.                 intFromPage = .FromPage
  121.                 intToPage = .ToPage
  122.             End With
  123.             DialogPrinterSetup = True
  124.         Else
  125.             DialogPrinterSetup = False
  126.         End If
  127.         Err.Clear
  128.     End If
  129. End Function
  130.  
  131. Public Sub DialogWebHelp(lngHWnd As Long, strHelpFile As String, lngHelpContextID As Long)
  132. '
  133. '   Performs a common dialog help calling function - for "chm" help files
  134. '
  135.     Dim strHelpFileType As String
  136.         
  137.     On Error Resume Next
  138.     If App.TaskVisible Then
  139.         If Not m_blnHtmlHelpLoaded Then
  140.             m_lngResult = LoadLibrary("hhctrl.ocx")
  141.             m_blnHtmlHelpLoaded = True
  142.         End If
  143.         m_lngResult = HtmlHelp(lngHWnd, strHelpFile, HH_HELP_CONTEXT, lngHelpContextID)
  144.         Err.Clear
  145.     End If
  146. End Sub
  147.  
  148. Public Sub DialogWebHelpClose(lngHWnd As Long)
  149. '
  150. '   Closes help window if it was open
  151. '
  152.     m_lngResult = HtmlHelp(lngHWnd, "", HH_CLOSE_ALL, 0)
  153. End Sub
  154.  
  155. Public Sub FormHelp(lngHWnd As Long, lngContextID As Long)
  156. '
  157. '   Call for help on a form
  158. '
  159.     On Error Resume Next
  160.     m_blnHelp = True
  161.     Call DialogWebHelp(lngHWnd, App.HelpFile, lngContextID)
  162.     Err.Clear
  163. End Sub
  164.  
  165. Public Sub FormLoad()
  166. '
  167. '   Keep track of loaded application forms
  168. '
  169.     g_intFormLoadCount = g_intFormLoadCount + 1
  170. End Sub
  171.  
  172. Public Sub FormUnload(lngHWnd As Long)
  173. '
  174. '   Make sure that help is closed when leaving form
  175. '
  176.     On Error Resume Next
  177.     g_intFormLoadCount = g_intFormLoadCount - 1
  178.     If m_blnHelp Then
  179.         Call DialogWebHelpClose(lngHWnd)
  180.         m_blnHelp = False
  181.     End If
  182.     Err.Clear
  183. End Sub
  184.  
  185.