Anyone know how to disable the cursor in a textbox in VB6? The textbox must be enabled and locked. But i dont want the cursor to blink when i click in the textbox.
Any suggetions?
Printable View
Anyone know how to disable the cursor in a textbox in VB6? The textbox must be enabled and locked. But i dont want the cursor to blink when i click in the textbox.
Any suggetions?
To disable cursor, give this single line code in Click event of the textbox:
Me.SetFocus
That doesnt work......
The cursor still stays in the textbox....
I'm not sure if this is what you're looking for, but this will hide the caret.
Put this in a module:
Option Explicit
Public OldWindowProc 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
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_USER = &H400
Private Declare Function HideCaret Lib "user32" (ByVal hwnd As Long) As Long
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const WM_RESERVED = &H100E
Const WM_PAINT = &HF
If msg = WM_PAINT Or msg = WM_RESERVED _
Then HideCaret Form1.Text1.hwnd
NewWindowProc = CallWindowProc( _
OldWindowProc, hwnd, msg, wParam, _
lParam)
End Function
Then put this in your Form Load, to get rid of the caret in Text1:
Private Sub Form_Load()
OldWindowProc = SetWindowLong( _
Text1.hwnd, GWL_WNDPROC, _
AddressOf NewWindowProc)
End Sub
Hope that helps you
GRAHAM :)
This code doesn't work, results in errros.....
But i want to hide the carret
I can assure you the code does work, check your typing, and make sure you have Option Explicit at form level.
I,ve just used this in a recent project, to allow editing by double clicking in a text box.
Cheers
GRAHAM :)
I got the code to work now, but now i get some errors when i stop the project to go back to design view. VB shutsdown...
Do you have the same problem?
Hi again,
No, I haven't had any problems with this code at all.
I downloaded an example of this from VB-Helper.
You can go straight to the zip download at:
http://www.vb-helper.com/howto/nocaret.zip
Cheers
GRAHAM ;)
Hi!
The code works great in runtime, but i still get a VB6 error when i stop the program, and VB shutsdown... I'm gonna reinstall vb and see if that solves the problem. What version of VB do you run? Do you have the service pack 3 installed if you are running VB6 ??
Thanks for the help with the code!
Cheers
Smirre
Hi Again!
Now the code works super great!!!
The problem was when i clicked the stop button, when i click the close button everything works great, no crash....
Cheers
Smirre
Yep, if you subclass a window, it is advisable to put the old window procedure back before closing.
I would put this in Form_Unload:
OldWindowProc = SetWindowLong( _
Text1.hwnd, GWL_WNDPROC, _
OldWindowProc)
Oh, yeah. If you go into debug mode, some weird behaviour is possible. The new windows procedure for the textbox is unreachable at that moment.