Click here to Skip to main content
11,805,604 members (54,402 online)
Click here to Skip to main content

T-Rex animation

, 23 Apr 2014 CPOL 10K 594 18
Rate this:
Please Sign up or sign in to vote.
Self contained EXE animation


This is a self contained EXE composited animation, written in procedural code with the low level SDK programming FLAT API, to get rid of any external dependencies.


While I could have used the extended layered style, i made the choice of using the desktop composition feature, introduced in Windows Vista.

When desktop composition is enabled, individual windows no longer draw directly to the screen or primary display device as they did in previous versions of Windows.
Instead, their drawing is redirected to off-screen surfaces in video memory, which are then rendered into a desktop image and presented on the display.

In Windows 8, Desktop Window Manager (DWM) is always ON and cannot be disabled by end users and apps. As in Windows 7, DWM is used to compose the desktop.

In Windows Vista and Windows 7, desktop composition is enabled only with the AERO Glass Theme.

The GDIPLUS flat API is used to display each frame of the PNG image in loop mode, and the T-Rex roar is using a standard WAV audio remixed to match exactly the animation duration.
Everything is embedded as resource, to produce only one single final EXE file.

Using the code

The source code written in C++ is self explanatory, and designed to work in 64-bit mode (VS2010+).

Load_TREX is the main function in charge of loading the embedded resources

    LONG_PTR nRet = 0;
    HRSRC hResource = FindResource(gP.instance, MAKEINTRESOURCE(TREX), RT_RCDATA);
    if (hResource) {
       long imageSize = SizeofResource(gP.instance, hResource);
       if (imageSize) {
          LPVOID pResourceData = LockResource(LoadResource(gP.instance, hResource));
          if (pResourceData) {
             HGLOBAL MemBuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, imageSize);
             if (MemBuffer) {
                LPVOID pBuffer = GlobalLock(MemBuffer);
                if (pBuffer) {
                   CopyMemory(pBuffer, pResourceData, imageSize);
                   LPSTREAM pStream = NULL;
                   if (CreateStreamOnHGlobal(MemBuffer, FALSE, &pStream) == 0) {
                      LONG_PTR hImage = 0;
                      if (GdipCreateBitmapFromStream(pStream, hImage) == 0) {
                         nRet = hImage;
                      ReleaseObject((PFUNKNOWN*) pStream);
    return nRet;

Points of Interest

The animation itself is performed from a child thread, rather than using a timer (but the timer code is also provided). The main advantage of using a thread is when dealing with multi-core, and when you have to use animation while the main process is running.

There is a much more complex demo based on the same DWM composited concept, here:

How to use the animation

Use drag and drop to move T-Rex everywhere on the desktop.
To close the animation, press the escape key or the ALT-F4 key combination.

And for those that are unable to compile the code, here is the link to download the EXE:


Here is another animation (written in PowerBASIC), but it is based on the same concept

If you like them i have a few more Smile | :)


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


About the Author

Software Developer zapsolution
France France
I am a low level SDK programmer, focusing mainly on graphic imaging and multimedia applications.
I am using several languages, including C, C++, PowerBASIC, WinDev.
I wrote also a few demos in C#, but i never used DotNET in real code production.

You may also be interested in...

Comments and Discussions

QuestionWow Pin
N. Henrik Lauridsen31-May-15 4:13
memberN. Henrik Lauridsen31-May-15 4:13 
QuestionT-Rex is not a valid win32 application Pin
myyr23-Apr-14 8:13
membermyyr23-Apr-14 8:13 
AnswerRe: T-Rex is not a valid win32 application Pin
zapsolution23-Apr-14 8:32
memberzapsolution23-Apr-14 8:32 
GeneralRe: T-Rex is not a valid win32 application Pin
myyr15-May-14 11:28
membermyyr15-May-14 11:28 
QuestionNew animations Pin
zapsolution23-Apr-14 7:47
memberzapsolution23-Apr-14 7:47 
QuestionHow to start? Pin
Rookev22-Apr-14 21:41
memberRookev22-Apr-14 21:41 
AnswerRe: How to start? Pin
zapsolution22-Apr-14 22:16
memberzapsolution22-Apr-14 22:16 
GeneralRe: How to start? Pin
Ronny9322-Apr-14 23:10
memberRonny9322-Apr-14 23:10 
GeneralCompiled EXE Pin
zapsolution23-Apr-14 2:10
memberzapsolution23-Apr-14 2:10 
GeneralRe: Compiled EXE Pin
Ronny9323-Apr-14 2:17
memberRonny9323-Apr-14 2:17 
QuestionAt last! Pin
megaadam22-Apr-14 3:44
membermegaadam22-Apr-14 3:44 
AnswerRe: At last! Pin
zapsolution22-Apr-14 22:19
memberzapsolution22-Apr-14 22:19 
GeneralRe: At last! Pin
megaadam23-Apr-14 0:45
membermegaadam23-Apr-14 0:45 
Questionfiles Pin
Nagrom22-Apr-14 1:39
memberNagrom22-Apr-14 1:39 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 23 Apr 2014
Article Copyright 2014 by zapsolution
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid