Thread: Missing checkbox...

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Missing checkbox...

    I have 3 buttons on my window and 1 checkbox. I get no errors
    when my program compiles/links but when it runs the checkbox is
    no where to be found.

    Here's my code:
    Code:
    //in my message handler
    
    case WM_CREATE:
    
    CreateWindowEx(0,"Button","End Turn",WS_CHILD | WS_VISIBLE 
    | BS_DEFPUSHBUTTON,245,50,60,30,hwnd,
    NULL,hInstMain,NULL);
    
    CreateWindowEx(0,"CheckBox","CheckBox",WS_CHILD | 
    WS_VISIBLE | BS_CHECKBOX,245,90,60,30,hwnd,
    NULL,hInstMain,NULL);
    Any ideas of what I'm doing wrong? The MSDN library wasn't too helpful. Thanks in advance for any advice.

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    You are passing the wrong class name to the CreateWindowEx function it should be "button" not "checkbox", b/c a checkbox is a type of button. Just change that and it should work fine.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Thanks, xds4lx. That fixed that problem, but now I've got a new one. How do I change the state of the checkbox. I can identify when it was clicked on (by checking the (HWND)lparam value when a WM_COMMAND message comes in) but I don't know how to "check/uncheck" the checkbox.

    I read through the MSDN help for it and tried the CButton::Create(blah,blah,blah) but it gave me errors like:

    error C2653: 'CButton' : is not a class or namespace name
    error C2065: 'Create' : undeclared identifier

    I've tried declaring an instance of the CButton class with:
    CButton cbCheckBox;

    And then using:
    cbCheckBox("Test",WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
    &rcCheckBox,&hwnd,NULL);

    This gives me errors:
    error C2146: syntax error : missing ';' before identifier 'cbCB'
    error C2501: 'CButton' : missing storage-class or type specifiers
    error C1004: unexpected end of file found

    Does anyone know of a good tutorial for using Command Buttons/Checkboxes, etc. WITHOUT using MFC?

    Again, thanks.

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Ok, when you are processing the WM_COMMAND message you should do something like this:
    Code:
    ....
    case WM_COMMAND:
    {    switch(LOWORD(wParam)) // which control (button or otherwise
         {                      // caused the message
              case MY_CHECKBOX: // this should be the id you used when 
              {                 // creating your "button"
                  switch(HIWORD(wParam))
                  {  case BN_CLICKED:
                     {  SendMessage(hButton, BM_SETCHECK, 1,0);
                        // The params are the control (or buttons hwnd, 
                        // the message to send, this case button set 
                        //check, 1 to tell it to check, 0 to uncheck, and 
                        //the last param should always be a 0!, or you 
                        //can use BM_GETCHECK to check the state of the 
                       //button, just look up "Button Messages in msdn"
                        return(0);
                       }
                      default:
                        return DefWindowProc(hWnd,Msg,wParam,lParam);
                   }
                 return(0);
                 }
             }
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Thanks again, xds4lx! It actually makes sense now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM