Results 1 to 11 of 11

Thread: Disable cursor in textbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343

    Question

    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?

  2. #2
    Junior Member
    Join Date
    May 2000
    Location
    New Delhi, India
    Posts
    18

    Lightbulb Disable Cursor

    To disable cursor, give this single line code in Click event of the textbox:

    Me.SetFocus
    Kazim Zaidi (the cracker)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    That doesnt work......

    The cursor still stays in the textbox....


  4. #4
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    This code doesn't work, results in errros.....

    But i want to hide the carret

  6. #6
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    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?




  8. #8
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    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

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    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

  11. #11
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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
  •  



Click Here to Expand Forum to Full Width