Thread: sorting through BN_CLICKEDs

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    sorting through BN_CLICKEDs

    in Win32 API, when my WndProc receives the BN_CLICKED command, i dont know how to tell different buttons apart. i tried doing a switch case with the HWNDs, like this:

    Code:
    case BN_CLICKED:
      switch ( (HWND)lParam)
      { // <--- error 1
        case hwndButton1:
    
        case hwndButton2:
      }
    but the program wont compile. it gives me three errors.
    the first says "switch expression not integral", pointing to the opening brace.
    the second and third errors are the same, "case expression not constant", and point to each of the case expressions.

    is this the right way to go about identifying controls, or is there a better way?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Shadow12345
    Guest
    case BN_CLICKED:
    switch ( (HWND)(lParam ))
    { // <--- error 1
    case hwndButton1:

    case hwndButton2:
    }

    shrug

    I've got that error before, maybe you are only supposed to use switch with integers

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    because the param is the button id number that you used to create the button. heres what it should look like:

    Code:
    switch(Msg)
    {    case WM_COMMAND:
          {       switch(LOWORD(lParam))  // Find out which control ID
                   {     case CLOSE_BUTTON_ID: // Whatever u named ur control ID
                          {   ..........
                          }
                          default:
                             return(DefWindowProc(hwnd, Msg, wParam, lParam));
                    }
            }
            default:
                 return(DefWindowProc(hwnd,Msg,wParam,lParam));
     }
    Last edited by xds4lx; 09-08-2002 at 12:02 AM.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    what is the button ID?

    Code:
    hwndButton = CreateWindow("BUTTON",  "OK",  
    WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 
    115, 10,100,100, hwnd,  
    NULL,(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),NULL);
    that is how i created the buttons.
    which bit is the ID?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    The parameter you are setting to null right after the parent window's handle, instead do (HMENU)(CONTROLD_ID). If you are using any resources just add a #define CONTORL_IDBLAHBLAHBLAH 1000000 or whatever in the resource.h, if your not using resources just define it in any of your headers or you main cpp file.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  3. Sorting words with a fast, effincient sorting method
    By Unregistered in forum C++ Programming
    Replies: 19
    Last Post: 07-12-2002, 04:21 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 08:05 PM