找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 3303|回复: 0

ToolBar的模样自己画(三)

[复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2010-1-30 09:21:55 | 显示全部楼层 |阅读模式

  1. '类中的各种属性与方法,主要用于外部调用
  2. Property Let BorderColor(ByVal vData As Long)
  3.     If m_lngBrdColor <> vData Then
  4.         m_lngBrdColor = vData
  5.         If m_lngBrdStyle > 3 Then Refresh
  6.     End If
  7. End Property
  8. Property Get BorderColor() As Long
  9.     BorderColor = m_lngBrdColor
  10. End Property
  11. Property Let BackPicture(ByVal vData As String)
  12.     If vData <> "" And Dir(vData) <> "" Then
  13.         If LCase(m_strBkPicture) <> LCase(vData) Then
  14.             m_strBkPicture = vData
  15.             Set mpicBk = LoadPicture(m_strBkPicture)
  16.             Refresh
  17.         End If
  18.     Else
  19.         Set mpicBk = Nothing
  20.         m_strBkPicture = ""
  21.     End If
  22. End Property
  23. Property Get BackPicture() As String
  24.     BackPicture = m_strBkPicture
  25. End Property
  26. Property Let FontName(ByVal vData As String)
  27. Dim s As String, i As Long
  28.     vData = Trim(vData)
  29.     s = StrConv(Font.lfFaceName, vbUnicode)
  30.     i = InStr(1, s, Chr(0))
  31.     If i > 0 Then
  32.         s = Left$(s, i - 1)
  33.     End If
  34.     If s <> vData Then
  35.         CopyMemory Font.lfFaceName(0), ByVal vData, lstrlen(vData)
  36.         Refresh
  37.     End If
  38. End Property
  39. Property Get FontName() As String
  40. Dim s As String, i As Long
  41.     s = StrConv(Font.lfFaceName, vbUnicode)
  42.     i = InStr(1, s, Chr(0) - 1)
  43.     If i > 0 Then
  44.         FontName = Left$(s, i - 1)
  45.     Else
  46.         FontName = s
  47.     End If
  48. End Property
  49. Property Let FontUnderline(ByVal vData As Boolean)
  50. Dim i As Long
  51.     i = IIf(vData, 1, 0)
  52.     If Font.lfUnderline <> i Then
  53.         Font.lfUnderline = i
  54.         Refresh
  55.     End If
  56. End Property
  57. Property Get FontUnderline() As Boolean
  58.     FontUnderline = (Font.lfUnderline = 1)
  59. End Property
  60. Property Let FontItalic(ByVal vData As Boolean)
  61. Dim i As Long
  62.     i = IIf(vData, 1, 0)
  63.     If Font.lfItalic <> i Then
  64.         Font.lfItalic = i
  65.         Refresh
  66.     End If
  67. End Property
  68. Property Get FontItalic() As Boolean
  69.     FontItalic = (Font.lfItalic = 1)
  70. End Property
  71. Property Let FontBold(ByVal vData As Boolean)
  72. Dim i As Long
  73.     i = IIf(vData, 700, 400)
  74.     If Font.lfWeight <> i Then
  75.         Font.lfWeight = i
  76.         Refresh
  77.     End If
  78. End Property
  79. Property Get FontBold() As Boolean
  80.     FontBold = (Font.lfWeight = 700)
  81. End Property
  82. Property Let FontSize(ByVal vData As Long)
  83.     If Font.lfHeight <> vData And vData >= 7 And vData <= 16 Then
  84.         Font.lfHeight = vData
  85.         Font.lfWidth = 0
  86.         Refresh
  87.     End If
  88. End Property
  89. Property Get FontSize() As Long
  90.     FontSize = Font.lfHeight
  91. End Property
  92. Property Let BorderStyle(ByVal vData As Long)
  93.     If m_lngBrdStyle <> vData Then
  94.         m_lngBrdStyle = vData
  95.         Refresh
  96.     End If
  97. End Property
  98. Property Get BorderStyle() As Long
  99.     BorderStyle = m_lngBrdStyle
  100. End Property
  101. Property Let TextHiColor(ByVal vData As Long)
  102.     m_lngTextHiColor = vData
  103. End Property
  104. Property Get TextHiColor() As Long
  105.     TextHiColor = m_lngTextHiColor
  106. End Property
  107. Property Let TextColor(ByVal vData As Long)
  108.     If m_lngTextColor <> vData Then
  109.         m_lngTextColor = vData
  110.         Refresh
  111.     End If
  112. End Property
  113. Property Get TextColor() As Long
  114.     TextColor = m_lngTextColor
  115. End Property
  116. Property Let BackColor(ByVal vData As Long)
  117.     If m_lngBackColor <> vData Then
  118.         m_lngBackColor = vData
  119.         If mpicBk Is Nothing Then Refresh
  120.     End If
  121. End Property
  122. Property Get BackColor() As Long
  123.     BackColor = m_lngBackColor
  124. End Property
  125. Sub BindToolBar(ByVal hWnd As Long)
  126.     If m_hWnd = 0 Then
  127.         m_hWnd = hWnd
  128.         If m_hWnd Then
  129.             OldWindowProc = GetWindowLong(m_hWnd, GWL_WNDPROC)
  130.             SetWindowLong m_hWnd, GWL_WNDPROC, AddressOf TBSubClass
  131.         End If
  132.         Refresh
  133.     End If
  134. End Sub
  135. Private Sub Class_Initialize()
  136. Dim rc As RECT, hBrush As Long, i As Long
  137.     m_lngTextColor = vbBlack
  138.     m_lngTextHiColor = vbRed
  139.     m_lngBackColor = &HD7E9EB
  140.     m_lngBrdColor = &H0
  141.     mlngBtnHiAlpha = 96
  142.     mlngBtnDownAlpha = 192
  143.     rc.Bottom = 128
  144.     rc.Right = 128
  145.     i = GetDC(0)
  146.     mdcWhite = NewMyHdc(i, rc.Right, rc.Bottom)
  147.     ReleaseDC 0, i
  148.     hBrush = CreateSolidBrush(vbWhite)
  149.     FillRect mdcWhite.hdc, rc, hBrush
  150.     DeleteObject hBrush
  151.     With Font
  152.         .lfCharSet = 1
  153.         .lfHeight = 12
  154.         .lfWeight = 400
  155.     End With
  156. End Sub
  157. Private Sub Class_Terminate()
  158.     SetWindowLong m_hWnd, GWL_WNDPROC, OldWindowProc
  159.     mdcWhite = DelMyHdc(mdcWhite)
  160.     Set mpicBk = Nothing
  161. End Sub
  162. Sub Refresh()
  163. Dim rc As RECT
  164.     If m_hWnd <> 0 Then
  165.         ShowWindow m_hWnd, 0
  166.         ShowWindow m_hWnd, 5
  167.     End If
  168. End Sub

复制代码
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表