'/////////////////////////////////////
'自定义消息框上的按钮的文字
'\\\\\\\\\\\\\\\\\\
'鬼龙之舞
'2004-3-1
'以下代码在模块
Option Explicit
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long,ByVal lpText As String,ByVal lpCaption As String,ByVal wType As Long) As Long
Private Declare Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextA" (ByVal hDlg As Long,ByVal nIDDlgItem As Long,ByVal lpString As String) As Long
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 Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private hHook As Long
Private Function HookProc(ByVal nCode As Long,ByVal wParam As Long,ByVal lParam As Long) As Long
If nCode = HCBT_ACTIVATE Then
'HCBT_ACTIVATE时wParam是将被激活的窗口的句柄
Dim hwnd As Long
hwnd = wParam
'设定按钮的文字
SetDlgItemText hwnd,vbOK,ByVal "确定[&O]"
SetDlgItemText hwnd,vbCancel,ByVal "取消[&C]"
SetDlgItemText hwnd,vbYes,ByVal "是[&Y]"
SetDlgItemText hwnd,vbNo,ByVal "否[&N]"
SetDlgItemText hwnd,vbAbort,ByVal "放弃[&A]"
SetDlgItemText hwnd,vbIgnore,ByVal "忽略[&I]"
SetDlgItemText hwnd,vbRetry,ByVal "重试[&R]"
'不要再Hook,以免带来不必要的麻烦
UnhookWindowsHookEx hHook
End If
HookProc = 0
End Function
'使用和VB的MsgBox一样的名字,如果你不想使用自定文字格式,只需要移除本模块即可 Public Function MsgBox(Prompt As String,Optional Button As VbMsgBoxStyle = vbOKOnly,Optional Title As String) As VbMsgBoxResult If Len(Title) = 0 Then Title = App.Title hHook = SetWindowsHookEx(WH_CBT,AddressOf HookProc,App.hInstance,App.ThreadID) '注意下面的第一个参数最好传递一个窗口的句柄,当然,让它作为0也可以 'MsgBox= MessageBox(0,Prompt,Title,Button) '不推荐这样做 MsgBox = MessageBox(Form1.hwnd,Button) End Function
原文链接:https://www.f2er.com/vb/260694.html