Results 1 to 7 of 7

Thread: Locking a checkbox via API

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 1999
    Location
    Behinf you
    Posts
    24

    Locking a checkbox via API

    Hello,
    I'm trying to find an API that LOCKS a checkbox in VB. There isn't a Locked property for the checkbox but I've heard it can be done. Any ideas?

  2. #2
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Why not disable the box? Use the Enabled property.
    <removed by admin>

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Yeah u beat me to same conclusion Midgets. Or maybe this is another attempt at changing the standard operation of a checkbox to confuse users?
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 1999
    Location
    Behinf you
    Posts
    24
    Changing the enabled property will cause the checkbox to be grayed. I want it to be enabled but that it's value will be locked.

  5. #5
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Ok
    if u dont end up going API way u can always simply have a very small checkbox with no caption and an attached label control that doubles as the checkbox caption. U can add code to the Label click event to change the checkbox value when 'enabled' and to ignore the checkbox value when 'disabled'
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  6. #6
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Use this to drive your users nuts.

    VB Code:
    1. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    2.     (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    3. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    4.     (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. Const GWL_STYLE = -16
    6. Const BS_AUTOCHECKBOX = 1
    7.  
    8. ' Make a checkbox control read-only (or restore its
    9. ' regular behavior).
    10. ' Doesn't work well if the Style property is set to 1-Graphical
    11.  
    12. Sub MakeCheckBoxReadOnly(CheckBox As CheckBox, ByVal bReadOnly As Boolean)
    13.     Dim lStyle As Long
    14.     lStyle = GetWindowLong(CheckBox.hWnd, GWL_STYLE)
    15.     If bReadOnly Then
    16.         lStyle = lStyle Or BS_AUTOCHECKBOX
    17.     Else
    18.         lStyle = lStyle And (Not BS_AUTOCHECKBOX)
    19.     End If
    20.     SetWindowLong CheckBox.hWnd, GWL_STYLE, lStyle
    21. End Sub
    22.  
    23. Private Sub Command1_Click()
    24. Static b As Boolean
    25.     Call MakeCheckBoxReadOnly(Check1, b)
    26.     b = Not b
    27. End Sub

  7. #7
    Addicted Member finn0013's Avatar
    Join Date
    Jan 2001
    Location
    Charleston, SC
    Posts
    222
    Couldn't you just use the LockWindowUpdate API call ?

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