Results 1 to 4 of 4

Thread: Command Button state

  1. #1

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Question

    How can I set the Command Button's state to clicked/unclicked?
    I know I can use the API message WM_LBUTTONDOWN to force the button to "DOWN". That works but if the focus goes to a newly opened form, the button's state has been initialised to "up"...
    I wonder why...

  2. #2
    Guest
    Send the BM_SETSTATE message.

    Add the following to a Form with 2 CommandButtons.
    Code:
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Const BM_SETSTATE = &HF3
    
    Private Sub Command1_Click()
        PostMessage Command2.hwnd, BM_SETSTATE, 1, 0
    End Sub

  3. #3

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Nice, Mega, but I really should have found it myself if I was not kind of stupid:
    I already used BM_SETSTATE but, I did a copy/paste from some source code on the web and this value was &H4. So that's an error on this site because it means BM_SETSTYLE (sets the border around the button) and not BM_SETSTATE.
    That's why it didn't work out.
    Thanks again for your reply. Now it works fine.

  4. #4

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    PS. I found the erroneous constant at http://www.vbapi.com/ref/b/bm_setstate.html

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