Click here to Skip to main content
15,892,161 members
Articles / Multimedia / GDI
Tip/Trick

GDI Animations in Different Parts of a Window

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
6 Jan 2012CPOL2 min read 15.9K   2   3


Introduction


I recently saw (don't remember where, may be on a site related to OpenGL) a screen with 4 parts, each displaying a different thing. Hence the question that came to me was how would I do that in GDI? And some animations would be fun too.

As a beginner, I started to Google around (may be not enough) but didn't find what I really had in mind. Sure MSDN has a lot of stuff and I started to read it, but eh, it was time to gather the pieces and start programing.


Details


By now, my GDI beginner's mantra is:

  • Nothing magical
  • SetPixel does it all
  • Nothing voodoo
  • BitBlt does it too

Once it's clear that multiple display is just a matter of selecting coordinates where to place pixels, things take an easier turn. Playing around with BitBlt, StrechtBlt (for scaling), SetPixel (for rotation, haven't yet tried PlgBlt) is fun ... when you know ... but when you begin you surely would like to get encouraged without being overwhelmed with tones of details sometimes hard to fathom.

I'd like to try here a little analogy between the drawing process with GDI and the real world.


Get a device context (think of it as a drawing surface) Take a sheet of paper (from the copy machine down the corridor)
Load an image (bunch of bits) in memory Choose an image that goes through your mind
Transfer the bits (BitBlt) from the memory to the video card frame buffer (its RAM) for display Transfer from your mind to the sheet of paper
Restore objects borrowed to the system (avoid GDI objects/memory leaks)Give your co-worker his golden pen back.


Not being my intention to dissert on windows programming and the message pump, I would just say that the WM_PAINT message is where to put the code to get started as the Win 32 project template under VS 2010 kindly invites to.

Animations lie on timers and on displaying at a different coordinates (or displaying something else).



The trick is just to declare the timers when Windows creates the window (under the WM_CREATE message) and unset them when (just before) the window is destroyed. I preferred to use callback functions rather than dealing with the WM_TIMER message.

The figure above shows a repeated pattern in the upper left quadrant, a scaling in the upper right quadrant, a rotation in the lower left quadrant and a scrolling text in the lower right one. Animations are toggled by the SPACE bar.


That's it, apart may be from the small rotation matrix, the rest of the code was pretty straightforward.


Althought it's perfectible, I'd like to think of it as a nice starting point that might give the desire to explore game programming.


Any comment, improvement, constructive critic is welcome. Till then, happy coding fellow beginners.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Biel Simon27-Mar-14 22:27
Biel Simon27-Mar-14 22:27 
GeneralRe: My vote of 1 Pin
nbaa6716-Oct-14 10:06
nbaa6716-Oct-14 10:06 
Generala couple of good tricks I have learnt when doing this sort o... Pin
Member 78913269-Jan-12 17:48
Member 78913269-Jan-12 17:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.