使用API函数
Public Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONDOWN = &H204Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic prevWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONDOWN Then
Else
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End If
End Function
Private Sub Command1_Click()
prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC)
SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc
Command1.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If prevWndProc <> 0 Then
SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc
prevWndProc = 0
End If
End Sub
Public Const GWL_WNDPROC = (-4)
Public Const WM_RBUTTONDOWN = &H204Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic prevWndProc As LongFunction WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_RBUTTONDOWN Then
Else
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End If
End Function
Private Sub Command1_Click()
prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC)
SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc
Command1.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If prevWndProc <> 0 Then
SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc
prevWndProc = 0
End If
End Sub
解决方案 »
- 如何把数据库里表的记录传给textbox控件数组?
- 用ListView和TreeView控件编写类似Windows资源管理器的拖拽功能。
- 有个MM在QQ上问静态编译在哪里设置,马上结贴
- 在vb中如何把ACCESS中的数据表导到EXCEL文件指定的SHEET中
- 在程序里怎么得到菜单,让它动态enable disable
- 哪位知道如何在picturebox中写入文本
- 极简单问题,两个控件有重叠部分,程序运行时如何调整它们的显示方式,也就是谁在谁的上面!
- 菜单问题?
- VB运行出错,请高人指点
- (100分)我正在制作OCX,...
- 会点vb,会点asp,会点jsp,我想换工作!谁能告诉我该去哪儿?
- ado对vfp的连接访问方式有几个!是不是就要通过ODBC!能不能直接访问那?很急阿
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "可显示用户菜单的文本框"
ClientHeight = 1755
ClientLeft = 45
ClientTop = 330
ClientWidth = 4860
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 1755
ScaleWidth = 4860
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 270
Left = 2393
TabIndex = 0
Top = 840
Width = 2415
End
Begin VB.TextBox Text2
Height = 270
Left = 2400
TabIndex = 1
Top = 1320
Width = 2415
End
Begin VB.Label Label3
Caption = $"FORM1.frx":0000
Height = 615
Left = 120
TabIndex = 4
Top = 120
Width = 4575
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "标准的文本框:"
Height = 255
Left = 120
TabIndex = 3
Top = 855
Width = 2175
End
Begin VB.Label Label2
Alignment = 1 'Right Justify
Caption = "可显示用户菜单的文本框:"
Height = 255
Left = 120
TabIndex = 2
Top = 1320
Width = 2175
End
Begin VB.Menu mnuMain
Caption = "菜单"
Visible = 0 'False
Begin VB.Menu mnu1
Caption = "示例菜单1"
End
Begin VB.Menu mnu2
Caption = "示例菜单2"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
With Text2
.Enabled = False
PopupMenu mnuMain
.Enabled = True
.SetFocus
End With
End If
End Sub
http://support.microsoft.com/support/kb/articles/Q224/3/02.aspHOWTO: Suppress Default Pop-up Menu When Using Custom Menu
http://support.microsoft.com/support/kb/articles/Q191/6/70.asp
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
if button=2 then
popupmenu yourmenu
end if
End SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
if button=2 then
popupmenu yourmenu
end if
End Sub