|
-
May 28th, 2000, 03:05 PM
#1
Thread Starter
Hyperactive Member
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?
-
May 28th, 2000, 03:27 PM
#2
Junior Member
Disable Cursor
To disable cursor, give this single line code in Click event of the textbox:
Me.SetFocus
Kazim Zaidi (the cracker)
-
May 28th, 2000, 03:40 PM
#3
Thread Starter
Hyperactive Member
That doesnt work......
The cursor still stays in the textbox....
-
May 28th, 2000, 05:13 PM
#4
Addicted Member
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
-
May 28th, 2000, 05:47 PM
#5
Thread Starter
Hyperactive Member
This code doesn't work, results in errros.....
But i want to hide the carret
-
May 28th, 2000, 06:20 PM
#6
Addicted Member
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
-
May 28th, 2000, 06:33 PM
#7
Thread Starter
Hyperactive Member
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?
-
May 28th, 2000, 06:41 PM
#8
Addicted Member
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
-
May 28th, 2000, 07:02 PM
#9
Thread Starter
Hyperactive Member
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
-
May 28th, 2000, 07:48 PM
#10
Thread Starter
Hyperactive Member
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
-
May 29th, 2000, 01:10 AM
#11
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.
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
|