-
I've written a sub that transfers selected text from one box to another, however it's triggered by a double click, and when you double click the text box is programmed to highlight the whole word that the cursor is over. I have the box reselect all the text that was transferred, however you still see the quick flash of the box's reselection from double click. Is there a way to disable this code? Thanks in advance.
-
why put it in a dbl-click? why not just right mouse click and bring up a popupmenu to call the sub?
-
Because I'm programming it for my father, and he wants it this way because he says all the physicians at his office are computer illiterate and that's how he wants it.
-
You can subclass your TextBox to catch the WM_LBUTTONDBLCLK message.
Add to a Module
Code:
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)
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
Const GWL_WNDPROC = (-4)
Private Const WM_LBUTTONDBLCLK = &H203
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_LBUTTONDBLCLK Then
'<-- Add your custom code here-->
Debug.Print Form1.Text1.SelText
Exit Function
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Add to a Form
Code:
Private Sub Form_Load()
SubClassWnd Text1.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd Text1.hwnd
End Sub
-
I've always wondered...what would happen if you didn't put that call in the Form_Unload?
-
its not pretty. Usually windows will crash.