改变VB 6.0命令按钮的Caption文本颜色

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
'Various GDI painting-related functions
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
'Prepare DC for drawing
SetBkMode hDC, TRANSPARENT
SetTextColor hDC, GetProp(hWnd, "VBTForeColor")
'Prepare a text buffer
S = String$(255, 0)
Private Const ODS_SELECTED = &H1
'Window messages we're using
Private Const WM_DESTROY = &H2
Private Const WM_DRAWITEM = &H2B
Private Type DRAWITEMSTRUCT
'Adjust specially for VB's CommandButton control
rct.Bottom = rct.Bottom - 4
End If
If (nState And ODS_SELECTED) = ODS_SELECTED Then
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'Owner draw constants
Private Const ODT_BUTTON = 4
DrawText hDC, S, LenB(StrConv(S, vbFromUnicode)), rct, DT_CENTER Or DT_SINGLELINE Or Va
End Sub
Public Function ExtButtonProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const TRANSPARENT = 1
Private Const DT_CENTER = &H1
Public Enum TextVAligns
DT_VCENTER = &H4
DT_BOTTOM = &H8
End Enum
Private Const DT_SINGLELINE = &H20
itemData As Long
End Type
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'Button is in down state - offset
'the text
rct.Left = rct.Left + 1
rct.Right = rct.Right + 1
rct.Bottom = rct.Bottom + 1
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, ByVal nBkMode As Long) As Long
'*******************对命令按钮进行颜色设置**********************
Private Sub Command2_Click() '改为蓝色
cmdButtonColorCaption Command1, vbBlue
End Sub
Private Const GWL_WNDPROC = (-4)
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
'
' 三、在FORM_Unload中调用以下过程
' cmdButtonApiRemove(cbControl As Control) '移除对按钮的API设置
'
'=============================================================================================================================
Private Sub Command3_Click() '使失效
cmdButtonDisenable Command1
End Sub
Private Sub Command4_Click() '使能
cmdButtonEnableColorCaption Command1, vbBlue
PrivatBiblioteka Type RECT Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
rct.Top = rct.Top + 1
End If
'------------------------- 此处修改适应中文显示 -----------------------
'DrawText hDC, s, Len(s) , rct, DT_CENTER Or DT_SINGLELINE Or va
End Sub
Private Sub Form_Load()
'注意Command1在编程时一定要将其Style设为1(Graphical)
cmdButtonColorCaption Command1, vbRed '初始设为红色
End Sub
Private Sub FORM_Unload(Cancel As Integer) '释放
'*
'*****************************************
Option Explicit
'=============================================================================================================================
cmdButtonApiRemove Command1
End Sub
'*****************************************
'*****************************************
'*
'* 第二部分:cmdButtonColorCaption.bas
'
' cmdButtonColorCaption.bas
'
' 本模块通过API,可以改变VB 6.0命令按钮的Caption文本颜色。
'
' 使用方法:
'
' 一、在编程时将按钮的Style设为Graphical
'
' 二、在运行时调用以下3个过程
' cmdButtonColorCaption(cbControl As Control, ccColor As Long) '改变按钮的Caption颜色:按钮cbControl,颜色ccColor
' cmdButtonEnableColorCaption(cbControl As Control, ccColor As Long) '“使能”按钮的各项功能:按钮cbControl,颜色ccColor
' cmdButtonDisenable(cbControl As Control) '使按钮的各项功能失效:按钮cbControl
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hDC As Long
rcItem As RECT
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Sub DrawButton(ByVal hWnd As Long, ByVal hDC As Long, rct As RECT, ByVal nState As Long)
Dim S As String
Dim Va As TextVAligns
Va = GetProp(hWnd, "VBTVAlign")
'What should we print on the button?
GetWindowText hWnd, S, 255
'Trim off nulls
S = Left$(S, InStr(S, Chr$(0)) - 1)
If Va = DT_BOTTOM Then
相关文档
最新文档