Thread: Displaying Text in Multiple Areas of the Client Window in WinMain

  1. #1
    Registered User
    Join Date
    Dec 2006

    Question Displaying Text in Multiple Areas of the Client Window in WinMain

    I have a Win32 application.
    I would like to display some text in various areas of my client window.

    So, I have in WndProc case WM_PAINT. In it I have all the things related to drawing including TextOut, of course.

    		// start X coordinate
    		// start Y coordinate
    		// what to print
    		// how many characters of text_to_draw to display
    Somewhere in my WinMain I would have something set all those variables to what I need, then I would call InvalidateRect() to generate WM_PAINT message and draw "tol_imp->text_to_draw".

    So far so good.

    But then if, immediately after InvalidateRect above, I proceed to change the text_to_draw and its companion variables to something else, hoping to have windows draw it in a different area of the window, the result is only the last thing gets drawn.
    It's like after the first InvalidateRect call, it doesn't take its time to finish drawing out the text then current in my text_to_draw variable, but continues on to the next statement where I change text_to_draw to the next bit of text and draws that.

    Any help on how I could draw differenct text strings in different parts of the window?
    (Alert, just started windows-based programming. Have been writing main() applications up to this point).

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Welcome to the forums!

    Calling InvalidateRect effectively posts a WM_PAINT message. This means that InvalidateRect will return immediately and the WM_PAINT will only be processed after all other waiting messages have been processed. Also, if you call InvalidateRect multiple times, they may be combined into one WM_PAINT message.

    If you wanted the InvalidateRect to be processed immediately, you could call UpdateWindow straight after InvalidateRect.

    However, this approach, as well as being inefficient, will not work. When your window needs repainting (for example, when it is covered and uncovered by another window) you will no longer have the information required to redraw.

    A better approach would be to collect your drawing operations in a vector and then loop through the vector in your WM_PAINT call.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Thanks for answering.
    Ok, I'll learn about vectors if I really have to (I do c programming, unfortunately, not c++, and I am not really a programmer to begin with).
    Would there be a link to an example someplace, perhaps?
    I am not entirely clear what the process of "collecting my drawing operations in a vector" actually entails.
    Thanks again.

  4. #4
    Registered User
    Join Date
    Dec 2006

    still wondering

    Just to say, I still haven't figured out that thing about collecting my drawing into a vector. Example anyone?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  4. displaying text in a MFC AppWizard window
    By that guy in forum Windows Programming
    Replies: 5
    Last Post: 07-23-2002, 11:40 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM