首页 >> 读书频道 >> 电脑 >> 更动MsgBox Button 标题(CBT Hook)
 
· Hook简介
· 如何得知Mouse已离开
· 网络数据库教程六
· TextBox模拟拖曳选
· 网络数据库教程五
· 如何在开始功能表的程式集
· 网络数据库教程四
· 设定Caret的大小与其
· 如何Restart Sh
· 于PictureBox/
· 如何用VB建立捷径(Sh
· 让一组相同的控制项有相同
 
· 电视剧《刁蛮公主》下载和
· 美容养颜手册
· 加油金顺剧情分集介绍完整
· 红楼梦:120回全本[清
· 素质教育在美国
· 全唐诗卷四十六
· 韩剧《布拉格恋人》剧情介
· 夜航船[作者:明·张岱]
· 局外人[作者:韩·可爱淘
· 现场流行病学
· 源氏物语[日本:紫式部]
· 武林寓言故事
 
· (出租)中动商场部分及写
· (出租)中动动漫基地&#
· 喜剧学院
· 《善德女王》剧情介绍
· 魔女18号 剧情
· 丑女无敌剧情介绍
· 魔女幼熙剧情介绍
· 龙游天下剧情介绍
· 震撼世界的七日剧情介绍
· 静静的白桦林剧情介绍
· 心情日记—老公今天我想对
· 旗舰剧情介绍
欢迎来到月影社区!如果您觉得这里不错,请推荐给您的朋友们。月影社区:http://wf66.com/

更动MsgBox Button 标题(CBT Hook)


查看有无更新版本

关键字:VB 2006-9-18

 

如果我们使用MsgBox,并设定其Buttons为vbYesNo,则出来的Button有 "是(Y)" 与 "否(N)"
,有没有可能变成"Yes(Y)"和 "No(N)"呢,或者有没有办法设定MsgBox的位置呢?如果我们
可以在MsgBox显示出来之前取得其hWnd,便可以进而更动其位置或Button的标题了;其实这
真的有些困难,因为MsgBox一呼叫,该Process便进入等待MsgBox结束的状态,连Timer都
不会动,所以想取得MsgBox的进一步资讯似乎很难。所以只好借重CBT Hook。

CBT Hook是做什麽用的呢?它是before activating, creating, destroying,
minimizing, maximizing, moving, or sizing a window; before completing a
system command; before removing a mouse or keyboard event from the
system message queue; before setting the keyboard focus; or before
synchronizing with the system message queue.在以上的状况发生之前拦截到讯息。
所以了,这就达到我们的目的 -->可在MsgBox display前取得其hWnd了。取得hWnd後再
使用EmunChildWindows()取得MsgBox的Control视窗,并取得"Button"型态者,进而判
断其Caption,并进行更改之。

这个程式重点在说明CBT Hook,我想没有人会为了更动MsgBox内的Button而如此做,应
会自行写一个Form,而来呼叫它,并可设定其位置。

'以下在FormPrivate Sub Command1_Click()Call EnableHookMsgBoxTitle = "MyTitle5"MsgBox "haha", vbYesNo, MsgBoxTitleCall FreeHookEnd Sub'以下程式在.Bas 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 Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lparam As Any) As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lparam As Long) As Long Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Public Const HCBT_ACTIVATE = 5 Public Const WH_CBT = 5 Public hHook As Long Public MsgBoxTitle as String Public Sub EnableHook() If hHook = 0 Then hHook = SetWindowsHookEx(WH_CBT, AddressOf HookProc, 0, App.ThreadID) End If End Sub Public Sub FreeHook() If hHook <> 0 Then Call UnhookWindowsHookEx(hHook) hHook = 0 End If End Sub Public 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, len5 As Long, i As Long Dim Title As String If hwnd = 0 Then ChgButtonTitle = 0 Exit Function End If clsName = String(255, 0) len5 = 256 i = GetClassName(hwnd, clsName, 256) clsName = Left(clsName, InStr(1, clsName, Chr(0)) - 1) Title = String(255, 0) i = GetWindowText(hwnd, Title, 256) Title = Left(Title, InStr(1, Title, Chr(0)) - 1) '找到Button型态的子Window,并更改其上的标题 If clsName = "Button" Then If Title = "是(&Y)" Then Call SetWindowText(hwnd, "Yes(&Y)") Else If Title = "否(&N)" Then Call SetWindowText(hwnd, "No(&N)") End If End If End If ChgButtonTitle = 1 '表示继续找下一个子Window End Function

更动MsgBox Button 标题(CBT Hook)

[ 1 ]
更动MsgBox Button 标题(CBT Hook) num

打印本页 关闭

关于我们版权声明本站导航友情连结作品演示 TOP↑