VB 自定义消息框上的按钮的文字_VB.net_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

VB 自定义消息框上的按钮的文字

作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0

本篇关键词:文字按钮消息定义
黑客防线网安网讯:'/////////////////////////////////////'自定义消息框上的按钮的文字'\\\\\\\\\\\\\\\\\\'鬼龙之舞'2004-3-1'以下代码在模块Option ExplicitPrivate Declare Func...

'/////////////////////////////////////
'自定义消息框上的按钮的文字
'\\\\\\\\\\\\\\\\\\
'鬼龙之舞
'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, Prompt, Title, Button)
End Function

'窗体部分,
'就如你所见一样,只是像平常一样的用法
Option Explicit
Private Sub Command1_Click()
If MsgBox("你好", vbOKCancel + vbInformation) = vbOK Then
    Call MsgBox("你按了OK", vbInformation)
End If
End Sub

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14675-1.html
网站维护教程更新时间:2012-04-03 01:12:15  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer