|
-
Apr 28th, 2000, 11:57 AM
#1
Thread Starter
Addicted Member
Subclassing a ComboBox Paste Event
What I'm doing is subclassing a ComboBox and trying to disable pasting to it by blocking the WM_PASTE message. However, this doesn't work for some reason. So next I tried listing off all of the messages sent to the ComboBox to see what was being sent to it exactly. What I got confused me even more! Whenever I did a paste (by pressing either <SHIFT>+<INSERT> or <CTRL>+<V> ) these are the mesages that were intercepted:
- WM_COMMAND (&H111)
- wParam = 0400 03E9 (EN_UPDATE + identifier of control)
- lParam = 6D8 (the control handle)
- WM_CTLCOLOREDIT (&H133)
- wParam = 5EE (varies a control Device Context handle)
- lParam = 6D8 (the control handle)
- WM_COMMAND (&H11)
- wParam = 0300 03E9 (EN_CHANGE + identifier of control)
- lParam = 6D8 (the control handle)
OK, so that's all fine and dandy, but how the hell does the Edit portion of the ComboBox receive the/a paste message? I tried it repeatedly and I always got this combination of messages. The odd thing is that I can send (and intercept) a WM_PASTE message to the ComboBox and it works fine!
Can anybody explain to me what is going on?
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
Apr 29th, 2000, 12:26 AM
#2
Thread Starter
Addicted Member
Doesn't anybody know an answer to this?
I really need to know this!
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
Apr 29th, 2000, 09:15 AM
#3
The problem is that the Combobox's Hwnd isn't the Handle receiving the Message, it the "Edit" Class it uses, so you need to Subclass this Window Handle instead, ie.
In a Module:
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare 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
Private Const GWL_WNDPROC = (-4)
Private Const WM_PASTE = &H302
Private lPrevWndProc As Long
Private Function CallBackProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg <> WM_PASTE Then CallBackProc = CallWindowProc(lPrevWndProc, hWnd, Msg, wParam, ByVal lParam)
End Function
Public Sub SubClassComboEdit(ByRef oCombo As ComboBox)
Dim lHwnd As Long
If lPrevWndProc = 0 Then
lHwnd = FindWindowEx(oCombo.hWnd, 0, "Edit", vbNullString)
lPrevWndProc = SetWindowLong(lHwnd, GWL_WNDPROC, AddressOf CallBackProc)
End If
End Sub
Public Sub RemoveSubClass(ByRef oCombo As ComboBox)
Dim lHwnd As Long
If lPrevWndProc Then
lHwnd = FindWindowEx(oCombo.hWnd, 0, "Edit", vbNullString)
Call SetWindowLong(lHwnd, GWL_WNDPROC, lPrevWndProc)
End If
End Sub
In the Form with the Combobox:
Code:
Private Sub Form_Load()
SubClassComboEdit Combo1
End Sub
Private Sub Form_Unload(Cancel As Integer)
RemoveSubClass Combo1
End Sub
-
Apr 29th, 2000, 10:17 AM
#4
Thread Starter
Addicted Member
-
Sep 11th, 2010, 10:13 PM
#5
New Member
Re: Subclassing a ComboBox Paste Event
Aaron Young, I need to block the copy and paste on my combobox and I tried this code of yours, but on the line between ''''
Public Sub SubClassComboEdit(ByRef oCombo As ComboBox)
Dim lHwnd As Long
If lPrevWndProc = 0 Then
''''''lHwnd = FindWindowEx(oCombo.hWnd, 0, "Edit", vbNullString)''''''
lPrevWndProc = SetWindowLong(lHwnd, GWL_WNDPROC, AddressOf CallBackProc)
End If
End Sub
It's coming an error 438.. How can I solve this problem? If u can see it for me, I uploaded it on it: http://rapidshare.com/files/418537411/teste_login.xls
Thanks a lot
PS: Some notes are in portuguese..
-
Sep 12th, 2010, 03:24 AM
#6
Re: Subclassing a ComboBox Paste Event
You do realise that this thread is over 10 years old don't you?
Error 438 means that the object does not support this property or method. In your case, a ComboBox in XL does not have a hwnd property.
-
Sep 12th, 2010, 02:52 PM
#7
New Member
Re: Subclassing a ComboBox Paste Event
hahahaha
No man.. I did'nt realised, because i'm a junior on VBA..
What can I do, you know?
I really need to block the paste and copy on the combobox, I tried many codes and variations till now, but I do not understand it as much it needs to work right :P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|