home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / allan2089911182007.psc / POSforbayshore / chameleonButton.ctl next >
Text File  |  1999-01-01  |  41KB  |  991 lines

  1. VERSION 5.00
  2. Begin VB.UserControl chameleonButton 
  3.    AutoRedraw      =   -1  'True
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   4800
  8.    DefaultCancel   =   -1  'True
  9.    ScaleHeight     =   240
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   320
  12. End
  13. Attribute VB_Name = "chameleonButton"
  14. Attribute VB_GlobalNameSpace = False
  15. Attribute VB_Creatable = True
  16. Attribute VB_PredeclaredId = False
  17. Attribute VB_Exposed = False
  18. Option Explicit
  19.  
  20. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  21. '%              <<< GONCHUKI SYSTEMS >>>              %
  22. '%                                                    %
  23. '%   CHAMELEON BUTTON - copyright ⌐2001 by gonchuki   %
  24. '%                                                    %
  25. '%  this custom control will emulate the most common  %
  26. '%      command buttons that everyone knows.          %
  27. '%                                                    %
  28. '% it took me about two weeks to develop this control %
  29. '%  and at this time i think it's completely bug free %
  30. '%     ALL THE CODE WAS WRITTEN FROM SCRATCH!!!       %
  31. '%                                                    %
  32. '%   ever wanted to add cool buttons to your app???   %
  33. '%          this is the BEST solution!!!              %
  34. '%                                                    %
  35. '%                                                    %
  36. '%     e-mail: gonchuki@yahoo.es                      %
  37. '%                                                    %
  38. '%              Don't forget to vote!!!               %
  39. '%                                                    %
  40. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41.  
  42. '######################################################
  43. '#                    UPDTATE LOG                     #
  44. '#  all times are GMT -03:00                          #
  45. '#                                                    #
  46. '#  November 9 - 03:00 am                             #
  47. '#              ╖ first release                       #
  48. '#                                                    #
  49. '#  November 9 - 05:00 pm                             #
  50. '#              ╖ added ShowFocusRect property        #
  51. '#              ╖ added repaint before triggering the #
  52. '#                click event                         #
  53. '#                                                    #
  54. '#  November 9 - 07:20 pm                             #
  55. '#              ╖ fixed the color shifting so it will #
  56. '#                display the correct color and not a #
  57. '#                weird one.                          #
  58. '#              ╖ improved Java button drawing        #
  59. '#              ╖ added custom colors capability      #
  60. '#                now it looks better than ever COOL! #
  61. '#              ╖ improved Flat button drawing        #
  62. '#                                                    #
  63. '# November 13 - 03:40 pm                             #
  64. '#              ╖ fixed the WinXP button colors and   #
  65. '#                styles. Note that as the colors are #
  66. '#                relative to a base, and for this    #
  67. '#                button i made a color work-around,  #
  68. '#                some colors will be un-reachable    #
  69. '#              ╖ added MouseMove event as requested  #
  70. '#                                                    #
  71. '# November 18 - 10:40 am                             #
  72. '#              ╖ translated all the line methods to  #
  73. '#                API calls. It's now faster than     #
  74. '#                ever. It will also decrease the     #
  75. '#                extra size of your exe!!!           #
  76. '#              ╖ improved Win32 button drawing       #
  77. '#              ╖ moved the direct calls to SetPixel  #
  78. '#                to use less inline .hdc calls       #
  79. '#              ╖ fixed KeyDown/KeyUp events so they  #
  80. '#                now act as they should              #
  81. '#                                                    #
  82. '######################################################
  83.  
  84.  
  85. Private Declare Function SetPixel Lib "gdi32" Alias "SetPixelV" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
  86. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
  87. Private Const COLOR_BTNFACE = 15
  88. Private Const COLOR_BTNSHADOW = 16
  89. Private Const COLOR_BTNTEXT = 18
  90. Private Const COLOR_BTNHIGHLIGHT = 20
  91. Private Const COLOR_BTNDKSHADOW = 21
  92. Private Const COLOR_BTNLIGHT = 22
  93.  
  94. Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  95. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
  96. Private Const DT_LEFT = &H0
  97. Private Const DT_CENTERABS = &H65
  98.  
  99. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  100. Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  101. Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  102. Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
  103.  
  104. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  105.  
  106. Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
  107. Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
  108.  
  109. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  110. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
  111. Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
  112. Private Const RGN_DIFF = 4
  113.  
  114. Private Type RECT
  115.         Left As Long
  116.         Top As Long
  117.         Right As Long
  118.         Bottom As Long
  119. End Type
  120.  
  121. Private Type POINTAPI
  122.         X As Long
  123.         Y As Long
  124. End Type
  125.  
  126. Public Enum ButtonTypes
  127.     [Windows 16-bit] = 1    'the old-fashioned Win16 button
  128.     [Windows 32-bit] = 2    'the classic windows button
  129.     [Windows XP] = 3        'the new brand XP button totally owner-drawn
  130.     [Mac] = 4               'i suppose it looks exactly as a Mac button... i took the style from a GetRight skin!!!
  131.     [Java metal] = 5        'there are also other styles but not so different from windows one
  132.     [Netscape 6] = 6        'this is the button displayed in web-pages, it also appears in some java apps
  133.     [Simple Flat] = 7       'the standard flat button seen on toolbars
  134. End Enum
  135.  
  136. Public Enum ColorTypes
  137.     [Use Windows] = 1
  138.     [Custom] = 2
  139.     [Force Standard] = 3
  140. End Enum
  141.  
  142. 'events
  143. Public Event Click()
  144. Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  145. Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  146. Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  147. Public Event KeyPress(KeyAscii As Integer)
  148. Public Event KeyDown(KeyCode As Integer, Shift As Integer)
  149. Public Event KeyUp(KeyCode As Integer, Shift As Integer)
  150.  
  151. 'variables
  152. Private MyButtonType As ButtonTypes
  153. Private MyColorType As ColorTypes
  154.  
  155. Private He As Long  'the height of the button
  156. Private Wi As Long  'the width of the button
  157.  
  158. Private BackC As Long 'back color
  159. Private ForeC As Long 'fore color
  160.  
  161. Private elTex As String     'current text
  162. Private TextFont As StdFont 'current font
  163.  
  164. Private rc As RECT, rc2 As RECT, rc3 As RECT
  165. Private rgnNorm As Long
  166.  
  167. Private LastButton As Byte, LastKeyDown As Byte
  168. Private isEnabled As Boolean
  169. Private hasFocus As Boolean, showFocusR As Boolean
  170.  
  171. Private cFace As Long, cLight As Long, cHighLight As Long, cShadow As Long, cDarkShadow As Long, cText As Long
  172.  
  173. Private lastStat As Byte, TE As String 'used to avoid unnecessary repaints
  174.  
  175. Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
  176.     Call UserControl_Click
  177. End Sub
  178.  
  179. Private Sub UserControl_AmbientChanged(PropertyName As String)
  180. Call Redraw(lastStat, True)
  181. End Sub
  182.  
  183. Private Sub UserControl_Click()
  184. If (LastButton = 1) And (isEnabled = True) Then
  185.     Call Redraw(0, True) 'be sure that the normal status is drawn
  186.     UserControl.Refresh
  187.     RaiseEvent Click
  188. End If
  189. End Sub
  190.  
  191. Private Sub UserControl_DblClick()
  192. If LastButton = 1 Then
  193.     Call UserControl_MouseDown(1, 1, 1, 1)
  194. End If
  195. End Sub
  196.  
  197. Private Sub UserControl_GotFocus()
  198. hasFocus = True
  199. Call Redraw(lastStat, True)
  200. End Sub
  201.  
  202. Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  203. RaiseEvent KeyDown(KeyCode, Shift)
  204.  
  205. LastKeyDown = KeyCode
  206. If KeyCode = 32 Then 'spacebar pressed
  207.     Call UserControl_MouseDown(1, 1, 1, 1)
  208. ElseIf (KeyCode = 39) Or (KeyCode = 40) Then 'right and down arrows
  209.     SendKeys "{Tab}"
  210. ElseIf (KeyCode = 37) Or (KeyCode = 38) Then 'left and up arrows
  211.     SendKeys "+{Tab}"
  212. End If
  213. End Sub
  214.  
  215. Private Sub UserControl_KeyPress(KeyAscii As Integer)
  216. RaiseEvent KeyPress(KeyAscii)
  217. End Sub
  218.  
  219. Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
  220. RaiseEvent KeyUp(KeyCode, Shift)
  221.  
  222. If (KeyCode = 32) And (LastKeyDown = 32) Then 'spacebar pressed
  223.     Call UserControl_MouseUp(1, 1, 1, 1)
  224.     LastButton = 1
  225.     Call UserControl_Click
  226. End If
  227. End Sub
  228.  
  229. Private Sub UserControl_LostFocus()
  230. hasFocus = False
  231. Call Redraw(lastStat, True)
  232. End Sub
  233.  
  234. Private Sub UserControl_Initialize()
  235. LastButton = 1
  236. rc2.Left = 2: rc2.Top = 2
  237. Call SetColors
  238. End Sub
  239.  
  240. Private Sub UserControl_InitProperties()
  241.     isEnabled = True
  242.     showFocusR = True
  243.     Set TextFont = UserControl.Font
  244.     MyButtonType = [Windows 32-bit]
  245.     MyColorType = [Use Windows]
  246.     BackC = GetSysColor(COLOR_BTNFACE)
  247.     ForeC = GetSysColor(COLOR_BTNTEXT)
  248. End Sub
  249.  
  250. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  251. LastButton = Button
  252. If Button <> 2 Then Call Redraw(2, False)
  253. RaiseEvent MouseDown(Button, Shift, X, Y)
  254. End Sub
  255.  
  256. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  257. If Button < 2 Then
  258.     If X < 0 Or Y < 0 Or X > Wi Or Y > He Then
  259.         'we are outside the button
  260.         Call Redraw(0, False)
  261.     Else
  262.         'we are inside the button
  263.         If Button = 1 Then Call Redraw(2, False)
  264.     End If
  265. End If
  266. RaiseEvent MouseMove(Button, Shift, X, Y)
  267. End Sub
  268.  
  269. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  270. If Button <> 2 Then Call Redraw(0, False)
  271. RaiseEvent MouseUp(Button, Shift, X, Y)
  272. End Sub
  273.  
  274. '########## BUTTON PROPERTIES ##########
  275. Public Property Get BackColor() As OLE_COLOR
  276. BackColor = BackC
  277. End Property
  278. Public Property Let BackColor(ByVal theCol As OLE_COLOR)
  279. BackC = theCol
  280. Call SetColors
  281. Call Redraw(lastStat, True)
  282. PropertyChanged "BCOL"
  283. End Property
  284.  
  285. Public Property Get ForeColor() As OLE_COLOR
  286. ForeColor = ForeC
  287. End Property
  288. Public Property Let ForeColor(ByVal theCol As OLE_COLOR)
  289. ForeC = theCol
  290. Call SetColors
  291. Call Redraw(lastStat, True)
  292. PropertyChanged "FCOL"
  293. End Property
  294.  
  295. Public Property Get ButtonType() As ButtonTypes
  296. ButtonType = MyButtonType
  297. End Property
  298.  
  299. Public Property Let ButtonType(ByVal newValue As ButtonTypes)
  300. MyButtonType = newValue
  301. Call UserControl_Resize
  302. Call Redraw(0, True)
  303. PropertyChanged "BTYPE"
  304. End Property
  305.  
  306. Public Property Get Caption() As String
  307. Caption = elTex
  308. End Property
  309.  
  310. Public Property Let Caption(ByVal newValue As String)
  311. elTex = newValue
  312. Call SetAccessKeys
  313. Call Redraw(0, True)
  314. PropertyChanged "TX"
  315. End Property
  316.  
  317. Public Property Get Enabled() As Boolean
  318. Enabled = isEnabled
  319. End Property
  320.  
  321. Public Property Let Enabled(ByVal newValue As Boolean)
  322. isEnabled = newValue
  323. Call Redraw(0, True)
  324. UserControl.Enabled = isEnabled
  325. PropertyChanged "ENAB"
  326. End Property
  327.  
  328. Public Property Get Font() As Font
  329. Set Font = TextFont
  330. End Property
  331.  
  332. Public Property Set Font(ByRef newFont As Font)
  333. Set TextFont = newFont
  334. Set UserControl.Font = TextFont
  335. Call Redraw(0, True)
  336. PropertyChanged "FONT"
  337. End Property
  338.  
  339. 'is very common that a windows user uses custom color
  340. 'schemes to view his/her desktop, and is also very
  341. 'common that this color scheme has weird colors that
  342. 'would alter the nice look of my buttons.
  343. 'So if you want to force the button to use the windows
  344. 'standard colors you may change this property to "Force Standard"
  345.  
  346. 'UPDATE!!!
  347. 'you may now use your custom colors to display the button!!!
  348.  
  349. Public Property Get ColorScheme() As ColorTypes
  350. ColorScheme = MyColorType
  351. End Property
  352.  
  353. Public Property Let ColorScheme(ByVal newValue As ColorTypes)
  354. MyColorType = newValue
  355. Call SetColors
  356. Call Redraw(0, True)
  357. PropertyChanged "COLTYPE"
  358. End Property
  359.  
  360. Public Property Get ShowFocusRect() As Boolean
  361. ShowFocusRect = showFocusR
  362. End Property
  363.  
  364. Public Property Let ShowFocusRect(ByVal newValue As Boolean)
  365. showFocusR = newValue
  366. Call Redraw(lastStat, True)
  367. PropertyChanged "FOCUSR"
  368. End Property
  369.  
  370.  
  371. Public Property Get hwnd() As Long
  372.     hwnd = UserControl.hwnd
  373. End Property
  374.  
  375. '########## END OF PROPERTIES ##########
  376.  
  377. Private Sub UserControl_Resize()
  378.     He = UserControl.ScaleHeight
  379.     Wi = UserControl.ScaleWidth
  380.     rc.Bottom = He: rc.Right = Wi
  381.     rc2.Bottom = He: rc2.Right = Wi
  382.     rc3.Left = 4: rc3.Top = 4: rc3.Right = Wi - 4: rc3.Bottom = He - 4
  383.     
  384.     DeleteObject rgnNorm
  385.     Call MakeRegion
  386.     SetWindowRgn UserControl.hwnd, rgnNorm, True
  387.     
  388.     Call Redraw(0, True)
  389. End Sub
  390.  
  391. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  392.     MyButtonType = PropBag.ReadProperty("BTYPE", 2)
  393.     elTex = PropBag.ReadProperty("TX", "")
  394.     isEnabled = PropBag.ReadProperty("ENAB", True)
  395.     Set TextFont = PropBag.ReadProperty("FONT", UserControl.Font)
  396.     MyColorType = PropBag.ReadProperty("COLTYPE", 1)
  397.     showFocusR = PropBag.ReadProperty("FOCUSR", True)
  398.     BackC = PropBag.ReadProperty("BCOL", GetSysColor(COLOR_BTNFACE))
  399.     ForeC = PropBag.ReadProperty("FCOL", GetSysColor(COLOR_BTNTEXT))
  400.  
  401.     UserControl.Enabled = isEnabled
  402.     Set UserControl.Font = TextFont
  403.     Call SetColors
  404.     Call SetAccessKeys
  405.     Call Redraw(0, True)
  406.  
  407. End Sub
  408.  
  409. Private Sub UserControl_Terminate()
  410.     DeleteObject rgnNorm
  411. End Sub
  412.  
  413. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  414.     Call PropBag.WriteProperty("BTYPE", MyButtonType)
  415.     Call PropBag.WriteProperty("TX", elTex)
  416.     Call PropBag.WriteProperty("ENAB", isEnabled)
  417.     Call PropBag.WriteProperty("FONT", TextFont)
  418.     Call PropBag.WriteProperty("COLTYPE", MyColorType)
  419.     Call PropBag.WriteProperty("FOCUSR", showFocusR)
  420.     Call PropBag.WriteProperty("BCOL", BackC)
  421.     Call PropBag.WriteProperty("FCOL", ForeC)
  422. End Sub
  423.  
  424. Private Sub Redraw(ByVal curStat As Byte, ByVal Force As Boolean)
  425.  
  426. 'here is the CORE of the button, everything is drawn here
  427. 'it's not well commented but i think that everything is
  428. 'pretty self explanatory...
  429.  
  430. If Force = False Then 'check drawing redundancy
  431.     If (curStat = lastStat) And (TE = elTex) Then Exit Sub
  432. End If
  433.  
  434. If He = 0 Then Exit Sub 'we don't want errors
  435.  
  436. lastStat = curStat
  437. TE = elTex
  438.  
  439. Dim i As Long, stepXP1 As Single, XPface As Long
  440. Dim preFocusValue As Boolean
  441.  
  442. preFocusValue = hasFocus 'save this value to restore it later
  443. If hasFocus = True Then hasFocus = ShowFocusRect
  444.  
  445. With UserControl
  446. .Cls
  447. DrawRectangle 0, 0, Wi, He, cFace
  448.  
  449. If isEnabled = True Then
  450.     SetTextColor .hdc, cText 'restore font color
  451.     If curStat = 0 Then
  452. '#@#@#@#@#@# BUTTON NORMAL STATE #@#@#@#@#@#
  453.         Select Case MyButtonType
  454.             Case 1 'Windows 16-bit
  455.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  456.                 DrawLine 1, 0, Wi - 1, 0, cDarkShadow
  457.                 DrawLine 1, He - 1, Wi - 1, He - 1, cDarkShadow
  458.                 DrawLine 0, 1, 0, He - 1, cDarkShadow
  459.                 DrawLine Wi - 1, 1, Wi - 1, He - 1, cDarkShadow
  460.                 DrawRectangle 1, 1, Wi - 2, He - 2, cHighLight, True
  461.                 DrawRectangle 2, 2, Wi - 4, He - 4, cHighLight, True
  462.                 DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  463.                 DrawLine Wi - 3, 2, Wi - 3, He - 1, cShadow
  464.                 DrawLine 1, He - 2, Wi - 1, He - 2, cShadow
  465.                 DrawLine 2, He - 3, Wi - 2, He - 3, cShadow
  466.                 If hasFocus = True Then DrawFocusR
  467.             Case 2 'Windows 32-bit
  468.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  469.                 If (Ambient.DisplayAsDefault = True) And (showFocusR = True) Then
  470.                     DrawRectangle 1, 1, Wi - 2, He - 2, cHighLight, True
  471.                     DrawRectangle 2, 2, Wi - 4, He - 4, cLight, True
  472.                     DrawLine Wi - 2, 1, Wi - 2, He - 1, cDarkShadow
  473.                     DrawLine Wi - 3, 2, Wi - 3, He - 1, cShadow
  474.                     DrawLine 1, He - 2, Wi - 1, He - 2, cDarkShadow
  475.                     DrawLine 2, He - 3, Wi - 2, He - 3, cShadow
  476.                     If hasFocus = True Then DrawFocusR
  477.                     DrawRectangle 0, 0, Wi, He, cDarkShadow, True
  478.                 Else
  479.                     DrawRectangle 0, 0, Wi - 1, He - 1, cHighLight, True
  480.                     DrawRectangle 1, 1, Wi - 2, He - 2, cLight, True
  481.                     DrawLine Wi - 1, 0, Wi - 1, He, cDarkShadow
  482.                     DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  483.                     DrawLine 0, He - 1, Wi - 1, He - 1, cDarkShadow
  484.                     DrawLine 1, He - 2, Wi - 2, He - 2, cShadow
  485.                 End If
  486.             Case 3 'Windows XP
  487.                 stepXP1 = 25 / He
  488.                 XPface = ShiftColor(cFace, &H30, True)
  489.                 For i = 1 To He
  490.                     DrawLine 0, i, Wi, i, ShiftColor(XPface, -stepXP1 * i, True)
  491.                 Next
  492.                 SetTextColor UserControl.hdc, cText
  493.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  494.                 DrawLine 2, 0, Wi - 2, 0, &H733C00
  495.                 DrawLine 2, He - 1, Wi - 2, He - 1, &H733C00
  496.                 DrawLine 0, 2, 0, He - 2, &H733C00
  497.                 DrawLine Wi - 1, 2, Wi - 1, He - 2, &H733C00
  498.                 mSetPixel 1, 1, &H7B4D10
  499.                 mSetPixel 1, He - 2, &H7B4D10
  500.                 mSetPixel Wi - 2, 1, &H7B4D10
  501.                 mSetPixel Wi - 2, He - 2, &H7B4D10
  502.                 
  503.                 If (hasFocus = True) Or ((Ambient.DisplayAsDefault = True) And (showFocusR = True)) Then
  504.                     DrawRectangle 1, 2, Wi - 2, He - 4, &HE7AE8C, True
  505.                     DrawLine 2, He - 2, Wi - 2, He - 2, &HEF826B
  506.                     DrawLine 2, 1, Wi - 2, 1, &HFFE7CE
  507.                     DrawLine 1, 2, Wi - 1, 2, &HF7D7BD
  508.                     
  509.                     DrawLine 2, 3, 2, He - 3, &HF0D1B5
  510.                     DrawLine Wi - 3, 3, Wi - 3, He - 3, &HF0D1B5
  511.                 Else 'we do not draw the bevel always because the above code would repaint over it
  512.                     DrawLine 2, He - 2, Wi - 2, He - 2, ShiftColor(XPface, -&H30, True)
  513.                     DrawLine 1, He - 3, Wi - 2, He - 3, ShiftColor(XPface, -&H20, True)
  514.                     DrawLine Wi - 2, 2, Wi - 2, He - 2, ShiftColor(XPface, -&H24, True)
  515.                     DrawLine Wi - 3, 3, Wi - 3, He - 3, ShiftColor(XPface, -&H18, True)
  516.                     DrawLine 2, 1, Wi - 2, 1, ShiftColor(XPface, &H10, True)
  517.                     DrawLine 1, 2, Wi - 2, 2, ShiftColor(XPface, &HA, True)
  518.                     DrawLine 1, 2, 1, He - 2, ShiftColor(XPface, -&H5, True)
  519.                     DrawLine 2, 3, 2, He - 3, ShiftColor(XPface, -&HA, True)
  520.                 End If
  521.             Case 4 'Mac
  522.                 DrawRectangle 1, 1, Wi - 2, He - 2, cLight
  523.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  524.                 DrawLine 2, 0, Wi - 2, 0, cDarkShadow
  525.                 DrawLine 2, He - 1, Wi - 2, He - 1, cDarkShadow
  526.                 DrawLine 0, 2, 0, He - 2, cDarkShadow
  527.                 DrawLine Wi - 1, 2, Wi - 1, He - 2, cDarkShadow
  528.                 mSetPixel 1, 1, cDarkShadow
  529.                 mSetPixel 1, He - 2, cDarkShadow
  530.                 mSetPixel Wi - 2, 1, cDarkShadow
  531.                 mSetPixel Wi - 2, He - 2, cDarkShadow
  532.                 mSetPixel 1, 2, cFace
  533.                 mSetPixel 2, 1, cFace
  534.                 DrawLine 3, 2, Wi - 3, 2, cHighLight
  535.                 DrawLine 2, 2, 2, He - 3, cHighLight
  536.                 mSetPixel 3, 3, cHighLight
  537.                 DrawLine Wi - 3, 1, Wi - 3, He - 3, cFace
  538.                 DrawLine 1, He - 3, Wi - 3, He - 3, cFace
  539.                 mSetPixel Wi - 4, He - 4, cFace
  540.                 DrawLine Wi - 2, 3, Wi - 2, He - 2, cShadow
  541.                 DrawLine 3, He - 2, Wi - 2, He - 2, cShadow
  542.                 mSetPixel Wi - 3, He - 3, cShadow
  543.                 mSetPixel 2, He - 2, cFace
  544.                 mSetPixel 2, He - 3, cLight
  545.                 mSetPixel Wi - 2, 2, cFace
  546.                 mSetPixel Wi - 3, 2, cLight
  547.             Case 5 'Java
  548.                 .FontBold = True
  549.                 DrawRectangle 1, 1, Wi - 1, He - 1, ShiftColor(cFace, &HC)
  550.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  551.                 DrawRectangle 1, 1, Wi - 1, He - 1, cHighLight, True
  552.                 DrawRectangle 0, 0, Wi - 1, He - 1, ShiftColor(cShadow, -&H1A), True
  553.                 mSetPixel 1, He - 2, ShiftColor(cShadow, &H1A)
  554.                 mSetPixel Wi - 2, 1, ShiftColor(cShadow, &H1A)
  555.                 If hasFocus = True Then DrawRectangle (Wi - UserControl.TextWidth(elTex)) \ 2 - 3, (He - UserControl.TextHeight(elTex)) \ 2 - 1, UserControl.TextWidth(elTex) + 6, UserControl.TextHeight(elTex) + 2, &HCC9999, True
  556.                 .FontBold = TextFont.Bold
  557.             Case 6 'Netscape
  558.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  559.                 DrawRectangle 0, 0, Wi, He, ShiftColor(cLight, &H8), True
  560.                 DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cLight, &H8), True
  561.                 DrawLine Wi - 1, 0, Wi - 1, He, cShadow
  562.                 DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  563.                 DrawLine 0, He - 1, Wi, He - 1, cShadow
  564.                 DrawLine 1, He - 2, Wi - 1, He - 2, cShadow
  565.                 If hasFocus = True Then DrawFocusR
  566.              Case 7 'Flat
  567.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  568.                 DrawRectangle 0, 0, Wi, He, cHighLight, True
  569.                 DrawLine Wi - 1, 0, Wi - 1, He, cShadow
  570.                 DrawLine 0, He - 1, Wi, He - 1, cShadow
  571.                 If hasFocus = True Then DrawFocusR
  572.         End Select
  573.     ElseIf curStat = 2 Then
  574. '#@#@#@#@#@# BUTTON IS DOWN #@#@#@#@#@#
  575.         Select Case MyButtonType
  576.             Case 1 'Windows 16-bit
  577.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  578.                 DrawLine 1, 0, Wi - 1, 0, cDarkShadow
  579.                 DrawLine 1, He - 1, Wi - 1, He - 1, cDarkShadow
  580.                 DrawLine 0, 1, 0, He - 1, cDarkShadow
  581.                 DrawLine Wi - 1, 1, Wi - 1, He - 1, cDarkShadow
  582.                 DrawRectangle 1, 1, Wi - 2, He - 2, cShadow, True
  583.                 DrawRectangle 2, 2, Wi - 4, He - 4, cShadow, True
  584.                 DrawLine Wi - 2, 1, Wi - 2, He - 1, cHighLight
  585.                 DrawLine Wi - 3, 2, Wi - 3, He - 1, cHighLight
  586.                 DrawLine 1, He - 2, Wi - 1, He - 2, cHighLight
  587.                 DrawLine 2, He - 3, Wi - 2, He - 3, cHighLight
  588.                 If hasFocus = True Then DrawFocusR
  589.             Case 2 'Windows 32-bit
  590.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  591.                 
  592.                 If showFocusR = True Then
  593.                     DrawRectangle 0, 0, Wi, He, cDarkShadow, True
  594.                     DrawRectangle 1, 1, Wi - 2, He - 2, cShadow, True
  595.                     If hasFocus = True Then DrawFocusR
  596.                 Else
  597.                     DrawRectangle 0, 0, Wi - 1, He - 1, cDarkShadow, True
  598.                     DrawRectangle 1, 1, Wi - 2, He - 2, cShadow, True
  599.                     DrawLine Wi - 1, 0, Wi - 1, He, cHighLight
  600.                     DrawLine Wi - 2, 1, Wi - 2, He - 1, cLight
  601.                     DrawLine 0, He - 1, Wi - 1, He - 1, cHighLight
  602.                     DrawLine 1, He - 2, Wi - 2, He - 2, cLight
  603.                 End If
  604.             Case 3 'Windows XP
  605.                 stepXP1 = 15 / He
  606.                 XPface = ShiftColor(cFace, &H30, True)
  607.                 XPface = ShiftColor(XPface, -32, True)
  608.                 For i = 1 To He
  609.                     DrawLine 0, He - i, Wi, He - i, ShiftColor(XPface, -stepXP1 * i, True)
  610.                 Next
  611.                 SetTextColor .hdc, cText
  612.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  613.                 DrawLine 2, 0, Wi - 2, 0, &H733C00
  614.                 DrawLine 2, He - 1, Wi - 2, He - 1, &H733C00
  615.                 DrawLine 0, 2, 0, He - 2, &H733C00
  616.                 DrawLine Wi - 1, 2, Wi - 1, He - 2, &H733C00
  617.                 mSetPixel 1, 1, &H7B4D10
  618.                 mSetPixel 1, He - 2, &H7B4D10
  619.                 mSetPixel Wi - 2, 1, &H7B4D10
  620.                 mSetPixel Wi - 2, He - 2, &H7B4D10
  621.                 
  622.                 DrawLine 2, He - 2, Wi - 2, He - 2, ShiftColor(XPface, &H10, True)
  623.                 DrawLine 1, He - 3, Wi - 2, He - 3, ShiftColor(XPface, &HA, True)
  624.                 DrawLine Wi - 2, 2, Wi - 2, He - 2, ShiftColor(XPface, &H5, True)
  625.                 DrawLine Wi - 3, 3, Wi - 3, He - 3, XPface
  626.                 DrawLine 2, 1, Wi - 2, 1, ShiftColor(XPface, -&H20, True)
  627.                 DrawLine 1, 2, Wi - 2, 2, ShiftColor(XPface, -&H18, True)
  628.                 DrawLine 1, 2, 1, He - 2, ShiftColor(XPface, -&H20, True)
  629.                 DrawLine 2, 2, 2, He - 2, ShiftColor(XPface, -&H16, True)
  630.                 
  631. '                DrawRectangle 1, 2, Wi - 2, He - 4, &H31B2FF, True
  632. '                DrawLine 2, He - 2,Wi - 2, He - 2, &H96E7&
  633. '                DrawLine 2, 1,Wi - 2, 1, &HCEF3FF
  634. '                DrawLine 1, 2,Wi - 1, 2, &H8CDBFF
  635. '                DrawLine 2, 3,2, He - 3, &H6BCBFF
  636. '                DrawLine Wi - 3, 3,Wi - 3, He - 3, &H6BCBFF
  637.             Case 4 'Mac
  638.                 DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cShadow, -&H10)
  639.                 SetTextColor .hdc, cLight
  640.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  641.                 DrawLine 2, 0, Wi - 2, 0, cDarkShadow
  642.                 DrawLine 2, He - 1, Wi - 2, He - 1, cDarkShadow
  643.                 DrawLine 0, 2, 0, He - 2, cDarkShadow
  644.                 DrawLine Wi - 1, 2, Wi - 1, He - 2, cDarkShadow
  645.                 DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cShadow, -&H40), True
  646.                 DrawRectangle 2, 2, Wi - 4, He - 4, ShiftColor(cShadow, -&H20), True
  647.                 mSetPixel 2, 2, ShiftColor(cShadow, -&H40)
  648.                 mSetPixel 3, 3, ShiftColor(cShadow, -&H20)
  649.                 mSetPixel 1, 1, cDarkShadow
  650.                 mSetPixel 1, He - 2, cDarkShadow
  651.                 mSetPixel Wi - 2, 1, cDarkShadow
  652.                 mSetPixel Wi - 2, He - 2, cDarkShadow
  653.                 DrawLine Wi - 3, 1, Wi - 3, He - 3, cShadow
  654.                 DrawLine 1, He - 3, Wi - 2, He - 3, cShadow
  655.                 mSetPixel Wi - 4, He - 4, cShadow
  656.                 DrawLine Wi - 2, 3, Wi - 2, He - 2, ShiftColor(cShadow, -&H10)
  657.                 DrawLine 3, He - 2, Wi - 2, He - 2, ShiftColor(cShadow, -&H10)
  658.                 mSetPixel Wi - 2, He - 3, ShiftColor(cShadow, -&H20)
  659.                 mSetPixel Wi - 3, He - 2, ShiftColor(cShadow, -&H20)
  660.  
  661.                 mSetPixel 2, He - 2, ShiftColor(cShadow, -&H20)
  662.                 mSetPixel 2, He - 3, ShiftColor(cShadow, -&H10)
  663.                 mSetPixel 1, He - 3, ShiftColor(cShadow, -&H10)
  664.                 mSetPixel Wi - 2, 2, ShiftColor(cShadow, -&H20)
  665.                 mSetPixel Wi - 3, 2, ShiftColor(cShadow, -&H10)
  666.                 mSetPixel Wi - 3, 1, ShiftColor(cShadow, -&H10)
  667.             Case 5 'Java
  668.                 .FontBold = True
  669.                 DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cShadow, &H10), False
  670.                 DrawRectangle 0, 0, Wi - 1, He - 1, ShiftColor(cShadow, -&H1A), True
  671.                 DrawLine Wi - 1, 1, Wi - 1, He, cHighLight
  672.                 DrawLine 1, He - 1, Wi - 1, He - 1, cHighLight
  673.                 DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  674.                 If hasFocus = True Then DrawRectangle (Wi - UserControl.TextWidth(elTex)) \ 2 - 3, (He - UserControl.TextHeight(elTex)) \ 2 - 1, UserControl.TextWidth(elTex) + 6, UserControl.TextHeight(elTex) + 2, &HCC9999, True
  675.                 .FontBold = TextFont.Bold
  676.             Case 6 'Netscape
  677.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  678.                 DrawRectangle 0, 0, Wi, He, cShadow, True
  679.                 DrawRectangle 1, 1, Wi - 2, He - 2, cShadow, True
  680.                 DrawLine Wi - 1, 0, Wi - 1, He, ShiftColor(cLight, &H8)
  681.                 DrawLine Wi - 2, 1, Wi - 2, He - 1, ShiftColor(cLight, &H8)
  682.                 DrawLine 0, He - 1, Wi, He - 1, ShiftColor(cLight, &H8)
  683.                 DrawLine 1, He - 2, Wi - 1, He - 2, ShiftColor(cLight, &H8)
  684.                 If hasFocus = True Then DrawFocusR
  685.              Case 7 'Flat
  686.                 DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  687.                 DrawRectangle 0, 0, Wi, He, cShadow, True
  688.                 DrawLine Wi - 1, 0, Wi - 1, He, cHighLight
  689.                 DrawLine 0, He - 1, Wi - 1, He - 1, cHighLight
  690.                 If hasFocus = True Then DrawFocusR
  691.         End Select
  692.     End If
  693. Else
  694. '#~#~#~#~#~# DISABLED STATUS #~#~#~#~#~#
  695.     Select Case MyButtonType
  696.         Case 1 'Windows 16-bit
  697.             SetTextColor .hdc, cHighLight
  698.             DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  699.             SetTextColor .hdc, cShadow
  700.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  701.             DrawLine 1, 0, Wi - 1, 0, cDarkShadow
  702.             DrawLine 1, He - 1, Wi - 1, He - 1, cDarkShadow
  703.             DrawLine 0, 1, 0, He - 1, cDarkShadow
  704.             DrawLine Wi - 1, 1, Wi - 1, He - 1, cDarkShadow
  705.             DrawRectangle 1, 1, Wi - 2, He - 2, cHighLight, True
  706.             DrawRectangle 2, 2, Wi - 4, He - 4, cHighLight, True
  707.             DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  708.             DrawLine Wi - 3, 2, Wi - 3, He - 1, cShadow
  709.             DrawLine 1, He - 2, Wi - 1, He - 2, cShadow
  710.             DrawLine 2, He - 3, Wi - 2, He - 3, cShadow
  711.         Case 2 'Windows 32-bit
  712.             SetTextColor .hdc, cHighLight
  713.             DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  714.             SetTextColor .hdc, cShadow
  715.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  716.             DrawRectangle 0, 0, Wi - 1, He - 1, cHighLight, True
  717.             DrawRectangle 1, 1, Wi - 2, He - 2, cLight, True
  718.             DrawLine Wi - 1, 0, Wi - 1, He, cDarkShadow
  719.             DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  720.             DrawLine 0, He - 1, Wi - 1, He - 1, cDarkShadow
  721.             DrawLine 1, He - 2, Wi - 2, He - 2, cShadow
  722.         Case 3 'Windows XP
  723.             XPface = ShiftColor(cFace, &H30, True)
  724.             DrawRectangle 0, 0, Wi, He, ShiftColor(XPface, -&H18, True)
  725.             SetTextColor .hdc, ShiftColor(XPface, -&H68, True)
  726.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  727.             DrawLine 2, 0, Wi - 2, 0, ShiftColor(XPface, -&H54, True)
  728.             DrawLine 2, He - 1, Wi - 2, He - 1, ShiftColor(XPface, -&H54, True)
  729.             DrawLine 0, 2, 0, He - 2, ShiftColor(XPface, -&H54, True)
  730.             DrawLine Wi - 1, 2, Wi - 1, He - 2, ShiftColor(XPface, -&H54, True)
  731.             mSetPixel 1, 1, ShiftColor(XPface, -&H48, True)
  732.             mSetPixel 1, He - 2, ShiftColor(XPface, -&H48, True)
  733.             mSetPixel Wi - 2, 1, ShiftColor(XPface, -&H48, True)
  734.             mSetPixel Wi - 2, He - 2, ShiftColor(XPface, -&H48, True)
  735.         Case 4 'Mac
  736.             DrawRectangle 1, 1, Wi - 2, He - 2, cLight
  737.             SetTextColor .hdc, cHighLight
  738.             DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  739.             SetTextColor .hdc, cShadow
  740.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  741.             DrawLine 2, 0, Wi - 2, 0, cDarkShadow
  742.             DrawLine 2, He - 1, Wi - 2, He - 1, cDarkShadow
  743.             DrawLine 0, 2, 0, He - 2, cDarkShadow
  744.             DrawLine Wi - 1, 2, Wi - 1, He - 2, cDarkShadow
  745.             mSetPixel 1, 1, cDarkShadow
  746.             mSetPixel 1, He - 2, cDarkShadow
  747.             mSetPixel Wi - 2, 1, cDarkShadow
  748.             mSetPixel Wi - 2, He - 2, cDarkShadow
  749.             mSetPixel 1, 2, cFace
  750.             mSetPixel 2, 1, cFace
  751.             DrawLine 3, 2, Wi - 3, 2, cHighLight
  752.             DrawLine 2, 2, 2, He - 3, cHighLight
  753.             mSetPixel 3, 3, cHighLight
  754.             DrawLine Wi - 3, 1, Wi - 3, He - 3, cFace
  755.             DrawLine 1, He - 3, Wi - 3, He - 3, cFace
  756.             mSetPixel Wi - 4, He - 4, cFace
  757.             DrawLine Wi - 2, 3, Wi - 2, He - 2, cShadow
  758.             DrawLine 3, He - 2, Wi - 2, He - 2, cShadow
  759.             mSetPixel Wi - 3, He - 3, cShadow
  760.             mSetPixel 2, He - 2, cFace
  761.             mSetPixel 2, He - 3, cLight
  762.             mSetPixel Wi - 2, 2, cFace
  763.             mSetPixel Wi - 3, 2, cLight
  764.         Case 5 'Java
  765.             .FontBold = True
  766.             SetTextColor .hdc, cShadow
  767.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  768.             DrawRectangle 0, 0, Wi, He, cShadow, True
  769.             .FontBold = TextFont.Bold
  770.         Case 6 'Netscape
  771.             SetTextColor .hdc, cShadow
  772.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  773.             DrawRectangle 0, 0, Wi, He, ShiftColor(cLight, &H8), True
  774.             DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cLight, &H8), True
  775.             DrawLine Wi - 1, 0, Wi - 1, He, cShadow
  776.             DrawLine Wi - 2, 1, Wi - 2, He - 1, cShadow
  777.             DrawLine 0, He - 1, Wi, He - 1, cShadow
  778.             DrawLine 1, He - 2, Wi - 1, He - 2, cShadow
  779.         Case 7 'Flat
  780.             SetTextColor .hdc, cHighLight
  781.             DrawText .hdc, elTex, Len(elTex), rc2, DT_CENTERABS
  782.             SetTextColor .hdc, cShadow
  783.             DrawText .hdc, elTex, Len(elTex), rc, DT_CENTERABS
  784.             DrawRectangle 0, 0, Wi, He, cHighLight, True
  785.             DrawLine Wi - 1, 0, Wi - 1, He, cShadow
  786.             DrawLine 0, He - 1, Wi - 1, He - 1, cShadow
  787.     End Select
  788. End If
  789. End With
  790. 'restore focus value
  791. hasFocus = preFocusValue
  792.  
  793. End Sub
  794.  
  795. Private Sub DrawRectangle(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal Color As Long, Optional OnlyBorder As Boolean = False)
  796. 'this is my custom function to draw rectangles and frames
  797. 'it's faster and smoother than using the line method
  798.  
  799. Dim bRect As RECT
  800. Dim hBrush As Long
  801. Dim Ret As Long
  802.  
  803. bRect.Left = X
  804. bRect.Top = Y
  805. bRect.Right = X + Width
  806. bRect.Bottom = Y + Height
  807.  
  808. hBrush = CreateSolidBrush(Color)
  809.  
  810. If OnlyBorder = False Then
  811.     Ret = FillRect(UserControl.hdc, bRect, hBrush)
  812. Else
  813.     Ret = FrameRect(UserControl.hdc, bRect, hBrush)
  814. End If
  815.  
  816. Ret = DeleteObject(hBrush)
  817. End Sub
  818.  
  819. Private Sub DrawLine(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal Color As Long)
  820. 'a fast way to draw lines
  821. Dim pt As POINTAPI
  822.  
  823. UserControl.ForeColor = Color
  824. MoveToEx UserControl.hdc, X1, Y1, pt
  825. LineTo UserControl.hdc, X2, Y2
  826.  
  827. End Sub
  828.  
  829. Private Sub mSetPixel(ByVal X As Long, ByVal Y As Long, ByVal Color As Long)
  830.     Call SetPixel(UserControl.hdc, X, Y, Color)
  831. End Sub
  832.  
  833. Private Sub DrawFocusR()
  834.     SetTextColor UserControl.hdc, cText
  835.     DrawFocusRect UserControl.hdc, rc3
  836. End Sub
  837. Private Sub SetColors()
  838. 'this function sets the colors taken as a base to build
  839. 'all the other colors and styles.
  840.  
  841. If MyColorType = Custom Then
  842.     cFace = BackC
  843.     cText = ForeC
  844.     cShadow = ShiftColor(cFace, -&H40)
  845.     cLight = ShiftColor(cFace, &H1F)
  846.     cHighLight = ShiftColor(cFace, &H2F) 'it should be 3F but it looks too lighter
  847.     cDarkShadow = ShiftColor(cFace, -&HC0)
  848. ElseIf MyColorType = [Force Standard] Then
  849.     cFace = &HC0C0C0
  850.     cShadow = &H808080
  851.     cLight = &HDFDFDF
  852.     cDarkShadow = &H0
  853.     cHighLight = &HFFFFFF
  854.     cText = &H0
  855. Else
  856. 'if MyColorType is 1 or has not been set then use windows colors
  857.     cFace = GetSysColor(COLOR_BTNFACE)
  858.     cShadow = GetSysColor(COLOR_BTNSHADOW)
  859.     cLight = GetSysColor(COLOR_BTNLIGHT)
  860.     cDarkShadow = GetSysColor(COLOR_BTNDKSHADOW)
  861.     cHighLight = GetSysColor(COLOR_BTNHIGHLIGHT)
  862.     cText = GetSysColor(COLOR_BTNTEXT)
  863. End If
  864. End Sub
  865.  
  866. Private Sub MakeRegion()
  867. 'this function creates the regions to "cut" the UserControl
  868. 'so it will be transparent in certain areas
  869.  
  870. Dim rgn1 As Long, rgn2 As Long
  871.     
  872.     DeleteObject rgnNorm
  873.     rgnNorm = CreateRectRgn(0, 0, Wi, He)
  874.     rgn2 = CreateRectRgn(0, 0, 0, 0)
  875.     
  876. Select Case MyButtonType
  877.     Case 1 'Windows 16-bit
  878.         rgn1 = CreateRectRgn(0, 0, 1, 1)
  879.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  880.         DeleteObject rgn1
  881.         rgn1 = CreateRectRgn(0, He, 1, He - 1)
  882.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  883.         DeleteObject rgn1
  884.         rgn1 = CreateRectRgn(Wi, 0, Wi - 1, 1)
  885.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  886.         DeleteObject rgn1
  887.         rgn1 = CreateRectRgn(Wi, He, Wi - 1, He - 1)
  888.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  889.         DeleteObject rgn1
  890.     Case 3, 4 'Windows XP and Mac
  891.         rgn1 = CreateRectRgn(0, 0, 2, 1)
  892.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  893.         DeleteObject rgn1
  894.         rgn1 = CreateRectRgn(0, He, 2, He - 1)
  895.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  896.         DeleteObject rgn1
  897.         rgn1 = CreateRectRgn(Wi, 0, Wi - 2, 1)
  898.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  899.         DeleteObject rgn1
  900.         rgn1 = CreateRectRgn(Wi, He, Wi - 2, He - 1)
  901.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  902.         DeleteObject rgn1
  903.         rgn1 = CreateRectRgn(0, 1, 1, 2)
  904.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  905.         DeleteObject rgn1
  906.         rgn1 = CreateRectRgn(0, He - 1, 1, He - 2)
  907.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  908.         DeleteObject rgn1
  909.         rgn1 = CreateRectRgn(Wi, 1, Wi - 1, 2)
  910.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  911.         DeleteObject rgn1
  912.         rgn1 = CreateRectRgn(Wi, He - 1, Wi - 1, He - 2)
  913.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  914.         DeleteObject rgn1
  915.     Case 5 'Java
  916.         rgn1 = CreateRectRgn(0, He, 1, He - 1)
  917.         CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  918.         DeleteObject rgn1
  919.         rgn1 = CreateRectRgn(Wi, 0, Wi - 1, 1)
  920.         CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  921.         DeleteObject rgn1
  922. End Select
  923.  
  924. DeleteObject rgn2
  925. End Sub
  926.  
  927. Private Sub SetAccessKeys()
  928. 'this is a TRUE access keys parser
  929. 'i hate seeing how other programmers just check for the
  930. 'existence of the ampersand regardless of what follows it
  931.  
  932. Dim ampersandPos As Long
  933.  
  934. If Len(elTex) > 1 Then
  935.     ampersandPos = InStr(1, elTex, "&", vbTextCompare)
  936.     If (ampersandPos < Len(elTex)) And (ampersandPos > 0) Then
  937.         If Mid(elTex, ampersandPos + 1, 1) <> "&" Then 'if text is sonething like && then no access key should be assigned, so continue searching
  938.             UserControl.AccessKeys = LCase(Mid(elTex, ampersandPos + 1, 1))
  939.         Else 'do only a second pass to find another ampersand character
  940.             ampersandPos = InStr(ampersandPos + 2, elTex, "&", vbTextCompare)
  941.             If Mid(elTex, ampersandPos + 1, 1) <> "&" Then
  942.                 UserControl.AccessKeys = LCase(Mid(elTex, ampersandPos + 1, 1))
  943.             Else
  944.                 UserControl.AccessKeys = ""
  945.             End If
  946.         End If
  947.     Else
  948.         UserControl.AccessKeys = ""
  949.     End If
  950. Else
  951.     UserControl.AccessKeys = ""
  952. End If
  953. End Sub
  954.  
  955. Private Function ShiftColor(ByVal Color As Long, ByVal Value As Long, Optional isXP As Boolean = False) As Long
  956. 'this function will add or remove a certain color
  957. 'quantity and return the result
  958.  
  959. Dim Red As Long, Blue As Long, Green As Long
  960.  
  961. If isXP = False Then
  962.     Blue = ((Color \ &H10000) Mod &H100) + Value
  963. Else
  964.     Blue = ((Color \ &H10000) Mod &H100)
  965.     Blue = Blue + ((Blue * Value) \ &HC0)
  966. End If
  967. Green = ((Color \ &H100) Mod &H100) + Value
  968. Red = (Color And &HFF) + Value
  969.     
  970.     'check red
  971.     If Red < 0 Then
  972.         Red = 0
  973.     ElseIf Red > 255 Then
  974.         Red = 255
  975.     End If
  976.     'check green
  977.     If Green < 0 Then
  978.         Green = 0
  979.     ElseIf Green > 255 Then
  980.         Green = 255
  981.     End If
  982.     'check blue
  983.     If Blue < 0 Then
  984.         Blue = 0
  985.     ElseIf Blue > 255 Then
  986.         Blue = 255
  987.     End If
  988.  
  989. ShiftColor = RGB(Red, Green, Blue)
  990. End Function
  991.