永发信息网

如何在VB中实现自定义消息的响应函数

答案:1  悬赏:50  手机版
解决时间 2021-03-28 18:41
如何在VB中实现自定义消息的响应函数
最佳答案
大神给你来个例子 子类化窗口回调



窗体模块 代码开始
Option Explicit


Private Sub Command1_Click()
SendMessage frm1.hwnd, WM_USER + 1, 123, 45
End Sub


Private Sub Form_Load()
SetTimer Me.hwnd, 0, 1000, 0
pOldProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
SetWindowLong Me.hwnd, GWL_WNDPROC, AddressOf MyProc
End Sub


Private Sub Form_Unload(Cancel As Integer)
KillTimer Me.hwnd, 0
End Sub
窗体模块代码  结束


标准模块   x.bas文件开始
Option Explicit
Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Const GWL_WNDPROC As Long = -4
Public Const WM_SYSCOMMAND As Long = &H112&
Public Const SC_CONTEXTHELP As Long = &HF180&
Public Const WM_TIMER As Long = &H113
Public pOldProc As Long


Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_USER As Long = &H400




Function MyProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg
Case WM_USER + 1
frm1.Print "消息 WM_USER+1, wMsg:" & wMsg & ", wParam:" & wParam & ", lParam:" & lParam
Case WM_SYSCOMMAND
If wParam = SC_CONTEXTHELP Then
Shell "notepad c:windowssystem32eula.txt", vbNormalFocus
End If
Case WM_TIMER
'frm1.Cls
'frm1.Print Now
frm1.Caption = Now
End Select
MyProc = CallWindowProc(pOldProc, hwnd, wMsg, wParam, lParam)
End Function
标准模块x.bas文件结束
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
硬盘这种问题该怎么解决呢 前面六七十G有几个
9月10是自己生日祝福语怎么说
夏季服装,成分写着粘胶,这是什么成分?
新的物权法对地下车位的买卖有什么说法
天津市宝坻区霍各庄镇西双树村南区为什么安不
各位大神,小米可以刷成国际版吗,18种
路痴要怎么样才能让自己有方向感?要如何才能
如何补气
下列事件中,属于不确定事件的是A.2008年奥运
36岁零基础,自学JAVA然后找这方面工作,怎么
martin smith牌电吉他怎么样?是哪个国家的?
【长铃 威驰cm48q-2】怎么换齿轮油
好看的肉不肉小说推荐,肉不肉小说排行榜
为什么男人离婚了就不想复婚
为什么说静止的物体也具有惯性?
推荐资讯
黄河娃地址在什么地方,想过去办事,
一个乘号的左上角有个弯钩猜成语
有没有关于猪笼草的信息?
隔夜花螺放过冰箱可以吃吗?
一个女孩子 外表很秀气纤弱肤白 可性格却很酷
dnf死亡祭礼怎么样
对讲机必须要有中转台么?
为什么在我班里,那些"霸王","地头蛇"我都能
超智能足球里潜龙哪集受了重伤?
邵东县邵阳名新阁专业发型工作室在哪里啊,我
广西老少边山穷县指那些
有做新媒体或者自媒体的吗
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?