Thread: Checkboxes

  1. #1
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256

    Checkboxes

    I was able to find out how to create a checkbox through a resource with a simple google search, but I can't for the life of me find anything about using one. A little clever MessageBox-ing told me that when I click the box, even though nothing seems to happen, the message is being sent to my dialog. However, I don't know what to do next. Any advice or sample code?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Add the message handler to the message map.

    ON_BN_CLICKED(checkboxID, CallbackFunction)

    Kuphryn

  3. #3
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Add that piece of code under the case for the button's Message? Sweet. Thanks. That's all I needed.

  4. #4
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Okay, maybe that wasn't all. I'm getting an undefined reference error for ON_BN_CLICKED. I ran a search, and it doesn't exist in any of my header files. Did you not mean that literally like you didn't mean checkboxID literally?

  5. #5
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Are you using MFC or the API directly?? The answer to the question will vary depending on what you're using.

    Cheers.

  6. #6
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    That would be API.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    How about the BN_CLICKED message:
    http://msdn.microsoft.com/library/de...bn_clicked.asp

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The BN_CLICKED notification that Knutso has kindly provided a link to will tell you when your checkbox has been clicked (search this board as there are plenty of examples of its use). In order to find out whether the checkbox is checked or not, you'll need to send the checkbox a BM_GETCHECK message with SendMessage; the return value will give you the check state. The IsDlgButtonChecked function accomplishes the same thing.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    So, basically, sending that when the box is clicked switches its state?

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    No, that tells you its current state. The action of clicking will change its state, of course, but if you want to manually change it then send the control a BM_SETCHECK message.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Yeah. I only recently discovered the wonders of MSDN, so I was able to figure that out myself. Sorry to have bothered you guys, and thanks for helping anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xuni: a Graphical User Interface Widget Toolkit
    By dwks in forum Projects and Job Recruitment
    Replies: 45
    Last Post: 06-04-2008, 02:35 PM
  2. ListView and checkboxes
    By Joelito in forum Windows Programming
    Replies: 3
    Last Post: 10-30-2006, 09:31 PM
  3. Checkboxes not Checking?
    By digitaltsai in forum Windows Programming
    Replies: 4
    Last Post: 02-02-2006, 08:21 PM
  4. c++ checkboxes, scroll bars, ect.
    By Rune Hunter in forum C++ Programming
    Replies: 4
    Last Post: 02-03-2005, 06:24 AM
  5. Color Checkboxes
    By SpEcIeS in forum Windows Programming
    Replies: 6
    Last Post: 01-13-2005, 10:02 AM