home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Great_&_Si70055482002.psc / dwdMCCombo.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-04-08  |  34.6 KB  |  862 lines

  1. VERSION 5.00
  2. Begin VB.UserControl dwdMCCombo 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   705
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   2010
  8.    ScaleHeight     =   705
  9.    ScaleWidth      =   2010
  10.    ToolboxBitmap   =   "dwdMCCombo.ctx":0000
  11.    Begin VB.ListBox lstList 
  12.       Appearance      =   0  'Flat
  13.       Height          =   225
  14.       ItemData        =   "dwdMCCombo.ctx":0312
  15.       Left            =   60
  16.       List            =   "dwdMCCombo.ctx":0314
  17.       TabIndex        =   1
  18.       Top             =   420
  19.       Visible         =   0   'False
  20.       Width           =   1875
  21.    End
  22.    Begin VB.TextBox txtText 
  23.       BorderStyle     =   0  'None
  24.       Height          =   315
  25.       Left            =   60
  26.       TabIndex        =   0
  27.       Top             =   60
  28.       Width           =   1875
  29.    End
  30. Attribute VB_Name = "dwdMCCombo"
  31. Attribute VB_GlobalNameSpace = False
  32. Attribute VB_Creatable = True
  33. Attribute VB_PredeclaredId = False
  34. Attribute VB_Exposed = True
  35. Option Explicit
  36. Implements dwdSubClass
  37. '***********************************************************************************************
  38. 'DWD Multi-Column ComboBox - ActiveX Control
  39. 'Author(s): Matthew Hood Email: DragonWeyrDev@Yahoo.com
  40. '***********************************************************************************************
  41. '***********************************************************************************************
  42. 'Dependencies:
  43. '***********************************************************************************************
  44. 'Revision History:
  45. '[Matthew Hood]
  46. '   08/13/01 - New
  47. '   02/07/02 - Bug fix.
  48. '              The application will now remain activated when the user shows the drop-down.
  49. '              Added support for MDI & MDI Child forms.
  50. '   02/12/02 - Bug fix.
  51. '              Moved "Me.ButtonDown = False" to the lstList_Click event from the lstList_MouseDown
  52. '              event to fix a clicking bug.  Removed the lstList_MouseDown event.
  53. '   04/07/02 - Bug fix.
  54. '              Fixed scrollbar display for WindowsXP.
  55. '***********************************************************************************************
  56. '***********************************************************************************************
  57. 'Private API Types
  58. '***********************************************************************************************
  59. Private Type RECT
  60.     Left As Long
  61.     Top As Long
  62.     Right As Long
  63.     Bottom As Long
  64. End Type
  65. Private Type POINTAPI
  66.     X As Long
  67.     Y As Long
  68. End Type
  69. '***********************************************************************************************
  70. 'Private API Constants
  71. '***********************************************************************************************
  72. Private Const SM_CXHTHUMB As Long = 10
  73. Private Const DFC_SCROLL As Long = 3
  74. Private Const DFCS_SCROLLDOWN As Long = &H1
  75. Private Const DFCS_PUSHED As Long = &H200
  76. Private Const DFCS_FLAT As Long = &H4000
  77. Private Const DFCS_INACTIVE As Long = &H100
  78. Private Const GWL_EXSTYLE As Long = (-20)
  79. Private Const GWL_STYLE As Long = (-16)
  80. Private Const SW_HIDE As Long = 0
  81. Private Const SW_SHOW As Long = 5
  82. Private Const SWP_NOSIZE As Long = &H1
  83. Private Const SWP_NOACTIVATE As Long = &H10
  84. Private Const SWP_SHOWWINDOW As Long = &H40
  85. Private Const SWP_HIDEWINDOW As Long = &H80
  86. Private Const WS_EX_TOOLWINDOW As Long = &H80
  87. Private Const WS_BORDER As Long = &H800000
  88. Private Const WS_CHILD As Long = &H40000000
  89. Private Const SPI_GETWORKAREA As Long = 48
  90. Private Const HWND_TOPMOST As Long = -1
  91. Private Const LB_FINDSTRING As Long = &H18F
  92. Private Const LB_SETTABSTOPS As Long = &H192
  93. Private Const WM_ACTIVATE As Long = &H6
  94. Private Const WM_NCACTIVATE As Long = &H86
  95. Private Const GA_ROOT As Long = 2
  96. '***********************************************************************************************
  97. 'Private API Declarations
  98. '***********************************************************************************************
  99. Private Declare Function DrawFrameControlAPI Lib "user32" Alias "DrawFrameControl" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
  100. Private Declare Function GetDesktopWindowAPI Lib "user32" Alias "GetDesktopWindow" () As Long
  101. Private Declare Function GetAncestorAPI Lib "user32.dll" Alias "GetAncestor" (ByVal hWnd As Long, ByVal gaFlags As Long) As Long
  102. Private Declare Function GetSystemMetricsAPI Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
  103. Private Declare Function GetWindowRectAPI Lib "user32" Alias "GetWindowRect" (ByVal hWnd As Long, lpRect As RECT) As Long
  104. Private Declare Function MoveWindowAPI Lib "user32" Alias "MoveWindow" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
  105. Private Declare Function SendMessageAPI Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  106. Private Declare Function SetParentAPI Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  107. Private Declare Function SetWindowLongAPI Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  108. Private Declare Function SetWindowPosAPI Lib "user32" Alias "SetWindowPos" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  109. Private Declare Function ShowWindowAPI Lib "user32" Alias "ShowWindow" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
  110. Private Declare Function SystemParametersInfoAPI Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
  111. Private Declare Function LBItemFromPtAPI Lib "comctl32.dll" Alias "LBItemFromPt" (ByVal hWnd As Long, ByVal ptx As Long, ByVal pty As Long, ByVal bAutoScroll As Long) As Long
  112. Private Declare Function ClientToScreenAPI Lib "user32" Alias "ClientToScreen" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
  113. Private Declare Function GetWindowLongAPI Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  114. Private Declare Function SetWindowThemeAPI Lib "uxtheme.dll" Alias "SetWindowTheme" (ByVal hWnd As Long, pszSubAppName As String, pszSubIdList As String) As Long 'Rev. (04/07/02)
  115. '***********************************************************************************************
  116. 'Public Enumerations
  117. '***********************************************************************************************
  118. Public Enum dwdComboBoxStyle
  119.     vbComboDropdown
  120.     vbComboDropdownList
  121. End Enum
  122. '***********************************************************************************************
  123. 'Public Events
  124. '***********************************************************************************************
  125. Public Event ButtonClick(ByVal ButtonDown As Boolean)
  126. Public Event Change()
  127. Public Event Click()
  128. Public Event DblClick()
  129. Public Event KeyDown(KeyCode As Integer, Shift As Integer)
  130. Public Event KeyPress(KeyAscii As Integer)
  131. Public Event KeyUp(KeyCode As Integer, Shift As Integer)
  132. Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  133. Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  134. Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  135. '***********************************************************************************************
  136. 'Private Member Variables
  137. '***********************************************************************************************
  138. Private mButtonDown As Boolean
  139. Private mColumnCount As Long
  140. Private mColumnWidth() As Long
  141. Private mDropDownHeight As Long
  142. Private mDropDownWidth As Long
  143. Private mDropDownWidthAutoSize As Boolean
  144. Private mHotTracking As Boolean
  145. Private mList As Collection
  146. Private mListIndex As Long
  147. Private mLocked As Boolean
  148. Private mNoClick As Boolean
  149. Private mOldValue As String
  150. Private mStyle As dwdComboBoxStyle
  151. '***********************************************************************************************
  152. 'Public Properties
  153. '***********************************************************************************************
  154. Public ParentHwnd As Long
  155. Public Property Get Alignment() As AlignmentConstants
  156. On Error Resume Next
  157.     Alignment = txtText.Alignment
  158. End Property
  159. Public Property Let Alignment(ByVal Value As AlignmentConstants)
  160.     txtText.Alignment = Value
  161.     Call PropertyChanged("Alignment")
  162. End Property
  163. Public Property Get BackColor() As OLE_COLOR
  164. On Error Resume Next
  165.     BackColor = txtText.BackColor
  166. End Property
  167. Public Property Let BackColor(ByVal Value As OLE_COLOR)
  168.     txtText.BackColor = Value
  169.     lstList.BackColor = Value
  170.     Call PropertyChanged("BackColor")
  171. End Property
  172. Public Property Get ButtonDown() As Boolean
  173. On Error Resume Next
  174.     ButtonDown = mButtonDown
  175. End Property
  176. Public Property Let ButtonDown(ByVal Value As Boolean)
  177.     If Value = mButtonDown Then Exit Property
  178.     mButtonDown = Value
  179.     Call pDrawButton
  180.     Call pShowHideDropDown
  181. End Property
  182. Public Property Get ColumnCount() As Long
  183. On Error Resume Next
  184.     ColumnCount = mColumnCount
  185. End Property
  186. Public Property Let ColumnCount(ByVal Value As Long)
  187.     Dim l As Long
  188.     If Value < 1 Then
  189.         Err.Raise 380
  190.         Exit Property
  191.     End If
  192.     mColumnCount = Value
  193.     ReDim Preserve mColumnWidth(1 To Value) As Long
  194.     For l = 1 To mList.Count
  195.         mList(l).ColCount = Value
  196.     Next l
  197.     Call PropertyChanged("ColumnCount")
  198. End Property
  199. Public Property Get ColumnWidth(ByVal Index As Long) As Long
  200. On Error Resume Next
  201.     ColumnWidth = mColumnWidth(Index)
  202. End Property
  203. Public Property Let ColumnWidth(ByVal Index As Long, ByVal Value As Long)
  204.     mColumnWidth(Index) = Value
  205. End Property
  206. Public Property Get DropDownHeight() As Long
  207. On Error Resume Next
  208.     DropDownHeight = mDropDownHeight
  209. End Property
  210. Public Property Let DropDownHeight(ByVal Value As Long)
  211.     mDropDownHeight = Value
  212.     Call PropertyChanged("DropDownHeight")
  213. End Property
  214. Public Property Get DropDownWidth() As Long
  215. On Error Resume Next
  216.     DropDownWidth = mDropDownWidth
  217. End Property
  218. Public Property Let DropDownWidth(ByVal Value As Long)
  219.     If (Value < -1) Then
  220.         Err.Raise 380
  221.         Exit Property
  222.     End If
  223.     mDropDownWidthAutoSize = (Value = UserControl.Width)
  224.     mDropDownWidth = Value
  225.     Call PropertyChanged("DrowDownWidth")
  226. End Property
  227. Public Property Get Enabled() As Boolean
  228. On Error Resume Next
  229.     Enabled = UserControl.Enabled
  230. End Property
  231. Public Property Let Enabled(ByVal Value As Boolean)
  232.     UserControl.Enabled = Value
  233.     txtText.Enabled = Value
  234.     If (Not Value) Then
  235.         Me.ButtonDown = False
  236.     Else
  237.         Call pDrawButton
  238.     End If
  239.     Call PropertyChanged("Enabled")
  240. End Property
  241. Public Property Get Font() As StdFont
  242. On Error Resume Next
  243.     Set Font = txtText.Font
  244. End Property
  245. Public Property Set Font(ByVal Value As StdFont)
  246.     Set txtText.Font = Value
  247.     Set lstList.Font = Value
  248.     Call PropertyChanged("Font")
  249. End Property
  250. Public Property Get FontBold() As Boolean
  251. On Error Resume Next
  252.     FontBold = txtText.FontBold
  253. End Property
  254. Public Property Let FontBold(ByVal Value As Boolean)
  255.     txtText.FontBold = Value
  256.     lstList.FontBold = Value
  257.     Call PropertyChanged("FontBold")
  258. End Property
  259. Public Property Get FontItalic() As Boolean
  260. On Error Resume Next
  261.     FontItalic = txtText.FontItalic
  262. End Property
  263. Public Property Let FontItalic(ByVal Value As Boolean)
  264.     txtText.FontItalic = Value
  265.     lstList.FontItalic = Value
  266.     Call PropertyChanged("FontItalic")
  267. End Property
  268. Public Property Get FontName() As String
  269. On Error Resume Next
  270.     FontName = txtText.FontName
  271. End Property
  272. Public Property Let FontName(ByVal Value As String)
  273.     txtText.FontName = Value
  274.     lstList.FontName = Value
  275.     Call PropertyChanged("FontName")
  276. End Property
  277. Public Property Get FontSize() As Single
  278. On Error Resume Next
  279.     FontSize = txtText.FontSize
  280. End Property
  281. Public Property Let FontSize(ByVal Value As Single)
  282.     txtText.FontSize = Value
  283.     lstList.FontSize = Value
  284.     Call PropertyChanged("FontSize")
  285. End Property
  286. Public Property Get FontStrikethru() As Boolean
  287. On Error Resume Next
  288.     FontStrikethru = txtText.FontStrikethru
  289. End Property
  290. Public Property Let FontStrikethru(ByVal Value As Boolean)
  291.     txtText.FontStrikethru = Value
  292.     Call PropertyChanged("FontSFontStrikethruize")
  293. End Property
  294. Public Property Get FontUnderline() As Boolean
  295. On Error Resume Next
  296.     FontUnderline = txtText.FontUnderline
  297. End Property
  298. Public Property Let FontUnderline(ByVal Value As Boolean)
  299.     txtText.FontUnderline = Value
  300.     Call PropertyChanged("FontUnderline")
  301. End Property
  302. Public Property Get ForeColor() As OLE_COLOR
  303. On Error Resume Next
  304.     ForeColor = txtText.ForeColor
  305. End Property
  306. Public Property Let ForeColor(ByVal Value As OLE_COLOR)
  307.     txtText.ForeColor = Value
  308.     Call PropertyChanged("ForeColor")
  309. End Property
  310. Public Property Get Height() As Long
  311. On Error Resume Next
  312.     Height = UserControl.Height
  313. End Property
  314. Public Property Get hWnd() As Long
  315. On Error Resume Next
  316.     hWnd = UserControl.hWnd
  317. End Property
  318. Public Property Get hWndEdit() As Long
  319. On Error Resume Next
  320.     hWndEdit = txtText.hWnd
  321. End Property
  322. Public Property Get hWndList() As Long
  323. On Error Resume Next
  324.     hWndList = lstList.hWnd
  325. End Property
  326. Public Property Get ItemText(ByVal ListIndex As Long, ByVal ColIndex As Long) As String
  327. On Error Resume Next
  328.     ItemText = mList(ListIndex).Text(ColIndex)
  329. End Property
  330. Public Property Let ItemText(ByVal ListIndex As Long, ByVal ColIndex As Long, ByVal Value As String)
  331.     Dim l As Long
  332.     Dim sText As String
  333.     mList(ListIndex).Text(ColIndex) = Value
  334.     sText = mList(ListIndex).Text(1)
  335.     For l = 2 To mColumnCount
  336.         sText = sText & vbTab & mList(ListIndex).Text(l)
  337.     Next l
  338.     lstList.List(ListIndex - 1) = sText
  339.     If (ListIndex = 1) And (ColIndex = 1) Then Me.Text = Value
  340. End Property
  341. Public Property Get ListCount() As Long
  342. On Error Resume Next
  343.     ListCount = mList.Count
  344. End Property
  345. Public Property Get ListIndex() As Long
  346. On Error Resume Next
  347.     ListIndex = mListIndex
  348. End Property
  349. Public Property Let ListIndex(ByVal Value As Long)
  350.     mListIndex = Value
  351.     If (mListIndex = 0) Then
  352.         Me.Text = vbNullString
  353.     Else
  354.         Me.Text = mList(Value).Text(1)
  355.     End If
  356. End Property
  357. Public Property Get Locked() As Boolean
  358. On Error Resume Next
  359.     Locked = mLocked
  360. End Property
  361. Public Property Let Locked(ByVal Value As Boolean)
  362.     mLocked = Value
  363.     If (mStyle = vbComboDropdown) Then txtText.Locked = Value
  364.     Call PropertyChanged("Locked")
  365. End Property
  366. Public Property Get MaxLength() As Long
  367. On Error Resume Next
  368.     MaxLength = txtText.MaxLength
  369. End Property
  370. Public Property Let MaxLength(ByVal Value As Long)
  371.     txtText.MaxLength = Value
  372.     Call PropertyChanged("MaxLength")
  373. End Property
  374. Public Property Get SelLength() As Long
  375. On Error Resume Next
  376.     SelLength = txtText.SelLength
  377. End Property
  378. Public Property Let SelLength(ByVal Value As Long)
  379.     txtText.SelLength = Value
  380. End Property
  381. Public Property Get SelStart() As Long
  382. On Error Resume Next
  383.     SelStart = txtText.SelStart
  384. End Property
  385. Public Property Let SelStart(ByVal Value As Long)
  386.     txtText.SelStart = Value
  387. End Property
  388. Public Property Get SelText() As String
  389. On Error Resume Next
  390.     SelText = txtText.SelText
  391. End Property
  392. Public Property Let SelText(ByVal Value As String)
  393.     txtText.SelText = Value
  394. End Property
  395. Public Property Get Style() As dwdComboBoxStyle
  396. On Error Resume Next
  397.     Style = mStyle
  398. End Property
  399. Public Property Let Style(ByVal Value As dwdComboBoxStyle)
  400.     mStyle = Value
  401.     If Value = vbComboDropdownList Then
  402.         txtText.Locked = True
  403.     Else
  404.         txtText.Locked = mLocked
  405.     End If
  406.     Call PropertyChanged("Style")
  407. End Property
  408. Public Property Get Text() As String
  409. On Error Resume Next
  410.     Text = txtText.Text
  411. End Property
  412. Public Property Let Text(ByVal Value As String)
  413.     txtText.Text = Value
  414.     Call PropertyChanged("Text")
  415. End Property
  416. Public Property Get ToolTip() As String
  417. On Error Resume Next
  418.     ToolTip = txtText.ToolTipText
  419. End Property
  420. Public Property Let ToolTip(ByVal Value As String)
  421. On Error Resume Next
  422.     txtText.ToolTipText = Value
  423.     UserControl.Extender.ToolTipText = Value
  424. End Property
  425. '***********************************************************************************************
  426. 'Private Methods
  427. '***********************************************************************************************
  428. 'Draws the drop-down button.
  429. Private Sub pDrawButton()
  430.     If UserControl.Enabled Then
  431.         If mButtonDown Then
  432.             Call DrawFrameControlAPI(ByVal UserControl.hdc, pRect((txtText.Width / Screen.TwipsPerPixelX), 0, GetSystemMetricsAPI(ByVal SM_CXHTHUMB), ((txtText.Height + 30) / Screen.TwipsPerPixelY) - 4), DFC_SCROLL, DFCS_SCROLLDOWN Or DFCS_PUSHED Or DFCS_FLAT)
  433.         Else
  434.             Call DrawFrameControlAPI(ByVal UserControl.hdc, pRect((txtText.Width / Screen.TwipsPerPixelX), 0, GetSystemMetricsAPI(ByVal SM_CXHTHUMB), ((txtText.Height + 30) / Screen.TwipsPerPixelY) - 4), DFC_SCROLL, DFCS_SCROLLDOWN)
  435.         End If
  436.     Else
  437.         Call DrawFrameControlAPI(ByVal UserControl.hdc, pRect((txtText.Width / Screen.TwipsPerPixelX), 0, GetSystemMetricsAPI(ByVal SM_CXHTHUMB), ((txtText.Height + 30) / Screen.TwipsPerPixelY) - 4), DFC_SCROLL, DFCS_SCROLLDOWN Or DFCS_INACTIVE)
  438.     End If
  439. End Sub
  440. 'Returns the Hi & Lo values of the lParam.
  441. Private Sub pGetHiLoWord(ByVal lParam As Long, ByRef LoWord As Long, ByRef HiWord As Long)
  442. On Error Resume Next
  443.     LoWord = lParam And &HFFFF&
  444.     HiWord = lParam \ &H10000 And &HFFFF&
  445. End Sub
  446. Private Function pGetListRECT() As RECT
  447. On Error Resume Next
  448.     Dim rct As RECT
  449.     Dim rctUC As RECT
  450.     Dim rctSCR As RECT
  451.     Dim lSCRH As Long
  452.     Dim lHeight As Long
  453.     Dim lBottom As Long
  454.     Dim lRight As Long
  455.     Dim lWidth As Long
  456.     Dim lCnt As Long
  457.     Call GetWindowRectAPI(ByVal UserControl.hWnd, rctUC)
  458.     Call SystemParametersInfoAPI(ByVal SPI_GETWORKAREA, ByVal 0, rctSCR, ByVal 0)
  459.     lSCRH = rctSCR.Bottom - rctSCR.Top
  460.     lCnt = mList.Count
  461.     If (mDropDownHeight = 0) Then
  462.         If (lCnt > 8) Then
  463.             lHeight = (8 * 195)
  464.         ElseIf (lCnt = 0) Then
  465.             lHeight = 230
  466.         Else
  467.             lHeight = 30 + (lCnt * 195)
  468.         End If
  469.     ElseIf (lCnt = 0) Then
  470.         lHeight = 230
  471.     Else
  472.         lHeight = mDropDownHeight
  473.     End If
  474.     rct.Bottom = (lHeight / Screen.TwipsPerPixelY)
  475.     rct.Top = rctUC.Bottom + 1
  476.     If (mDropDownWidth = -1) Then
  477.         For lCnt = 1 To mColumnCount
  478.             If mColumnWidth(lCnt) = 0 Then
  479.                 lWidth = lWidth + 1440
  480.             Else
  481.                 lWidth = lWidth + mColumnWidth(lCnt)
  482.             End If
  483.         Next lCnt
  484.     Else
  485.         lWidth = mDropDownWidth
  486.     End If
  487.     If lWidth < UserControl.Width Then lWidth = UserControl.Width
  488.     rct.Right = (lWidth / Screen.TwipsPerPixelX)
  489.     rct.Left = rctUC.Left
  490.     lRight = rct.Left + rct.Right
  491.     pGetListRECT = rct
  492. End Function
  493. 'Returns a rectangle type from specified parameters.
  494. Private Function pRect(Left As Long, Top As Long, Width As Long, Height As Long) As RECT
  495. On Error Resume Next
  496.     With pRect
  497.       .Left = Left
  498.       .Top = Top
  499.       .Right = Left + Width
  500.       .Bottom = Top + Height
  501.    End With
  502. End Function
  503. Private Sub pShowHideDropDown()
  504. On Error Resume Next
  505.     Const CONST_DLUPERTWIP As Single = 21.9
  506.     Dim rct As RECT
  507.     Dim lPhWnd As Long
  508.     Dim l As Long
  509.     Dim mCols() As Long
  510.     If mButtonDown Then
  511.         ReDim mCols(mColumnCount - 1) As Long
  512.         For l = 0 To mColumnCount - 1
  513.             If (l <> 0) Then
  514.                 mCols(l) = mCols(l - 1) + (mColumnWidth(l + 1) / CONST_DLUPERTWIP)
  515.             Else
  516.                 mCols(l) = (mColumnWidth(l + 1) / CONST_DLUPERTWIP)
  517.             End If
  518.         Next l
  519.         Call SendMessageAPI(lstList.hWnd, LB_SETTABSTOPS, 0&, ByVal 0&)
  520.         Call SendMessageAPI(lstList.hWnd, LB_SETTABSTOPS, 3, mCols(0))
  521.         lstList.Refresh
  522.         mNoClick = True
  523.         lstList.ListIndex = lstList.ListCount - 1
  524.         lstList.ListIndex = 0
  525.         lstList.ListIndex = mListIndex - 1
  526.         mNoClick = False
  527.         mOldValue = Me.Text
  528.         
  529.         rct = pGetListRECT
  530.         Call SetParentAPI(lstList.hWnd, GetDesktopWindowAPI)
  531.         Call MoveWindowAPI(lstList.hWnd, rct.Left, rct.Top, rct.Right, rct.Bottom, -1)
  532.         Call SetWindowThemeAPI(lstList.hWnd, 0, 0) 'Rev. (04/07/02)
  533.         Call SetWindowLongAPI(lstList.hWnd, GWL_STYLE, WS_BORDER)
  534.         Call SetWindowLongAPI(lstList.hWnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW)
  535.         Call SetWindowPosAPI(lstList.hWnd, HWND_TOPMOST, rct.Left, rct.Top, rct.Right, rct.Bottom, (SWP_HIDEWINDOW Or SWP_NOSIZE)) 'Rev. (02/07/02)
  536.         Call SetWindowPosAPI(lstList.hWnd, HWND_TOPMOST, rct.Left, rct.Top, rct.Right, rct.Bottom, (SWP_SHOWWINDOW Or SWP_NOSIZE))
  537.         
  538.         'Rev. (02/07/02)
  539.         If UserControl.Parent.MDIChild Then
  540.             lPhWnd = GetAncestorAPI(UserControl.Parent.hWnd, GA_ROOT)
  541.         Else
  542.             lPhWnd = UserControl.Parent.hWnd
  543.         End If
  544.         Call SendMessageAPI(lPhWnd, WM_NCACTIVATE, 1, 0)
  545.         'End Rev. (02/07/02)
  546.         Call AttachMessage(Me, lstList.hWnd, WM_ACTIVATE)
  547.         DoEvents
  548.         lstList.SetFocus
  549.     Else
  550.         Call SetParentAPI(lstList.hWnd, UserControl.hWnd)
  551.         Call ShowWindowAPI(lstList.hWnd, SW_HIDE)
  552.         Call DetachMessage(Me, lstList.hWnd, WM_ACTIVATE)
  553.         Call SendMessageAPI(UserControl.Parent.hWnd, WM_ACTIVATE, 1, 0)
  554.     End If
  555.     RaiseEvent ButtonClick(mButtonDown)
  556. End Sub
  557. '***********************************************************************************************
  558. 'Public Methods
  559. '***********************************************************************************************
  560. Public Function AddItem(ByVal Value As String) As Long
  561. On Error Resume Next
  562.     Dim itm As dwdListItem
  563.     Set itm = New dwdListItem
  564.     itm.ColCount = mColumnCount
  565.     itm.Text(1) = Value
  566.     mList.Add itm
  567.     Set itm = Nothing
  568.     lstList.AddItem Value
  569.     AddItem = mList.Count
  570. End Function
  571. Public Sub Clear()
  572. On Error Resume Next
  573.     Set mList = New Collection
  574.     lstList.Clear
  575.     mListIndex = 0
  576. End Sub
  577. Public Function FindItem(ByVal Value As String, Optional ByVal ColumnIndex As Long = 1, Optional ByVal StartIndex As Long, Optional ByVal Exact As Boolean) As Long
  578. On Error Resume Next
  579.     Dim l As Long
  580.     Dim sFText As String
  581.     Dim lLen As Long
  582.     sFText = Value
  583.     lLen = Len(sFText)
  584.     If (sFText = vbNullString) Then
  585.         FindItem = 0
  586.         Exit Function
  587.     End If
  588.     If (StartIndex = 0) And (mList.Count > 0) Then StartIndex = 1
  589.     If (ColumnIndex < 1) Or (ColumnIndex > mColumnCount) Then ColumnIndex = 1
  590.     For l = StartIndex To mList.Count
  591.         If Exact Then
  592.             If StrComp(mList(l).Text(ColumnIndex), sFText, vbTextCompare) = 0 Then
  593.                 FindItem = l
  594.                 Exit For
  595.             Else
  596.                 FindItem = 0
  597.             End If
  598.         Else
  599.             If (StrComp(Left$(mList(l).Text(ColumnIndex), lLen), sFText, vbTextCompare) = 0) Then
  600.                 FindItem = l
  601.                 Exit For
  602.             Else
  603.                 FindItem = 0
  604.             End If
  605.         End If
  606.     Next l
  607. End Function
  608. Public Function RemoveItem(ByVal Index As Long)
  609. On Error Resume Next
  610.     mList.Remove Index
  611.     mListIndex = mListIndex - 1
  612.     lstList.RemoveItem Index - 1
  613. End Function
  614. '***********************************************************************************************
  615. 'Change/Validation Events
  616. '***********************************************************************************************
  617. Private Sub txtText_Change()
  618. On Error Resume Next
  619.     mListIndex = Me.FindItem(txtText.Text, , , True)
  620.     RaiseEvent Change
  621. End Sub
  622. '***********************************************************************************************
  623. 'Mouse Events
  624. '***********************************************************************************************
  625. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  626. On Error Resume Next
  627.     If (X > txtText.Width) Then
  628.         Me.ButtonDown = Not Me.ButtonDown
  629.     Else
  630.         RaiseEvent MouseDown(Button, Shift, X, Y)
  631.     End If
  632. End Sub
  633. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  634. On Error Resume Next
  635.     RaiseEvent MouseMove(Button, Shift, X, Y)
  636. End Sub
  637. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  638. On Error Resume Next
  639.     RaiseEvent MouseUp(Button, Shift, X, Y)
  640. End Sub
  641. Private Sub txtText_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  642. On Error Resume Next
  643.     RaiseEvent MouseDown(Button, Shift, X, Y)
  644. End Sub
  645. Private Sub txtText_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  646. On Error Resume Next
  647.     RaiseEvent MouseMove(Button, Shift, X, Y)
  648. End Sub
  649. Private Sub txtText_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  650. On Error Resume Next
  651.     RaiseEvent MouseUp(Button, Shift, X, Y)
  652. End Sub
  653. Private Sub lstList_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  654. On Error Resume Next
  655.     Dim lIndex As Long
  656.     Dim pt As POINTAPI
  657.       
  658.     pt.X = X \ Screen.TwipsPerPixelX
  659.     pt.Y = Y \ Screen.TwipsPerPixelY
  660.     Call ClientToScreenAPI(lstList.hWnd, pt)
  661.     lIndex = LBItemFromPtAPI(lstList.hWnd, pt.X, pt.Y, False)
  662.     If (lIndex > -1) Then
  663.         mHotTracking = True
  664.         lstList.Selected(lIndex) = True
  665.         mHotTracking = False
  666.     End If
  667. End Sub
  668. '***********************************************************************************************
  669. 'Keyboard Events
  670. '***********************************************************************************************
  671. Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  672. On Error Resume Next
  673.     RaiseEvent KeyDown(KeyCode, Shift)
  674. End Sub
  675. Private Sub UserControl_KeyPress(KeyAscii As Integer)
  676. On Error Resume Next
  677.     RaiseEvent KeyPress(KeyAscii)
  678. End Sub
  679. Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
  680. On Error Resume Next
  681.     RaiseEvent KeyUp(KeyCode, Shift)
  682. End Sub
  683. Private Sub txtText_KeyDown(KeyCode As Integer, Shift As Integer)
  684. On Error Resume Next
  685.     RaiseEvent KeyDown(KeyCode, Shift)
  686.     Select Case KeyCode
  687.         Case vbKeyF4
  688.             If (Shift = 0) Then
  689.                 KeyCode = 0
  690.                 Me.ButtonDown = Not Me.ButtonDown
  691.             End If
  692.         Case vbKeyUp
  693.             If (Shift = 0) Then
  694.                 KeyCode = 0
  695.                 If (Me.ListIndex > 0) Then
  696.                     Me.ListIndex = Me.ListIndex - 1
  697.                 End If
  698.             End If
  699.         Case vbKeyDown
  700.             If (Shift = 0) Then
  701.                 KeyCode = 0
  702.                 If (Me.ListIndex = -1) Then
  703.                     Me.ListIndex = 0
  704.                 ElseIf (Me.ListIndex < Me.ListCount) Then
  705.                     Me.ListIndex = Me.ListIndex + 1
  706.                 End If
  707.             End If
  708.     End Select
  709. End Sub
  710. Private Sub txtText_KeyPress(KeyAscii As Integer)
  711. On Error Resume Next
  712.     RaiseEvent KeyPress(KeyAscii)
  713. End Sub
  714. Private Sub txtText_KeyUp(KeyCode As Integer, Shift As Integer)
  715. On Error Resume Next
  716.     RaiseEvent KeyUp(KeyCode, Shift)
  717. End Sub
  718. Private Sub lstList_KeyDown(KeyCode As Integer, Shift As Integer)
  719. On Error Resume Next
  720.     Select Case KeyCode
  721.         Case vbKeyF4
  722.             Me.ButtonDown = False
  723.         Case vbKeyReturn
  724.             If (Shift = 0) Then Call lstList_DblClick
  725.         Case vbKeyEscape
  726.             If (Shift = 0) Then
  727.                 Me.Text = mOldValue
  728.                 Me.ButtonDown = False
  729.             End If
  730.     End Select
  731. End Sub
  732. '***********************************************************************************************
  733. 'Click Events
  734. '***********************************************************************************************
  735. Private Sub txtText_Click()
  736. On Error Resume Next
  737.     RaiseEvent Click
  738. End Sub
  739. Private Sub txtText_DblClick()
  740. On Error Resume Next
  741.     RaiseEvent DblClick
  742. End Sub
  743. Private Sub lstList_Click()
  744. On Error Resume Next
  745.     If mNoClick Or mHotTracking Then Exit Sub
  746.     Me.Text = mList(lstList.ListIndex + 1).Text(1)
  747.     Me.ButtonDown = False 'Rev. (02/12/02)
  748. End Sub
  749. Private Sub lstList_DblClick()
  750.     Me.Text = mList(lstList.ListIndex + 1).Text(1)
  751.     Me.ButtonDown = False
  752. End Sub
  753. '***********************************************************************************************
  754. 'Focus Events
  755. '***********************************************************************************************
  756. Private Sub txtText_GotFocus()
  757. On Error Resume Next
  758.     With txtText
  759.         .SelStart = 0
  760.         .SelLength = Len(.Text)
  761.     End With
  762. End Sub
  763. '***********************************************************************************************
  764. 'Resize Events
  765. '***********************************************************************************************
  766. Private Sub UserControl_Resize()
  767. On Error Resume Next
  768.     Dim lWidth As Long
  769.     Dim lHeight As Long
  770.     lWidth = UserControl.Width - ((GetSystemMetricsAPI(ByVal SM_CXHTHUMB) + 4) * Screen.TwipsPerPixelX)
  771.     lHeight = UserControl.Height - 30
  772.     txtText.Move 0, 30, lWidth, lHeight
  773.     If mDropDownWidthAutoSize Then mDropDownWidth = UserControl.Width
  774. End Sub
  775. '***********************************************************************************************
  776. 'Paint Events
  777. '***********************************************************************************************
  778. Private Sub UserControl_Paint()
  779. On Error Resume Next
  780.     Call pDrawButton
  781. End Sub
  782. '***********************************************************************************************
  783. 'Control Property Events
  784. '***********************************************************************************************
  785. Private Sub UserControl_InitProperties()
  786. On Error Resume Next
  787.     Me.ColumnCount = 1
  788.     Me.DropDownWidth = UserControl.Width
  789.     Me.Text = UserControl.Extender.Name
  790. End Sub
  791. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  792. On Error Resume Next
  793.     Me.Alignment = PropBag.ReadProperty("Alignment", vbLeftJustify)
  794.     Me.BackColor = PropBag.ReadProperty("BackColor", &H80000005)
  795.     Me.ColumnCount = PropBag.ReadProperty("ColumnCount", 1)
  796.     Me.DropDownHeight = PropBag.ReadProperty("DropDownHeight", 0)
  797.     Me.DropDownWidth = PropBag.ReadProperty("DropDownWidth", UserControl.Width)
  798.     Me.Enabled = PropBag.ReadProperty("Enabled", True)
  799.     Set Me.Font = PropBag.ReadProperty("Font", txtText.Font)
  800.     Me.FontBold = PropBag.ReadProperty("FontBold", False)
  801.     Me.FontItalic = PropBag.ReadProperty("FontItalic", False)
  802.     Me.FontName = PropBag.ReadProperty("FontName", "MS Sans Serif")
  803.     Me.FontSize = PropBag.ReadProperty("FontSize", 8)
  804.     Me.FontStrikethru = PropBag.ReadProperty("FontStrikethru", False)
  805.     Me.FontUnderline = PropBag.ReadProperty("FontUnderline", False)
  806.     Me.ForeColor = PropBag.ReadProperty("ForeColor", &H80000008)
  807.     Me.Locked = PropBag.ReadProperty("Locked", False)
  808.     Me.MaxLength = PropBag.ReadProperty("MaxLength", 0)
  809.     Me.Style = PropBag.ReadProperty("Style", vbComboDropdown)
  810.     Me.Text = PropBag.ReadProperty("Text")
  811.     Me.ToolTip = PropBag.ReadProperty("ToolTip")
  812. End Sub
  813. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  814. On Error Resume Next
  815.     Call PropBag.WriteProperty("Alignment", Me.Alignment, vbLeftJustify)
  816.     Call PropBag.WriteProperty("BackColor", Me.BackColor, &H80000005)
  817.     Call PropBag.WriteProperty("ColumnCount", Me.ColumnCount, 1)
  818.     Call PropBag.WriteProperty("DropDownHeight", Me.DropDownHeight, 0)
  819.     Call PropBag.WriteProperty("DropDownWidth", Me.DropDownWidth, UserControl.Width)
  820.     Call PropBag.WriteProperty("Enabled", Me.Enabled, True)
  821.     Call PropBag.WriteProperty("Font", Me.Font, txtText.Font)
  822.     Call PropBag.WriteProperty("FontBold", Me.FontBold, False)
  823.     Call PropBag.WriteProperty("FontItalic", Me.FontItalic, False)
  824.     Call PropBag.WriteProperty("FontName", Me.FontName, "MS Sans Serif")
  825.     Call PropBag.WriteProperty("FontSize", Me.FontSize, 8)
  826.     Call PropBag.WriteProperty("FontStrikethru", Me.FontStrikethru, False)
  827.     Call PropBag.WriteProperty("FontUnderline", Me.FontUnderline, False)
  828.     Call PropBag.WriteProperty("ForeColor", Me.ForeColor, &H80000008)
  829.     Call PropBag.WriteProperty("Locked", Me.Locked, False)
  830.     Call PropBag.WriteProperty("MaxLength", Me.MaxLength, 0)
  831.     Call PropBag.WriteProperty("Style", Me.Style, vbComboDropdown)
  832.     Call PropBag.WriteProperty("Text", Me.Text)
  833.     Call PropBag.WriteProperty("ToolTip", Me.ToolTip)
  834. End Sub
  835. '***********************************************************************************************
  836. 'Control Initialize/Terminate Events
  837. '***********************************************************************************************
  838. Private Sub UserControl_Initialize()
  839. On Error Resume Next
  840.     Set mList = New Collection
  841. End Sub
  842. Private Sub UserControl_Terminate()
  843. On Error Resume Next
  844.     Set mList = Nothing
  845. End Sub
  846. Private Property Let dwdSubClass_MsgResponse(ByVal RHS As EMsgResponse)
  847. 'Needed for Implements
  848. End Property
  849. Private Property Get dwdSubClass_MsgResponse() As EMsgResponse
  850.     dwdSubClass_MsgResponse = emrConsume
  851. End Property
  852. Private Function dwdSubClass_WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  853.     Const WA_INACTIVE = 0
  854.     Dim lLoW As Long
  855.     Dim lHiW As Long
  856.     Select Case wMsg
  857.         Case WM_ACTIVATE
  858.             Call pGetHiLoWord(wParam, lLoW, lHiW)
  859.             If (lLoW = WA_INACTIVE) Then Me.ButtonDown = False
  860.     End Select
  861. End Function
  862.