For school I'm making a trivia game with the windows gdi. You select either 1, 2, or 3 players. Then it draws the question, you hit a button either a b c or d and then the answer is displayed, at which time you are then able to hit "next question".
My question is this: My function to ask a question draws the text right onto the main DC. The problem is that the previous text stays on the screen since I don't draw onto a buffer, then blit to the main DC. I have to use a not-so-good way to clear the screen.
This is how I have to do it:
It's just a blank DC blitted onto the main DC, i skip the bottom because otherwise it goes right over my buttons. Now here is my Ask() function. Could someone help me on how to draw first to a buffer then blit the buffer to the main DC? My attempt is commented out.
BitBlt(hDC, 0, 0, rcClient.right, rcClient.bottom-45, hDCMem, 0, 0, WHITENESS);
So in all, here are my questions:
A) How do I get my Ask() function to write first to a buffer, then onto the main DC?
B) How can I blit onto the main DC, over the whole client rect size, and not make my buttons disappear?
Oh, and yes I now know I can use strlen for the string size. I'll be changing that.
void Ask(HDC hDC, RECT* prc, QUESTION quest)
HDC hDCMem = CreateCompatibleDC(hDC);
COLORREF BgColor = GetBkColor(hDC);
int BkMode = GetBkMode(hDC);
int questsize, choicesize;
SetBkMode (hDCMem, BkMode );
//DrawText(hDC, message, -1, prc, DT_WORDBREAK);
for(int i=0; i <= MAX_NUM; i++)
if((quest.question)[i] == '?')
questsize = i+1;
for(i=0; i<=MAX_NUM; i++)
if((quest.choices)[i] == '.')
choicesize = i+1;
TextOut(hDC, 5, 5, current_player->playername, strlen(current_player->playername));
TextOut(hDC, 5, 25, quest.question, questsize);
TextOut(hDC, 5, 45, quest.choices , choicesize);
//TextOut(hDCMem, 5, 5, current_player->playername, strlen(current_player->playername));
//TextOut(hDCMem, 5, 25, quest.question, questsize);
//TextOut(hDCMem, 5, 45, quest.choices , choicesize);
//BitBlt(hDC, 0, 0, prc->right, prc->bottom, hDCMem, 0, 0, SRCCOPY);