Thread: couple of questions on drawing text and buttons

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001

    couple of questions on drawing text and buttons

    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:
    BitBlt(hDC, 0, 0, rcClient.right, rcClient.bottom-45, hDCMem, 0, 0, WHITENESS);
    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.

    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?

    void Ask(HDC hDC, RECT* prc, QUESTION quest)
    	HDC hDCMem = CreateCompatibleDC(hDC);
    	COLORREF BgColor = GetBkColor(hDC);
    	int      BkMode  = GetBkMode(hDC);
    	int questsize, choicesize;
    	SetBkColor(hDCMem, BgColor);
    	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);
    	ReleaseDC(hWnd, hDCMem);
    	//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);
    Oh, and yes I now know I can use strlen for the string size. I'll be changing that.

  2. #2
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    anyone know this one?

  3. #3
    Join Date
    Jan 2002
    Handle the WM_ERASEBKGND message to erase the window background and do your text rendering during WM_PAINT handling. When you need to change the text simply use InvalidateRect, with the last parameter of the function set to TRUE to ensure the back ground is erased and set the second parameter to the rectangle you wish to overwrite ie:
    RECT rcToOverWrite;
    //set the dimensions of the update rectangle
    SetRect(&rcToOverWrite,20,20,200,200); //modify to fit
    where hwnd is your window handle. This ensures that the specified rectangle is erased at the next WM_PAINT event.

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    i think i get what you mean. i just used InvalidateRect(hWnd, &rcClient, TRUE) instead of blitting the hDCMem with WHITENESS.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. text box & buttons on window .. pls help urgent ???
    By intruder in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2002, 10:28 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM