'方法是有,不过不建议这么做.你确定你还要这么做?确定?好吧.那就接着往下看.
'只有想不到,没有做不到,看我无敌API......呵呵
'这段代码大部分是别人写的,我只是修改并封装成函数.
'功能可扩展:颜色,背景图案,按钮颜色,按钮图案...(总之,很多很多...)
'函数调用方法:MyMsgBox 显示的信息,按钮,标题,字体名称(默认为宋体),字体大小,斜体,下划线,删除线
'窗体代码
Private Sub Command1_Click()
MyMsgBox "我变,我变,我变变变!!!!", vbYesNo, "- -|||", "黑体"
End Sub
'模块代码
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Long, ByVal W As Long, ByVal E As Long, ByVal O As Long, ByVal W As Long, ByVal I As Long, ByVal u As Long, ByVal S As Long, ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal Q As Long, ByVal PAF As Long, ByVal F As String) As Long
Private Const HCBT_ACTIVATE = 5
Private Const WH_CBT = 5
Private Const DEFAULT_CHARSET = 1
Private Const OUT_TT_ONLY_PRECIS = 7
Private Const CLIP_DEFAULT_PRECIS = 0
Private Const DEFAULT_QUALITY = 0
Private Const FF_DONTCARE = 0
Private Const WM_SETFONT = &H30
Private hHook As Long
Private MsgBoxTitle As String
Private hFont As Long
Private Sub EnableHook()
If hHook = 0 Then
hHook = SetWindowsHookEx(WH_CBT, AddressOf HookProc, 0, App.ThreadID)
End If
End Sub
Private Sub FreeHook()
If hHook <> 0 Then
Call UnhookWindowsHookEx(hHook)
hHook = 0
End If
End Sub
Private Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode < 0 Then
HookProc = CallNextHookEx(hHook, nCode, wParam, lParam)
Exit Function
End If
'当MsgBox Activate之前去更改Button的标题
If nCode = HCBT_ACTIVATE Then
Dim str5 As String
Dim len5 As Long, I As Long
str5 = String(255, 0)
len5 = 256
I = GetWindowText(wParam, str5, len5)
str5 = Left(str5, InStr(1, str5, Chr(0)) - 1)
'如果Active Window上的标题是MsgBox上的标题
'
If str5 = MsgBoxTitle Then
'取得MsgBox上的所有子window
Call EnumChildWindows(wParam, AddressOf ChgButtonTitle, 0)
End If
End If
HookProc = 0 '令待完成的动作继续完成,若为1,则取消原本要完成的动作
End Function
Private Function ChgButtonTitle(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim clsName As String
If hwnd = 0 Then
ChgButtonTitle = 0
Exit Function
End If
clsName = String(255, 0)
Call GetClassName(hwnd, clsName, 256)
clsName = Left(clsName, InStr(1, clsName, Chr(0)) - 1)
'找到Static型态的子Window,并更改其上的标题
If clsName = "Static" Then
SendMessage hwnd, WM_SETFONT, hFont, True
End If
ChgButtonTitle = 1 '表示继续找下一个子Window
End Function
Public Function MyMsgBox(ByVal Prompt As String, Optional ByVal Buttons As Long, Optional ByVal Title As String = " ", Optional ByVal sFontName As String = "宋体", Optional ByVal FontSize As Long, Optional ByVal FontItalic As Boolean = False, Optional ByVal FontUnderline As Boolean = False, Optional ByVal FontStrikethru As Boolean = False) As Long
hFont = CreateFont(FontSize, 0, 0, 0, 0, FontItalic, FontUnderline, FontStrikethru, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, sFontName)
Call EnableHook
MsgBoxTitle = Title
MyMsgBox = MsgBox(Prompt, Buttons, MsgBoxTitle)
Call FreeHook
End Function
温馨提示:内容为网友见解,仅供参考