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
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNSHADOW = 16
Private Const COLOR_BTNTEXT = 18
Private Const COLOR_BTNHIGHLIGHT = 20
Private Const COLOR_BTNDKSHADOW = 21
Private Const COLOR_BTNLIGHT = 22
Private Declare Function GetBkColor Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function GetTextColor Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDc As Long, ByVal crColor As Long) As Long
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
Private Const DT_CALCRECT = &H400
Private Const DT_WORDBREAK = &H10
Private Const DT_CENTER = &H1 Or DT_WORDBREAK
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Const PS_SOLID = 0
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hDc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function FrameRect Lib "user32" (ByVal hDc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hDc As Long, lpRect As RECT) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hDc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Const RGN_DIFF = 4
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function InflateRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CopyRect Lib "user32" (lpDestRect As RECT, lpSourceRect As RECT) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type RECT
left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Public Enum ButtonTypes
[Windows 16-bit] = 1 'the old-fashioned Win16 button
[Windows 32-bit] = 2 'the classic windows button
[Windows XP] = 3 'the new brand XP button totally owner-drawn
[Mac] = 4 'i suppose it looks exactly as a Mac button... i took the style from a GetRight skin!!!
[Java metal] = 5 'there are also other styles but not so different from windows one
[Netscape 6] = 6 'this is the button displayed in web-pages, it also appears in some java apps
[Simple Flat] = 7 'the standard flat button seen on toolbars
[Flat Highlight] = 8 'again the flat button but this one has no border until the mouse is over it
End Enum
Public Enum ColorTypes
[Use Windows] = 1
[Custom] = 2
[Force Standard] = 3
[Use Container] = 4
End Enum
'events
Public Event Click()
Public Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event KeyPress(KeyAscii As Integer)
Public Event KeyDown(KeyCode As Integer, Shift As Integer)
Public Event KeyUp(KeyCode As Integer, Shift As Integer)
Public Event MouseOver()
Public Event MouseOut()
'variables
Private MyButtonType As ButtonTypes
Private MyColorType As ColorTypes
Private He As Long 'the height of the button
Private Wi As Long 'the width of the button
Private BackC As Long 'back color
Private ForeC As Long 'fore color
Private ForeO As Long 'fore color when mouse is over
Private elTex As String 'current text
Private rc As RECT, rc2 As RECT, rc3 As RECT
Private rgnNorm As Long
Private LastButton As Byte, LastKeyDown As Byte
Private isEnabled As Boolean
Private hasFocus As Boolean, showFocusR As Boolean
Private cFace As Long, cLight As Long, cHighLight As Long, cShadow As Long, cDarkShadow As Long, cText As Long, cTextO As Long
Private lastStat As Byte, TE As String 'used to avoid unnecessary repaints
Private isOver As Boolean
Private Sub OverTimer_Timer()
Dim pt As POINTAPI
GetCursorPos pt
If UserControl.hwnd <> WindowFromPoint(pt.x, pt.y) Then
OverTimer.Enabled = False
isOver = False
Call Redraw(0, True)
RaiseEvent MouseOut
End If
End Sub
Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
Call UserControl_Click
End Sub
Private Sub UserControl_AmbientChanged(PropertyName As String)
If MyColorType = [Use Container] Then
Call SetColors
Call Redraw(lastStat, True)
End If
End Sub
Private Sub UserControl_Click()
If (LastButton = 1) And (isEnabled = True) Then
Call Redraw(0, True) 'be sure that the normal status is drawn
UserControl.Refresh
RaiseEvent Click
End If
End Sub
Private Sub UserControl_DblClick()
If LastButton = 1 Then
Call UserControl_MouseDown(1, 1, 1, 1)
End If
End Sub
Private Sub UserControl_GotFocus()
hasFocus = True
Call Redraw(lastStat, True)
End Sub
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyDown(KeyCode, Shift)
LastKeyDown = KeyCode
If KeyCode = 32 Then 'spacebar pressed
Call UserControl_MouseDown(1, 1, 1, 1)
ElseIf (KeyCode = 39) Or (KeyCode = 40) Then 'right and down arrows
SendKeys "{Tab}"
ElseIf (KeyCode = 37) Or (KeyCode = 38) Then 'left and up arrows
SendKeys "+{Tab}"
End If
End Sub
Private Sub UserControl_KeyPress(KeyAscii As Integer)
RaiseEvent KeyPress(KeyAscii)
End Sub
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyUp(KeyCode, Shift)
If (KeyCode = 32) And (LastKeyDown = 32) Then 'spacebar pressed
Call UserControl_MouseUp(1, 1, 1, 1)
LastButton = 1
Call UserControl_Click
End If
End Sub
Private Sub UserControl_LostFocus()
hasFocus = False
Call Redraw(lastStat, True)
End Sub
Private Sub UserControl_Initialize()
LastButton = 1
Call SetColors
End Sub
Private Sub UserControl_InitProperties()
isEnabled = True
showFocusR = True
elTex = Ambient.DisplayName
Set UserControl.font = Ambient.font
MyButtonType = [Windows 32-bit]
MyColorType = [Use Windows]
BackC = GetSysColor(COLOR_BTNFACE)
ForeC = GetSysColor(COLOR_BTNTEXT)
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
RaiseEvent MouseDown(Button, Shift, x, y)
LastButton = Button
If Button <> 2 Then Call Redraw(2, False)
End Sub
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
RaiseEvent MouseMove(Button, Shift, x, y)
If Button < 2 Then
If x < 0 Or y < 0 Or x > Wi Or y > He Then
'we are outside the button
Call Redraw(0, False)
Else
'we are inside the button
If (Button = 0) And (isOver = False) Then
OverTimer.Enabled = True
isOver = True
RaiseEvent MouseOver
Call Redraw(0, True)
ElseIf Button = 1 Then
Call Redraw(2, False)
End If
End If
End If
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
RaiseEvent MouseUp(Button, Shift, x, y)
If Button <> 2 Then Call Redraw(0, False)
End Sub
'########## BUTTON PROPERTIES ##########
Public Property Get BackColor() As OLE_COLOR
BackColor = BackC
End Property
Public Property Let BackColor(ByVal theCol As OLE_COLOR)
BackC = theCol
Call SetColors
Call Redraw(lastStat, True)
PropertyChanged "BCOL"
End Property
Public Property Get ForeColor() As OLE_COLOR
ForeColor = ForeC
End Property
Public Property Let ForeColor(ByVal theCol As OLE_COLOR)
ForeC = theCol
If Ambient.UserMode = False Then ForeO = theCol
Call SetColors
Call Redraw(lastStat, True)
PropertyChanged "FCOL"
End Property
Public Property Get ForeOver() As OLE_COLOR
ForeOver = ForeO
End Property
Public Property Let ForeOver(ByVal theCol As OLE_COLOR)
ForeO = theCol
Call SetColors
Call Redraw(lastStat, True)
PropertyChanged "FCOLO"
End Property
Public Property Get ButtonType() As ButtonTypes
ButtonType = MyButtonType
End Property
Public Property Let ButtonType(ByVal newValue As ButtonTypes)
MyButtonType = newValue
If ButtonType = [Java metal] Then UserControl.FontBold = True
Call UserControl_Resize
PropertyChanged "BTYPE"
End Property
Public Property Get Caption() As String
Caption = elTex
End Property
Public Property Let Caption(ByVal newValue As String)
elTex = newValue
Call SetAccessKeys
Call CalcTextRects
Call Redraw(0, True)
PropertyChanged "TX"
End Property
Public Property Get Enabled() As Boolean
Enabled = isEnabled
End Property
Public Property Let Enabled(ByVal newValue As Boolean)
isEnabled = newValue
Call Redraw(0, True)
UserControl.Enabled = isEnabled
PropertyChanged "ENAB"
End Property
Public Property Get font() As font
Set font = UserControl.font
End Property
Public Property Set font(ByRef newFont As font)
Set UserControl.font = newFont
Call CalcTextRects
Call Redraw(0, True)
PropertyChanged "FONT"
End Property
Public Property Get FontBold() As Boolean
Attribute FontBold.VB_MemberFlags = "400"
FontBold = UserControl.FontBold
End Property
Public Property Let FontBold(ByVal newValue As Boolean)
UserControl.FontBold = newValue
Call CalcTextRects
Call Redraw(0, True)
End Property
Public Property Get FontItalic() As Boolean
Attribute FontItalic.VB_MemberFlags = "400"
FontItalic = UserControl.FontItalic
End Property
Public Property Let FontItalic(ByVal newValue As Boolean)
UserControl.FontItalic = newValue
Call CalcTextRects
Call Redraw(0, True)
End Property
Public Property Get FontUnderline() As Boolean
Attribute FontUnderline.VB_MemberFlags = "400"
FontUnderline = UserControl.FontUnderline
End Property
Public Property Let FontUnderline(ByVal newValue As Boolean)
UserControl.FontUnderline = newValue
Call CalcTextRects
Call Redraw(0, True)
End Property
Public Property Get FontSize() As Integer
Attribute FontSize.VB_MemberFlags = "400"
FontSize = UserControl.FontSize
End Property
Public Property Let FontSize(ByVal newValue As Integer)
UserControl.FontSize = newValue
Call CalcTextRects
Call Redraw(0, True)
End Property
Public Property Get FontName() As String
Attribute FontName.VB_MemberFlags = "400"
FontName = UserControl.FontName
End Property
Public Property Let FontName(ByVal newValue As String)
UserControl.FontName = newValue
Call CalcTextRects
Call Redraw(0, True)
End Property
'it is very common that a windows user uses custom color
'schemes to view his/her desktop, and is also very
'common that this color scheme has weird colors that
'would alter the nice look of my buttons.
'So if you want to force the button to use the windows
'standard colors you may change this property to "Force Standard"
Public Property Get ColorScheme() As ColorTypes
ColorScheme = MyColorType
End Property
Public Property Let ColorScheme(ByVal newValue As ColorTypes)
MyColorType = newValue
Call SetColors
Call Redraw(0, True)
PropertyChanged "COLTYPE"
End Property
Public Property Get ShowFocusRect() As Boolean
ShowFocusRect = showFocusR
End Property
Public Property Let ShowFocusRect(ByVal newValue As Boolean)
showFocusR = newValue
Call Redraw(lastStat, True)
PropertyChanged "FOCUSR"
End Property
Public Property Get MousePointer() As MousePointerConstants
MousePointer = UserControl.MousePointer
End Property
Public Property Let MousePointer(ByVal newPointer As MousePointerConstants)
UserControl.MousePointer = newPointer
PropertyChanged "MPTR"
End Property
Public Property Get MouseIcon() As StdPicture
Set MouseIcon = UserControl.MouseIcon
End Property
Public Property Set MouseIcon(ByVal newIcon As StdPicture)
Private Sub Redraw(ByVal curStat As Byte, ByVal Force As Boolean)
'here is the CORE of the button, everything is drawn here
'it's not well commented but i think that everything is
'pretty self explanatory...
If Force = False Then 'check drawing redundancy
If (curStat = lastStat) And (TE = elTex)ustom coloropB Thennatory...
If Forceex)ustomRter thell .Wriu = .ReadProperty("FCOL", GetSyL orm
End Sub
Private Sub UserControl_WriteProperties) As BooleaaaCAontrolperty("BTYPE", MyButtonTytroaty = .ReadPxloDitrol_Wl iteProperties) As BooleaaaCAontrolperty("BTYPE", MyButtonTytroaty = .ReadPxloDitrol( UserControl_WriteProperties) As BoBing ntrolperty("BTYPE", Mroperties) As BoBesPxlohing)
EnnnnnMyButtonTytroaty = .ReadPxloDitrol( UserControl_WriteProperties) As BoBing eP .Readtrol( UsBesPxlen S8rControl_Wrisv,l sOol(s) As BooleaaaCAontrolperBrent MouseDup, a e Property Ge, -4,b redundol_WriteProbrolperBrent MouseDup, a e Property Ge, -rolpePropKeProbrolperBrennControlh-te Wi As Long 'the width of the button< dPxlodth obFon DrawPropertirdi Caption(ByVal newValue As String)
elTex(ByValtion(ByVal newValue nnnM, UserControlByVaetSysCmbien Property Get FontName(t drawa_Wrie FontUnderlinCony...
tption(ByVal r.E = .Rea height ofPiuseDup, a e Property GeL", BackCaoper) As BoBrty Ge,lFty("Fit will #
iesrol_Wrisv,l sOol(s) As BooobrolperBrent MouseDup, ae Property GeL", BackCaoper) As BoBrt)
End Property
Public Poobrolpt)
ERe Pro MouseDuttonType = e Properierty Ge, -4,b redundol_WriteProbrolperBrent Mouep1 dPxlo= .ReadPxloDitrol(y22 ...Xpented but troaty =d(ByV72 ...XoWriteProbrrControlf thtHderControl_InitProperties()4adtrolContperBre bu Wi = UserCoa..XoWriwckCaopeaal_TertpaaaCAkCaoper) Ac= tolf trierty Ge, -4,aty =d(ByV72 ...XoWriteProbrrControlf thtHderControl_ICwill #
Public Event MouseDown(Button As Inte:nnM, UserControlByVaetSysCmbien Property Get FontName(t drawa_Wrie FontUrIc,aty ng ' 'Proprie FontUrC_Wrie FontUrIc,aty eINKdFontUrIcsrit eINKdFed b) As BoBrt)
PublrRCc PtdPropI hr ien Pr[Propertniaer,hr Dier, ShHEthinblrRCc PtdPropI hr ien Pr[Propertniaer,hr Dier, Sh ontrol0den0r ButlrRDitrl sOol(s) As BooleaaaCAontrolperB0er,hr Dier, toleeeeeeeen0nt AscohOol(s) As BlTeegB0er,hrnsOol(s) As BooleaaaAscohOol(s) As BlTeegB0er,hrnsOol(saetSysCmbien Pro eeeen0ntoeIlScTlicnntrol.font)
tonType = e Properierty Ge, -4,b redundol_Writb ) As el
i]yy!1ci2Ce,3 iti]yylouseDuttonType = e Properienee =eegB0er,er lmr.3OL"O2mrO2mrO2mrO2mrO2m islPCtol MouseIegB0eoHEthing is lmr.3OL"O2mrO2mrO2myneUCalcTextRects
Call Redraw(0, True)
End PropertyIhUrXXXXX Po,SsXXXXyV72 u l> colcyy!1b2ouseDuttonTytre>t>3OL"O2mrO2mrO2myneUCalcTe()4adtrolContperBre
PublicXXXXXXXXXXXXXXXXXXXc
neawa_Wrie FEhr ien XXXXXXX5ift Aol0den0r Butlrien Xf i]y ty
'####nhng isll Cal olCont plicO.Prop f i]y ty
.Prop f i]y ty
.Prop f egB0etlri
Call Redraw(0, True)
Cs
PubX ytre>t>3OL"O2mrO2mrOAsop f i]y ty
.Prop f i]yLblic Po
With PropBaRXXXXX Po,SsXXXXyV72 u l> colcyy!1b2ouseDuttueaaa3 !gaHIPo,airtniaer,hr Dier, Sh ontrol0den0r ButlrRDitrl sOol(s) y("BCOL9eulrl sOol(s) y om color
i2 u OL9euSh rnrtniaeR0r ecgV72n0r f ran)
User
Call Rul= .Ro tAAAAAAAAAUrIcsri b yIhUrXXXXX Po,SsXXXXe1m$l itroaty3Property
Public PoobrolpteGet FontSize()er,hr Dier, Sh ontrol0den0r ButlrRDivate SPtNXXXXXolptRXXXXXXXXXXXXXXXXXuolContperBre hUrXXX44444444444444444444444wContperBre hUrXXX44444444444 Truea 444444444wContperBre fer(Byx
true)
i]yy!1ci2Ce,3 iti]yylouseDu,FbnhFbnhF1b2ouseDuttuea5myneUCalcTe()4adtrolContperBreContperBre hUrXXX44444444444 XvrolCrl sOol(s) y("B Bre L4444444 4adtrolContperBreContperBrDadundoltom c
EleulreContperBrDaaaaaueaa wiSMsocSulatyXXXcCm$l itroatyTytro trol.Mouet Foro trol.Mc4444wContperBiRitroatePointer()eaa wiSMsocSu pteGet FontS e>t>3OL"O2mrO2mrOAsop f eColor = BackClocSuleulocf Lol.Mc4444wCcxXX(eUrItperBiRitroatePoinmnt MousrroatePoinmntHsOol(eulocSuleu44wCcxXX(eUrItperBiRitroaPAsop f eColoFL PoobItperwiSMsPoinmntHsOol(ereCo! ist() As Boolean
ShowFocusRLfX444wCcxXX(eUrItperBiRitroaPAsop f eCom_Bre
asOol(s) y(howFocusRLol(ereCo! ist() As Boolean72n0r f CaoyrIcsr eColoFL PoobItperwiSMsPoinmntwoaPAsop eColoFinmntwoaPAsop 2obItpeehwnsXXXXe1cnaa wiSMspaloFinmntwoaPAsow44444444sl>ti2Cee'csrit
ro0RI "tDoperwi(erE Y PrmsocbliegB"tfa Lol.Mc4444wCcxXX(eUrItperBsoyrIcsr eColoFLdfe'csod,FL PoobItperwiSMsPoinmntHsOol(ereCo! ist() As Boolean
Sh oatePointer()eaa wiSml.Mc4444wCcxXX(eUr
ShowFocusRLfbPAsop eColoFi44 4adt,ocustre>ti]yy! isllFi44 v oXXXXXXi44 erE Y44wCcxXX(eUrItp)cxXX(0 erE Y4B"tf.itePrmIncId locSuntoFinmntwb DS(eUrntwb DS(eUrnterE Y44wX44wXXXXiDeadProsAuee,nbtrol.font)RS21VaNrhvl
EleulreCont As REC.Po,SseDu,FbnhFbnhF-LfbiuseDuL,nbByx
A dry
ran)leuloed(ByVal newVv0XXXdGe0bws) y sOedrD2 Set"ETnBSet"ETnBSblbselean72n0r f Mc4 fc=TXX444444 TrrD2 STruea 4444awa_Wrie FonterD2 STruea 4444awa_Wrie FonterD2 STruea 4444awa_Wrie FonterD2 STruea 4444awa_Wrie4444awa_dsruea 4444awa_T.e44444444444wContperBrersrie F pTRs4awa_ -44444444ehwndyMtea_T.e44444444444wContperBrersrie F pTORE of the butBoollinae4ehwndyMtea_T.e44444444444wContperBrRControl.FontItalic = nee hrcTextT84 eRI hrcnderline.teguan
trol.FontISen a 4ntperBrktBoolinei neanei neanyTytro trp eItalic = nee hrcTextT84 eRI hrcnderline.teguaneuloed(Bline.te.teguaneuloeeine.NuX Po,SsXXXr ObXrPoobLfbPcSureCo!fGProsAuee,nbByx
tswtawn D irE Y4B"tr ObXrPoobLfbPcSureIx
ta. f Mc4 fc=TXX444444 TrrD2 STrueaeIx
teenableSRI hrStdPictfbPcSureCo!fGProsAuee,nbByx
tswtawn D irE Y4B"tr ObXrPoobLfbPcSureCo!fGProsAuee,nbB TXXrlinterEEu44wCoJc=TXX!g SRTXXX Po,SsXXXr ObXrPoobLfbPcSureCo!fGProsAuee,nbByx
s 4444aeeiiftTOxerwpetSnl(gB"(eCcFuseI0e 444U%FPropcFniElptRXXXXHFPropcFnperwperwperwt]aeeiift=X P pe-s(TOxe1-cltT'_F ?kYapyt1FonEwETn)tSniB'erolContt _F ,BntervntervntervntervntervVyx