Can you have ranges in a switch statement?
-
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 | 3oh 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:
-
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 | 3oh 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:
2. Look up CWnd::IsZoomed in MSDN Michael :-)
-
2. Look up CWnd::IsZoomed in MSDN Michael :-)
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:
-
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 | 3oh 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:
- 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
-
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 | 3oh 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:
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 else3.) Try Chris Maunder's Grid Control. Jon Sagara "Ninety percent of baseball is mental, the other half is physical." -- Yogi Bera
-
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 | 3oh 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:
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:
-
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 | 3oh 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:
- Yes, if you use Pascal instead of C/C++ ;P . (Silly answer).
- You can also use GetWindowPlacement() for the general case, but IsZoomed() as pointed out earlier, is definitely easier.
- 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
-
- Yes, if you use Pascal instead of C/C++ ;P . (Silly answer).
- You can also use GetWindowPlacement() for the general case, but IsZoomed() as pointed out earlier, is definitely easier.
- 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
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: