home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD89128132000.psc / FBButton.ctl < prev    next >
Encoding:
Visual Basic user-defined control file  |  2000-08-14  |  30.3 KB  |  866 lines

  1. VERSION 5.00
  2. Begin VB.UserControl FlatButton 
  3.    AutoRedraw      =   -1  'True
  4.    ClientHeight    =   1395
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   1365
  8.    KeyPreview      =   -1  'True
  9.    ScaleHeight     =   93
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   91
  12.    ToolboxBitmap   =   "FBButton.ctx":0000
  13.    Begin VB.PictureBox picBuffer 
  14.       Appearance      =   0  'Flat
  15.       AutoRedraw      =   -1  'True
  16.       BorderStyle     =   0  'None
  17.       ForeColor       =   &H80000008&
  18.       Height          =   240
  19.       Left            =   120
  20.       ScaleHeight     =   240
  21.       ScaleWidth      =   240
  22.       TabIndex        =   2
  23.       Top             =   480
  24.       Visible         =   0   'False
  25.       Width           =   240
  26.    End
  27.    Begin VB.PictureBox picImage 
  28.       Appearance      =   0  'Flat
  29.       BackColor       =   &H00FFFFFF&
  30.       BorderStyle     =   0  'None
  31.       ForeColor       =   &H80000008&
  32.       Height          =   240
  33.       Left            =   120
  34.       ScaleHeight     =   240
  35.       ScaleWidth      =   240
  36.       TabIndex        =   1
  37.       Top             =   120
  38.       Visible         =   0   'False
  39.       Width           =   240
  40.    End
  41.    Begin VB.Timer tmrHighlight 
  42.       Enabled         =   0   'False
  43.       Interval        =   200
  44.       Left            =   120
  45.       Top             =   840
  46.    End
  47.    Begin VB.Label lblCaption 
  48.       Alignment       =   2  'Center
  49.       AutoSize        =   -1  'True
  50.       BackStyle       =   0  'Transparent
  51.       Caption         =   "lblCaption"
  52.       Height          =   195
  53.       Left            =   480
  54.       TabIndex        =   0
  55.       Top             =   120
  56.       Width           =   690
  57.    End
  58. End
  59. Attribute VB_Name = "FlatButton"
  60. Attribute VB_GlobalNameSpace = False
  61. Attribute VB_Creatable = True
  62. Attribute VB_PredeclaredId = False
  63. Attribute VB_Exposed = True
  64. Option Explicit
  65.  
  66. '========================================================================
  67. 'FlatButton Usage :
  68. '
  69. 'The use of this control is fairly straightforward, but the use of images
  70. 'warrants some explanation.
  71. '
  72. 'To use a picture you need to set the PicturehDC property of the FlatButton
  73. 'to the hDC property of a PictureBox (or other compatible hDC).
  74. '
  75. 'Example...
  76. 'Private Sub Form_Load()
  77. 'Me.FlatButton1.PicturehDC = Me.Picture1.hdc
  78. 'End Sub
  79. '
  80. 'The following picture box (Picture1) properties should be set...
  81. 'Appearance : 0 - Flat
  82. 'AutoRedraw : True
  83. 'AutoSize : True
  84. 'BackColor : Button Face
  85. 'BorderStyle : 0 - None
  86. 'Picture : Set to the picture you want to display on the FlatButton
  87. '
  88. '
  89. 'To show the full picture on the FlatButton set the PictureHeight and PictureWidth
  90. 'properties to the height and width of the picture in pixels. The default 16x16
  91. 'supports small icons.
  92. '
  93. '*** Any questions : please feel free to email wrhartel@camtech.net.au ***
  94. '
  95. '========================================================================
  96.  
  97. '========================================================================
  98. 'Notes : 6th August, 2000
  99. '
  100. 'The UserControl AccessKeyPress event does not fire if the access key of one
  101. 'of the UserControl's constituent control's access keys is pressed. As such,
  102. 'when the lblCaption access key is pressed, the UserControl only receives an
  103. 'EnterFocus event (as lblCaption takes the focus), and the UserControl does
  104. 'not receive an AccessKeyPress event.
  105. '
  106. 'To get the FlatButton user control to emulate CommandButton behaviour w.r.t.
  107. 'access keys (i.e., generate a click event when the user presses 'ALT' plus
  108. 'one of the control's access keys) it would be necessary to disable the
  109. 'UseMnemonic property of lblCaption, and in code REMOVE any '&' characters
  110. 'from the lblCaption caption property and assign them as UserControl Access
  111. 'keys. Next a line would need to be drawn underneath the appropriate characters
  112. 'in lblCaption by some other means (so the control user would still know what
  113. 'the access keys were). Now if the user presses 'ALT' plus an access key the
  114. 'UserControl would receive an AccessKeyPress event since lblCaption no longer
  115. 'has 'real' access keys.
  116. '
  117. 'Without this code, and leaving the UseMnemonic property of lblCaption set to
  118. 'True, a user pressing 'ALT' plus an access key will tab to the UserControl
  119. 'and give it focus, but will not generate a click event. Since this is not
  120. 'a major concern (just a small detail) this code has not yet been written.
  121. '========================================================================
  122.  
  123. '========================================================================
  124. 'DLL Base Address
  125. '========================================================================
  126. '&H6880000, based on 16M (16,777,216 or &H1000000) plus 1416 * 16K
  127.  
  128. '========================================================================
  129. 'Windows API Types
  130. '========================================================================
  131. Private Type POINTAPI
  132.     x As Long
  133.     y As Long
  134. End Type
  135.  
  136. Private Type RECT
  137.     Left As Long
  138.     Top As Long
  139.     Right As Long
  140.     Bottom As Long
  141. End Type
  142.  
  143. '========================================================================
  144. 'Windows API Declarations
  145. '========================================================================
  146. Private Declare Function WindowFromPoint Lib "user32.dll" (ByVal xPoint _
  147. As Long, ByVal yPoint As Long) As Long
  148. Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) _
  149. As Long
  150. Private Declare Function DrawEdge Lib "user32.dll" (ByVal hdc As Long, _
  151. qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
  152. Private Declare Function DrawFocusRect Lib "user32.dll" (ByVal hdc As Long, _
  153. lpRect As RECT) As Long
  154. Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, _
  155. ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As _
  156. Long, ByVal hSrcDC As Long, ByVal XSrc As Long, ByVal YSrc As Long, _
  157. ByVal dwRop As Long) As Long
  158.     
  159. '========================================================================
  160. 'Enumerations
  161. '========================================================================
  162. Public Enum fbAlignment
  163.     fbLeft = 0
  164.     fbRight
  165.     fbCenter
  166. End Enum
  167.     
  168. '========================================================================
  169. 'Constants
  170. '========================================================================
  171. Private Const BDR_RAISEDINNER As Long = &H4
  172. Private Const BDR_SUNKENOUTER As Long = &H2
  173. Private Const BDR_RAISED = &H5
  174. Private Const BDR_SUNKEN = &HA
  175. Private Const BDR_MOUSEOVER As Long = BDR_RAISEDINNER
  176. Private Const BDR_MOUSEDOWN As Long = BDR_SUNKENOUTER
  177. Private Const BDR_MOUSEOVER_HB As Long = BDR_RAISED
  178. Private Const BDR_MOUSEDOWN_HB As Long = BDR_SUNKEN
  179. Private Const BF_BOTTOM As Long = &H8
  180. Private Const BF_LEFT As Long = &H1
  181. Private Const BF_RIGHT As Long = &H4
  182. Private Const BF_TOP As Long = &H2
  183. 'Bitwise comparison
  184. Private Const BF_RECT As Long = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
  185. Private Const DUD_VALUE As Integer = -1
  186. Private Const NOT_APPLY_ALL As Integer = 0
  187. Private Const APPLY_ALL As Integer = 1
  188. Private Const INIT_PROP_FLAG As Integer = 0
  189. Private Const READ_PROP_FLAG As Integer = 1
  190. Private Const FORCE_FLATTEN As Integer = 1
  191. Private Const FOCUS_RECT_OFFSET As Integer = 4
  192.     
  193. Private Const mDef_lngForeColor As Long = vbBlack
  194. Private Const mDef_lngBackColor As Long = vbButtonFace
  195. Private Const mDef_lngHoverColor As Long = vbHighlight
  196. Private Const mDef_fbAlignment As Integer = fbAlignment.fbCenter
  197. Private Const mDef_booHasBorder As Boolean = False
  198. Private Const mDef_strCaption As String = "FlatButton"
  199. Private Const mDef_booEnabled As Boolean = True
  200. Private Const mDef_booHasFocusRect As Boolean = True
  201. Private Const mDef_booAlignPicLeft As Boolean = True
  202. Private Const mDef_intPictureWidth As Integer = 16
  203. Private Const mDef_intPictureHeight As Integer = mDef_intPictureWidth
  204. Private Const mDef_lngPicturehDC As Long = 0
  205. Private Const mDef_booHasPicture As Boolean = False
  206. Private Const mDef_booHasCaption As Boolean = True
  207.     
  208. Private Const FORECOLOR_PROPERTY_NAME As String = "ForeColor"
  209. Private Const ALIGNMENT_PROPERTY_NAME As String = "Alignment"
  210. Private Const HOVERCOLOR_PROPERTY_NAME As String = "HoverColor"
  211. Private Const ENABLED_PROPERTY_NAME As String = "Enabled"
  212. Private Const FONT_PROPERTY_NAME As String = "Font"
  213. Private Const HASFOCUSRECT_PROPERTY_NAME As String = "HasFocusRect"
  214. Private Const CAPTION_PROPERTY_NAME As String = "Caption"
  215. Private Const BACKCOLOR_PROPERTY_NAME As String = "BackColor"
  216. Private Const HASBORDER_PROPERTY_NAME As String = "HasBorder"
  217. Private Const ALIGNPICLEFT_PROPERTY_NAME As String = "AlignPicLeft"
  218. Private Const PICTUREWIDTH_PROPERTY_NAME As String = "PictureWidth"
  219. Private Const PICTUREHEIGHT_PROPERTY_NAME As String = "PictureHeight"
  220. Private Const HASPICTURE_PROPERTY_NAME As String = "HasPicture"
  221. Private Const HASCAPTION_PROPERTY_NAME As String = "HasCaption"
  222. Private Const PICTUREHDC_PROPERTY_NAME As String = "PicturehDC"
  223.     
  224. '========================================================================
  225. 'Variables
  226. '========================================================================
  227. Private mprop_lngForeColor As Long
  228. Private mProp_lngHoverColor As Long
  229. Private mProp_lngBackColor As Long
  230. Private mProp_fbAlignment As fbAlignment
  231. Private mProp_booHasBorder As Boolean
  232. Private mProp_strCaption As String
  233. Private mProp_booEnabled As Boolean
  234. Private mProp_booHasFocusRect As Boolean
  235. Private mProp_fntFont As StdFont
  236. Private mProp_booAlignPicLeft As Boolean
  237. Private mProp_intPictureHeight As Integer
  238. Private mProp_intPictureWidth As Integer
  239. Private mProp_lngPicturehDC As Long
  240. Private mProp_booHasPicture As Boolean
  241. Private mProp_booHasCaption As Boolean
  242.  
  243. Private mbooHasCapture As Boolean
  244. Private mpntLabelPos As POINTAPI
  245. Private mpntOldSize As POINTAPI
  246. Private mpntPicPos As POINTAPI
  247. Private intPropertiesKnown As Integer
  248.  
  249. Event Click()
  250.  
  251. '========================================================================
  252. 'UserControl Enter/Exit Focus
  253. '========================================================================
  254. Private Sub UserControl_EnterFocus()
  255.  
  256. Dim rctFocus As RECT
  257.  
  258. If Not mProp_booHasFocusRect Then Exit Sub
  259.  
  260. 'Draw a focus rectangle
  261. rctFocus.Left = FOCUS_RECT_OFFSET
  262. rctFocus.Top = FOCUS_RECT_OFFSET
  263. rctFocus.Right = ScaleWidth - FOCUS_RECT_OFFSET
  264. rctFocus.Bottom = ScaleHeight - FOCUS_RECT_OFFSET
  265. DrawFocusRect hdc, rctFocus
  266.  
  267. End Sub
  268.  
  269. Private Sub UserControl_ExitFocus()
  270. 'Remove the focus rectangle
  271. If mProp_booHasFocusRect Then Line (FOCUS_RECT_OFFSET, FOCUS_RECT_OFFSET)- _
  272. (ScaleWidth - FOCUS_RECT_OFFSET - 1, ScaleHeight - FOCUS_RECT_OFFSET - 1), _
  273. mProp_lngBackColor, B
  274. End Sub
  275.  
  276. '========================================================================
  277. 'UserControl Initialize/InitProprties
  278. '========================================================================
  279. Private Sub UserControl_Initialize()
  280. tmrHighlight.Enabled = False
  281. tmrHighlight.Interval = 100
  282. End Sub
  283.  
  284. Private Sub UserControl_InitProperties()
  285.  
  286. UserControl.Width = 1095
  287. UserControl.Height = 390
  288.  
  289. mprop_lngForeColor = mDef_lngForeColor
  290. mProp_fbAlignment = mDef_fbAlignment
  291. mProp_booAlignPicLeft = mDef_booAlignPicLeft
  292. mProp_intPictureWidth = mDef_intPictureWidth
  293. mProp_intPictureHeight = mDef_intPictureHeight
  294. mProp_lngPicturehDC = mDef_lngPicturehDC
  295. mProp_booHasCaption = mDef_booHasCaption
  296. mProp_booHasPicture = mDef_booHasPicture
  297. mProp_booHasBorder = mDef_booHasBorder
  298. mProp_lngBackColor = mDef_lngBackColor
  299. mProp_strCaption = mDef_strCaption
  300. mProp_booEnabled = mDef_booEnabled
  301. mProp_booHasFocusRect = mDef_booHasFocusRect
  302. mProp_lngHoverColor = mDef_lngHoverColor
  303.  
  304. Set mProp_fntFont = Ambient.Font
  305. intPropertiesKnown = 1
  306.  
  307. ApplyAllProperties INIT_PROP_FLAG
  308.  
  309. End Sub
  310.  
  311. '========================================================================
  312. 'UserControl Property Bag Stuff
  313. '========================================================================
  314. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  315.  
  316. With PropBag
  317.     mprop_lngForeColor = .ReadProperty(FORECOLOR_PROPERTY_NAME, mDef_lngForeColor)
  318.     mProp_fbAlignment = .ReadProperty(ALIGNMENT_PROPERTY_NAME, mDef_fbAlignment)
  319.     mProp_booAlignPicLeft = .ReadProperty(ALIGNPICLEFT_PROPERTY_NAME, mDef_booAlignPicLeft)
  320.     mProp_intPictureWidth = .ReadProperty(PICTUREWIDTH_PROPERTY_NAME, mDef_intPictureWidth)
  321.     mProp_intPictureHeight = .ReadProperty(PICTUREHEIGHT_PROPERTY_NAME, mDef_intPictureHeight)
  322.     mProp_lngPicturehDC = .ReadProperty(PICTUREHDC_PROPERTY_NAME, mDef_lngPicturehDC)
  323.     mProp_booHasPicture = .ReadProperty(HASPICTURE_PROPERTY_NAME, mDef_booHasPicture)
  324.     mProp_booHasCaption = .ReadProperty(HASCAPTION_PROPERTY_NAME, mDef_booHasCaption)
  325.     mProp_booHasBorder = .ReadProperty(HASBORDER_PROPERTY_NAME, mDef_booHasBorder)
  326.     mProp_lngBackColor = .ReadProperty(BACKCOLOR_PROPERTY_NAME, mDef_lngBackColor)
  327.     mProp_strCaption = .ReadProperty(CAPTION_PROPERTY_NAME, mDef_strCaption)
  328.     mProp_booEnabled = .ReadProperty(ENABLED_PROPERTY_NAME, mDef_booEnabled)
  329.     mProp_booHasFocusRect = .ReadProperty(HASFOCUSRECT_PROPERTY_NAME, mDef_booHasFocusRect)
  330.     Set mProp_fntFont = .ReadProperty(FONT_PROPERTY_NAME, Ambient.Font)
  331.     mProp_lngHoverColor = .ReadProperty(HOVERCOLOR_PROPERTY_NAME, mDef_lngHoverColor)
  332. End With
  333.  
  334. intPropertiesKnown = 1
  335.  
  336. ApplyAllProperties READ_PROP_FLAG
  337.  
  338. If Ambient.UserMode Then 'Runtime only
  339.     If mProp_booHasBorder Then
  340.         ApplyBorder FORCE_FLATTEN
  341.     End If
  342.     tmrHighlight.Enabled = True
  343. End If
  344.  
  345. End Sub
  346.  
  347. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  348. With PropBag
  349.     .WriteProperty FORECOLOR_PROPERTY_NAME, mprop_lngForeColor, mDef_lngForeColor
  350.     .WriteProperty ALIGNMENT_PROPERTY_NAME, mProp_fbAlignment, mDef_fbAlignment
  351.     .WriteProperty ALIGNPICLEFT_PROPERTY_NAME, mProp_booAlignPicLeft, mDef_booAlignPicLeft
  352.     .WriteProperty PICTUREWIDTH_PROPERTY_NAME, mProp_intPictureWidth, mDef_intPictureWidth
  353.     .WriteProperty PICTUREHEIGHT_PROPERTY_NAME, mProp_intPictureHeight, mDef_intPictureHeight
  354.     .WriteProperty PICTUREHDC_PROPERTY_NAME, mProp_lngPicturehDC, mDef_lngPicturehDC
  355.     .WriteProperty HASPICTURE_PROPERTY_NAME, mProp_booHasPicture, mDef_booHasPicture
  356.     .WriteProperty HASCAPTION_PROPERTY_NAME, mProp_booHasCaption, mDef_booHasCaption
  357.     .WriteProperty HASBORDER_PROPERTY_NAME, mProp_booHasBorder, mDef_booHasBorder
  358.     .WriteProperty BACKCOLOR_PROPERTY_NAME, mProp_lngBackColor, mDef_lngBackColor
  359.     .WriteProperty CAPTION_PROPERTY_NAME, mProp_strCaption, mDef_strCaption
  360.     .WriteProperty ENABLED_PROPERTY_NAME, mProp_booEnabled, mDef_booEnabled
  361.     .WriteProperty HASFOCUSRECT_PROPERTY_NAME, mProp_booHasFocusRect, mDef_booHasFocusRect
  362.     .WriteProperty FONT_PROPERTY_NAME, mProp_fntFont, Ambient.Font
  363.     .WriteProperty HOVERCOLOR_PROPERTY_NAME, mProp_lngHoverColor, mDef_lngHoverColor
  364. End With
  365. End Sub
  366.  
  367. '========================================================================
  368. 'Key Events
  369. '========================================================================
  370. Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
  371. RaiseEvent Click
  372. End Sub
  373.  
  374. Private Sub UserControl_KeyPress(KeyAscii As Integer)
  375. If KeyAscii = vbKeySpace Or KeyAscii = vbKeyReturn Then
  376.     RaiseEvent Click
  377. End If
  378. End Sub
  379.  
  380. Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  381. If KeyCode = vbKeySpace Or KeyCode = vbKeyReturn Then
  382.     UserControl_MouseDown vbLeftButton, DUD_VALUE, DUD_VALUE, DUD_VALUE
  383. End If
  384. End Sub
  385.  
  386. Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
  387. If KeyCode = vbKeySpace Or KeyCode = vbKeyReturn Then
  388.     UserControl_MouseUp DUD_VALUE, DUD_VALUE, DUD_VALUE, DUD_VALUE
  389. End If
  390. End Sub
  391.  
  392. '========================================================================
  393. 'MouseDown Events
  394. '========================================================================
  395. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  396.  
  397. Const OFFSET As Integer = 1
  398. Dim rctBtn As RECT
  399.  
  400. If Button = vbLeftButton Then
  401.     tmrHighlight.Enabled = False
  402.     lblCaption.Left = mpntLabelPos.x + OFFSET
  403.     lblCaption.Top = mpntLabelPos.y + OFFSET
  404.     picImage.Move mpntPicPos.x + OFFSET, mpntPicPos.y + OFFSET, _
  405.     picImage.Width, picImage.Height
  406.     Line (0, 0)-(Width, Height), mProp_lngBackColor, B
  407.     rctBtn.Left = 0
  408.     rctBtn.Top = 0
  409.     rctBtn.Right = ScaleWidth
  410.     rctBtn.Bottom = ScaleHeight
  411.     If mProp_booHasBorder = True Then
  412.         DrawEdge hdc, rctBtn, BDR_MOUSEDOWN_HB, BF_RECT
  413.     Else
  414.         DrawEdge hdc, rctBtn, BDR_MOUSEDOWN, BF_RECT
  415.     End If
  416. End If
  417.  
  418. End Sub
  419.  
  420. Private Sub lblCaption_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  421. UserControl_MouseDown Button, Shift, x, y
  422. End Sub
  423.  
  424. Private Sub picImage_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  425. UserControl_MouseDown Button, Shift, x, y
  426. End Sub
  427.  
  428. '========================================================================
  429. 'MouseUp Events
  430. '========================================================================
  431. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  432.  
  433. Dim pntCursor As POINTAPI
  434.  
  435. lblCaption.Left = mpntLabelPos.x
  436. lblCaption.Top = mpntLabelPos.y
  437. picImage.Move mpntPicPos.x, mpntPicPos.y, picImage.Width, picImage.Height
  438. GetCursorPos pntCursor
  439. If WindowFromPoint(pntCursor.x, pntCursor.y) = hWnd Or _
  440. WindowFromPoint(pntCursor.x, pntCursor.y) = picImage.hWnd Or _
  441. mProp_booHasBorder Then
  442.     ApplyBorder
  443.     mbooHasCapture = True
  444. Else
  445.     Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), mProp_lngBackColor, B
  446.     mbooHasCapture = False
  447. End If
  448.  
  449. tmrHighlight.Enabled = True
  450.  
  451. RaiseEvent Click
  452.  
  453. End Sub
  454.  
  455. Private Sub lblCaption_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  456. UserControl_MouseUp Button, Shift, x, y
  457. End Sub
  458.  
  459. Private Sub picImage_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  460. UserControl_MouseUp Button, Shift, x, y
  461. End Sub
  462.  
  463. '========================================================================
  464. 'Other UserControl Events
  465. '========================================================================
  466. Private Sub UserControl_Resize()
  467.  
  468. If intPropertiesKnown = 0 Then Exit Sub
  469.  
  470. Cls
  471. RedrawControl
  472.  
  473. 'Design-time or Has Border
  474. If Not Ambient.UserMode Or mProp_booHasBorder Then
  475.     ApplyBorder FORCE_FLATTEN
  476. End If
  477.  
  478. End Sub
  479.  
  480. Private Sub UserControl_AmbientChanged(PropertyName As String)
  481. If UCase$(PropertyName) = "BACKCOLOR" Then
  482.     BackColor = Ambient.BackColor
  483. End If
  484. End Sub
  485.  
  486. '========================================================================
  487. 'Other Object Events
  488. '========================================================================
  489. Private Sub picImage_Paint()
  490.  
  491. If mProp_booEnabled = True Then
  492.     'Draw picture
  493.     BitBlt picImage.hdc, 0, 0, mProp_intPictureWidth, _
  494.     mProp_intPictureHeight, mProp_lngPicturehDC, 0, 0, vbSrcCopy
  495. Else
  496.     'Draw picture (incase button begins its life disabled)
  497.     BitBlt picImage.hdc, 0, 0, mProp_intPictureWidth, _
  498.     mProp_intPictureHeight, mProp_lngPicturehDC, 0, 0, vbSrcCopy
  499.     'Draw dimmed (darker) picture
  500.     BitBlt picImage.hdc, 0, 0, mProp_intPictureWidth, _
  501.     mProp_intPictureHeight, picBuffer.hdc, 0, 0, vbSrcAnd
  502. End If
  503.  
  504. End Sub
  505.  
  506. Private Sub tmrHighlight_Timer()
  507.  
  508. Dim pntCursor As POINTAPI
  509.  
  510. GetCursorPos pntCursor
  511.  
  512. 'If mouse is over this control
  513. If WindowFromPoint(pntCursor.x, pntCursor.y) = hWnd Or _
  514. WindowFromPoint(pntCursor.x, pntCursor.y) = picImage.hWnd Then
  515.     If Not mbooHasCapture Then
  516.         ApplyBorder
  517.         lblCaption.ForeColor = mProp_lngHoverColor
  518.         mbooHasCapture = True
  519.     End If
  520. Else
  521.     If mbooHasCapture Then
  522.         'Remove thick edge
  523.         Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), mProp_lngBackColor, B
  524.         lblCaption.ForeColor = mprop_lngForeColor
  525.         mbooHasCapture = False
  526.     End If
  527. End If
  528.  
  529. End Sub
  530.  
  531. '========================================================================
  532. 'Properties requiring Apply**** to be called
  533. '========================================================================
  534. Public Property Get HasBorder() As Boolean
  535. Attribute HasBorder.VB_Description = "Sets/returns whether the FlatButton is drawn with a border at runtime."
  536.     HasBorder = mProp_booHasBorder
  537. End Property
  538.  
  539. Public Property Let HasBorder(ByVal booNewValue As Boolean)
  540. If Ambient.UserMode Then 'Design-time only
  541.     Err.Raise 383
  542. Else
  543.     mProp_booHasBorder = booNewValue
  544.     PropertyChanged HASBORDER_PROPERTY_NAME
  545. End If
  546. End Property
  547.  
  548. Public Property Get BackColor() As OLE_COLOR
  549. Attribute BackColor.VB_Description = "Returns/sets the background color used to display text and graphics in an object."
  550. BackColor = mProp_lngBackColor
  551. End Property
  552.  
  553. Public Property Let BackColor(ByVal oleNewValue As OLE_COLOR)
  554. mProp_lngBackColor = oleNewValue
  555. ApplyBackColor
  556. ApplyBorder
  557. PropertyChanged BACKCOLOR_PROPERTY_NAME
  558. End Property
  559.  
  560. Public Property Get Alignment() As fbAlignment
  561. Attribute Alignment.VB_Description = "Returns/sets the FlatButton control's caption alignment."
  562. Alignment = mProp_fbAlignment
  563. End Property
  564.  
  565. Public Property Let Alignment(ByVal fbNewValue As fbAlignment)
  566. mProp_fbAlignment = fbNewValue
  567. ApplyCaption
  568. PropertyChanged ALIGNMENT_PROPERTY_NAME
  569. End Property
  570.  
  571. Public Property Get Caption() As String
  572. Attribute Caption.VB_Description = "Returns/sets the text displayed in an object's title bar or below an object's icon."
  573. Caption = mProp_strCaption
  574. End Property
  575.  
  576. Public Property Let Caption(ByVal strNewValue As String)
  577. mProp_strCaption = strNewValue
  578. ApplyCaption
  579. PropertyChanged CAPTION_PROPERTY_NAME
  580. End Property
  581.  
  582. Public Property Get HasFocusRect() As Boolean
  583. Attribute HasFocusRect.VB_Description = "Read-only at runtime. Set/returns whether a focus rectangle is drawn on the FlatButton when it has focus."
  584. HasFocusRect = mProp_booHasFocusRect
  585. End Property
  586.  
  587. Public Property Let HasFocusRect(ByVal booNewValue As Boolean)
  588. If Ambient.UserMode Then 'Design-time only
  589.     Err.Raise 383
  590. Else
  591.     mProp_booHasFocusRect = booNewValue
  592.     PropertyChanged HASFOCUSRECT_PROPERTY_NAME
  593. End If
  594. End Property
  595.  
  596. Public Property Get Font() As StdFont
  597. Attribute Font.VB_Description = "Returns a Font object."
  598. Set Font = mProp_fntFont
  599. End Property
  600.  
  601. Public Property Set Font(ByVal fntNewValue As StdFont)
  602. Set mProp_fntFont = fntNewValue
  603. ApplyFont
  604. PropertyChanged FONT_PROPERTY_NAME
  605. End Property
  606.  
  607. Public Property Get Enabled() As Boolean
  608. Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
  609. Attribute Enabled.VB_UserMemId = -514
  610. Enabled = mProp_booEnabled
  611. End Property
  612.  
  613. Public Property Let Enabled(ByVal booNewValue As Boolean)
  614. mProp_booEnabled = booNewValue
  615. ApplyEnabled
  616. PropertyChanged ENABLED_PROPERTY_NAME
  617. End Property
  618.  
  619. Public Property Get HoverColor() As OLE_COLOR
  620. Attribute HoverColor.VB_Description = "Returns/sets the color of the FlatButton caption text when the mouse pointer is over the control."
  621. HoverColor = mProp_lngHoverColor
  622. End Property
  623.  
  624. Public Property Let HoverColor(ByVal oleNewValue As OLE_COLOR)
  625. mProp_lngHoverColor = oleNewValue
  626. PropertyChanged HOVERCOLOR_PROPERTY_NAME
  627. End Property
  628.  
  629. Public Property Get ForeColor() As OLE_COLOR
  630. Attribute ForeColor.VB_Description = "Returns/sets the FlatButtons foreground color which is used to display the button caption."
  631. ForeColor = mprop_lngForeColor
  632. End Property
  633.  
  634. Public Property Let ForeColor(ByVal oleNewValue As OLE_COLOR)
  635. mprop_lngForeColor = oleNewValue
  636. ApplyCaption
  637. PropertyChanged FORECOLOR_PROPERTY_NAME
  638. End Property
  639.  
  640. '========================================================================
  641. 'Properties requiring UserControl_Resize to be called
  642. '========================================================================
  643. Public Property Get HasPicture() As Boolean
  644. Attribute HasPicture.VB_Description = "Returns/sets whether a picture is used on the FlatButton."
  645. HasPicture = mProp_booHasPicture
  646. End Property
  647.  
  648. Public Property Let HasPicture(ByVal booNewValue As Boolean)
  649. mProp_booHasPicture = booNewValue
  650. PropertyChanged HASPICTURE_PROPERTY_NAME
  651. UserControl_Resize
  652. End Property
  653.  
  654. Public Property Get HasCaption() As Boolean
  655. Attribute HasCaption.VB_Description = "Returns/sets whether a text caption is used on the FlatButton."
  656. HasCaption = mProp_booHasCaption
  657. End Property
  658.  
  659. Public Property Let HasCaption(ByVal booNewValue As Boolean)
  660. mProp_booHasCaption = booNewValue
  661. PropertyChanged HASCAPTION_PROPERTY_NAME
  662. UserControl_Resize
  663. End Property
  664.  
  665. Public Property Get AlignPicLeft() As Boolean
  666. Attribute AlignPicLeft.VB_Description = "Specifies whether to align the FlatButton's picture to the left hand side of the button."
  667. AlignPicLeft = mProp_booAlignPicLeft
  668. End Property
  669.  
  670. Public Property Let AlignPicLeft(ByVal booNewValue As Boolean)
  671. mProp_booAlignPicLeft = booNewValue
  672. PropertyChanged ALIGNPICLEFT_PROPERTY_NAME
  673. UserControl_Resize
  674. End Property
  675.  
  676. Public Property Get PicturehDC() As Long
  677. Attribute PicturehDC.VB_Description = "Returns/sets the handle to a device context used as the source device context for the FlatButton picture."
  678. PicturehDC = mProp_lngPicturehDC
  679. End Property
  680.  
  681. Public Property Let PicturehDC(ByVal lngNewValue As Long)
  682. mProp_lngPicturehDC = lngNewValue
  683. PropertyChanged PICTUREHDC_PROPERTY_NAME
  684. UserControl_Resize
  685. End Property
  686.  
  687. Public Property Get PictureHeight() As Integer
  688. Attribute PictureHeight.VB_Description = "Returns/sets the height in pixels of the source device context."
  689. PictureHeight = mProp_intPictureHeight
  690. End Property
  691.  
  692. Public Property Let PictureHeight(ByVal intNewValue As Integer)
  693. mProp_intPictureHeight = intNewValue
  694. PropertyChanged PICTUREHEIGHT_PROPERTY_NAME
  695. UserControl_Resize
  696. End Property
  697.  
  698. Public Property Get PictureWidth() As Integer
  699. Attribute PictureWidth.VB_Description = "Returns/sets the width in pixels of the source device context."
  700. PictureWidth = mProp_intPictureWidth
  701. End Property
  702.  
  703. Public Property Let PictureWidth(ByVal intNewValue As Integer)
  704. mProp_intPictureWidth = intNewValue
  705. PropertyChanged PICTUREWIDTH_PROPERTY_NAME
  706. UserControl_Resize
  707. End Property
  708.  
  709. '========================================================================
  710. 'Private Subroutines
  711. '========================================================================
  712. Private Sub RedrawControl()
  713.  
  714. Dim intX As Integer
  715. Dim intLabelTop As Integer
  716. Dim intBadPicSizeFlag As Integer
  717.  
  718. 'Check that the picture has a valid size
  719. If mProp_booHasPicture = True Then
  720.     If mProp_intPictureWidth = 0 Or mProp_intPictureHeight = 0 Then
  721.         intBadPicSizeFlag = 1
  722.         mProp_booHasPicture = False 'Temporarily disable
  723.     Else
  724.         picImage.Width = mProp_intPictureWidth
  725.         picImage.Height = mProp_intPictureHeight
  726.         picBuffer.Width = mProp_intPictureWidth
  727.         picBuffer.Height = mProp_intPictureWidth
  728.     End If
  729. End If
  730.  
  731. lblCaption.AutoSize = True
  732. intLabelTop = (ScaleHeight / 2) - (lblCaption.Height / 2)
  733.  
  734. picImage.Top = (ScaleHeight / 2) - (picImage.Height / 2)
  735.  
  736. intX = (ScaleWidth - picImage.Width - lblCaption.Width) / 3
  737.  
  738. If mProp_booHasPicture = True And mProp_booHasCaption = True Then
  739.  
  740.     lblCaption.Top = intLabelTop
  741.  
  742.     If mProp_booAlignPicLeft = False Then
  743.         picImage.Left = intX
  744.         lblCaption.Visible = True
  745.         lblCaption.Left = 2 * intX + picImage.Width
  746.     Else
  747.         picImage.Left = 6
  748.         lblCaption.Visible = True
  749.         lblCaption.Left = 6 + picImage.Width + _
  750.         (ScaleWidth - 6 - picImage.Width - lblCaption.Width) / 2
  751.     End If
  752.     
  753.     picImage.Visible = True
  754.     picImage_Paint
  755.  
  756. ElseIf mProp_booHasPicture = False And mProp_booHasCaption = True Then
  757.     
  758.     lblCaption.AutoSize = False
  759.     lblCaption.Move 5, intLabelTop, ScaleWidth - 10, ScaleHeight
  760.     lblCaption.Visible = True
  761.     
  762.     picImage.Visible = False
  763.  
  764. ElseIf mProp_booHasPicture = True And mProp_booHasCaption = False Then
  765.     
  766.     lblCaption.Visible = False
  767.     picImage.Left = (ScaleWidth / 2) - (picImage.Width / 2)
  768.     
  769.     picImage.Visible = True
  770.     picImage_Paint
  771.  
  772. Else
  773.     
  774.     picImage.Visible = False
  775.     lblCaption.Visible = False
  776.  
  777. End If
  778.  
  779. 'Restore the HasPicture property if required
  780. If intBadPicSizeFlag = 1 Then mProp_booHasPicture = True
  781.  
  782. mpntLabelPos.x = lblCaption.Left
  783. mpntLabelPos.y = lblCaption.Top
  784. mpntPicPos.x = picImage.Left
  785. mpntPicPos.y = picImage.Top
  786. mpntOldSize.x = ScaleWidth
  787. mpntOldSize.y = ScaleHeight
  788.  
  789. End Sub
  790.  
  791. Private Sub ApplyAllProperties(ByVal intCallFlag As Integer)
  792. ApplyBackColor
  793. ApplyCaption APPLY_ALL
  794. ApplyFont APPLY_ALL
  795. ApplyEnabled APPLY_ALL
  796. If intCallFlag = READ_PROP_FLAG Then UserControl_Resize
  797. End Sub
  798.  
  799. Private Sub ApplyBackColor()
  800. UserControl.BackColor = mProp_lngBackColor
  801. End Sub
  802.  
  803. Private Sub ApplyCaption(Optional ByVal intApplyAll As Integer = NOT_APPLY_ALL)
  804.  
  805. Dim lngA As Long
  806.  
  807. AccessKeys = ""
  808.  
  809. For lngA = Len(mProp_strCaption) To 1 Step -1
  810.     If Mid$(mProp_strCaption, lngA, 1) = "&" Then
  811.         If lngA = 1 Then
  812.             AccessKeys = Mid$(mProp_strCaption, lngA + 1, 1)
  813.         ElseIf Not Mid$(mProp_strCaption, lngA - 1, 1) = "&" Then
  814.             AccessKeys = Mid$(mProp_strCaption, lngA + 1, 1)
  815.             Exit For
  816.         Else
  817.             lngA = lngA - 1
  818.         End If
  819.     End If
  820. Next
  821.  
  822. With lblCaption
  823.     .Caption = mProp_strCaption
  824.     .Alignment = mProp_fbAlignment
  825.     .ForeColor = mprop_lngForeColor
  826. End With
  827.  
  828. If intApplyAll = NOT_APPLY_ALL Then UserControl_Resize
  829.  
  830. End Sub
  831.  
  832. Private Sub ApplyFont(Optional ByVal intApplyAll As Integer = NOT_APPLY_ALL)
  833. Set UserControl.Font = mProp_fntFont
  834. Set lblCaption.Font = mProp_fntFont
  835. If intApplyAll = NOT_APPLY_ALL Then UserControl_Resize
  836. End Sub
  837.  
  838. Private Sub ApplyEnabled(Optional ByVal intApplyAll As Integer = NOT_APPLY_ALL)
  839. lblCaption.Enabled = mProp_booEnabled
  840. UserControl.Enabled = mProp_booEnabled
  841. If mProp_booHasPicture = True Then
  842.     If intApplyAll = NOT_APPLY_ALL Then UserControl_Resize
  843. End If
  844. End Sub
  845.  
  846. Private Sub ApplyBorder(Optional ByVal intFirstApply As Integer = 0)
  847. Dim rctBtn As RECT
  848. Line (0, 0)-(Width, Height), mProp_lngBackColor, B
  849. rctBtn.Left = 0
  850. rctBtn.Top = 0
  851. rctBtn.Right = ScaleWidth
  852. rctBtn.Bottom = ScaleHeight
  853. If mProp_booHasBorder = True Then
  854.     DrawEdge hdc, rctBtn, BDR_MOUSEOVER_HB, BF_RECT
  855.     If intFirstApply = FORCE_FLATTEN Or Not Ambient.UserMode Then
  856.         'Remove thick edge
  857.         Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), mProp_lngBackColor, B
  858.     End If
  859. Else
  860.     DrawEdge hdc, rctBtn, BDR_MOUSEOVER, BF_RECT
  861. End If
  862. End Sub
  863.  
  864.  
  865.  
  866.