Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can you have ranges in a switch statement?

Can you have ranges in a switch statement?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chambers
    wrote on last edited by
    #1

    Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

    switch (i)
    {
    case 0..20 : do something;
    case 20..120 : do something;
    case 170..450 : do something;
    }

    Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

    1 | 2 | 3
    3 | 2 | 1
    2 | 1 | 3

    oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

    M A J C R 5 Replies Last reply
    0
    • C Chambers

      Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

      switch (i)
      {
      case 0..20 : do something;
      case 20..120 : do something;
      case 170..450 : do something;
      }

      Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

      1 | 2 | 3
      3 | 2 | 1
      2 | 1 | 3

      oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      2. Look up CWnd::IsZoomed in MSDN Michael :-)

      C 1 Reply Last reply
      0
      • M Michael P Butler

        2. Look up CWnd::IsZoomed in MSDN Michael :-)

        C Offline
        C Offline
        Chambers
        wrote on last edited by
        #3

        Michael your answer to question was Perfect! What a weird name to call it though? I was looking through the MSDN help for IsMaximized etc etc.., ah well you live and learn, Thanks for the response Michael, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

        1 Reply Last reply
        0
        • C Chambers

          Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

          switch (i)
          {
          case 0..20 : do something;
          case 20..120 : do something;
          case 170..450 : do something;
          }

          Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

          1 | 2 | 3
          3 | 2 | 1
          2 | 1 | 3

          oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4
          1. Nope, you can't do ranges, unfortunately. You need to use an "if" statement. 2) IsZoomed, as answered by Michael. 3) I don't know. You want to create a custom data entry control? Why not use several edit controls placed next to each other? Regards, Alvaro
          1 Reply Last reply
          0
          • C Chambers

            Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

            switch (i)
            {
            case 0..20 : do something;
            case 20..120 : do something;
            case 170..450 : do something;
            }

            Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

            1 | 2 | 3
            3 | 2 | 1
            2 | 1 | 3

            oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

            J Offline
            J Offline
            Jon Sagara
            wrote on last edited by
            #5

            1.)

            switch (i)
            {
            case 0:
            case 1:
            case 2:
            ...
            case 20:
            // do something
            break;
            case 21:
            case 22:
            ...
            case 450:
            // do something
            break;
            }

            Though you should just use an if statement.

            if (/* i is in range 1 */)
            // do something
            else if (/* i is in range 2 */)
            // do something else
            else
            // do something else else

            3.) Try Chris Maunder's Grid Control. Jon Sagara "Ninety percent of baseball is mental, the other half is physical." -- Yogi Bera

            1 Reply Last reply
            0
            • C Chambers

              Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

              switch (i)
              {
              case 0..20 : do something;
              case 20..120 : do something;
              case 170..450 : do something;
              }

              Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

              1 | 2 | 3
              3 | 2 | 1
              2 | 1 | 3

              oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

              C Offline
              C Offline
              Chambers
              wrote on last edited by
              #6

              Thanks for the responses guys, especially for the Grid control link (Jon) cos its pretty much what I need (i need a simplified version, but I`ll just cut it down to that). I didn`t think you could have the ranges in a switch statement (since there are no books that describe how to) so thanks to both Alvaro and Jon for reaffirming my doubts. Oh and thanks to Chris Mauder for actually producing the Grid Control and making it freely available. Cheers guys, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

              1 Reply Last reply
              0
              • C Chambers

                Hi guys, I actually have three unrelated questions that I would like answered, they are : 1.) Can you have ranges in a switch statment, i.e.

                switch (i)
                {
                case 0..20 : do something;
                case 20..120 : do something;
                case 170..450 : do something;
                }

                Obviously the dotted line doesn`t work, but what do I have to do to get such a switch statement to work? 2.) Is there any way of getting the maximized state of a child window, without using one of the OnDoSomething() functions, i.e. is there a function in MFC which will tell me, true or false, the current child window is maximized? 3.) How can I create one control that holds separate integers in the format :

                1 | 2 | 3
                3 | 2 | 1
                2 | 1 | 3

                oh I also would like to know how to make it change size, say to hold five integers accross, and maybe three down. Thanks for reading this far guys, if you know the answer to any of the three questions, or merely have an idea, please let me know, I would be very grateful. Thanking you all, Alan.;) "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7
                1. Yes, if you use Pascal instead of C/C++ ;P . (Silly answer).
                2. You can also use GetWindowPlacement() for the general case, but IsZoomed() as pointed out earlier, is definitely easier.
                3. In general, you need to override the control's WM_PAINT handler to "do the right thing", i.e. display the numbers in an appropriate format. You can use Chris' grid control, but if you want your class to be lightweight, you'll probably want to just override OnPaint().

                /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

                C 1 Reply Last reply
                0
                • R Ravi Bhavnani
                  1. Yes, if you use Pascal instead of C/C++ ;P . (Silly answer).
                  2. You can also use GetWindowPlacement() for the general case, but IsZoomed() as pointed out earlier, is definitely easier.
                  3. In general, you need to override the control's WM_PAINT handler to "do the right thing", i.e. display the numbers in an appropriate format. You can use Chris' grid control, but if you want your class to be lightweight, you'll probably want to just override OnPaint().

                  /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

                  C Offline
                  C Offline
                  Chambers
                  wrote on last edited by
                  #8

                  In response to your answers : 1. Yep, thats why I asked if you could do it in C++. 2. Its definately the easiest function, and the most appropriate for what I want. 3. I am seriously thinking of doing your OnPaint overriding advice, cos I've had a look at Chris's non-MFC code, and I must be honest, I`m struggling to understand it. Thanks for your response though, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups