-
How to go about this?
I writing this program that tests the user on the given questions and answers. Now, I'm giving them the option to have multiple choice, fill in the blank, True and Fasle, etc. My question is this...
So, just imagine a static (with the question) and, for example, four radio buttons for multiple choice. But! The next question is a fill-in-the-blank! Which is a static and a text box. How would I go about changing/hiding the four radio buttons from the previous type of question? What I mean is, there are going to be a couple of controls, but then when the type of question changes, there are going to have to be different controls for the different types of questions. How would I do this? Hide all of the controls and then when I need them hide the ones that are on and make the ones needed unhidden? How would I do this?
-
Hmmm, i would suggest writing your own function and passing it some data telling it what the type of question is.
Then use the function ShowWindow() to show/hide your controls.
Say for instance:
Code:
void UpdateDisplayControls(int qtype)
{
if(qtype == 1)
{
//say 1 is fill in the blank so use ShowWindow() to hide your radio
//buttons
}
else
{
//say 2 is mutlipe radio choice, so use ShowWindow() to hide the
//edit box
}
}
Hope that helps, ShowWindow should look like this:
ShowWindow(hWndRadio1, SW_HIDE);
SW_SHOW is the other param :)
Cheers,
TNT
-
Okay, I'll go off from here. Thanks, TNT!
-
Another thing you could do Garf is to create separate arrays for each "screen". Two simple functions like these could be used:
void Show( HWND array[], int thisMany)
{
int c = 0;
while(c < thisMany)
ShowWindow(array[c++], SW_SHOW);
}
void Hide( HWND array[], int thisMany)
{
int c = 0;
while(c < thisMany)
ShowWindow(array[c++], SW_HIDE);
}
-
That's a good idea, Sebastiani. But, the array (you var 'array') would have to be an array of hwnds, because that is the param of ShowWindow. Thanks! I'm going to do it that way.
-
I would create small dialogs for the answer part. ie one with a static and edit for the fill in the blanks and one with the radio buttons for the multi choice.
Create all the answer dlgs at WM_INIT to the correct ratio based on screen size.
Hide them all.
When a question is asked just use SetWindowPos() to paste the right answer dlg to the right place on screen and show it.
Set them up with the same parent and winproc.
This way there is no wasted space where ctrls are there but hidden. (as all the crls are stacked on top of each other in small dlg's)
-
I'm not sure I understand what you are saying. So you make it so that there are separate dlgs besides the main window? I think I might see if I can do it that way.
-
Wow, I was getting ready to make a topic like this... I have almost the same problem. Whenever the player clicks a button on the main screen, my clear screen function i made just covers everything up, so the next screen if you click where that button was it appears again and does whatever it does. So I am not sure how to do this... is there anyway to program this stuff into my clear screen function? btw, here is what it is:
Code:
void ClearWindow(HWND hwnd)
{
HDC hdc = GetDC(hwnd);
RECT rect = {0};
GetClientRect(hwnd,&rect);
FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
ReleaseDC(hwnd,hdc);
}
Thanks lot. and im using C++ regular windows btw.
-
Garfield,
Yes. A seperate dlg for each combination of controls. That is, one for each type of answer. Hide the ones you don't need, show and set position of the one you do as each new question is 'asked'.
Tazar,
If I understand correctly, you need to UpdateWindow() or InvalidateRect() on the button after clearing the screen to make it reappear.
-
>> Tazar,
If I understand correctly, you need to UpdateWindow() or InvalidateRect() on the button after clearing the screen to make it reappear. <<
Wouldn't you need to do both? Invalidating it will only clear it, you'll have to call the procedure's WM_PAINT message to redraw.
-
I want the buttons to be erased for good once they click on the Start Game button. I tried the InvalidateRect Function, but it requires 3 arguments according to the yellow thing that popped up on VC++. The hwnd is ok, then it said
"CONST RECT *lpRect, BOOL bErase);"
So what would i put for them two?
I moved the ShowWindow(hwndStart, SW_HIDE); for all of the buttons into the Clear Screen function, so I guess I put the InvalidateRect Function above them inside the ClearWindow function? thanx!
-
Use GetClientRect (this is the function, I recall) to get the rectangle.
-
>> Tazar, If I understand correctly, you need to UpdateWindow() or InvalidateRect() on the button after clearing the screen to make it reappear. <<
>> Garfield Wouldn't you need to do both? Invalidating it will only clear it, you'll have to call the procedure's WM_PAINT message to redraw.
Both are different methods of sending a paint msg. Paint only draws the invalidated area.