Click here to Skip to main content
15,667,577 members
Articles / Programming Languages / C++
Posted 3 Nov 2007


14 bookmarked

Greeting Card

Rate me:
Please Sign up or sign in to vote.
2.63/5 (11 votes)
3 Nov 2007CPOL2 min read
This project uses the Transparent window to show the animation on the desktop.


This is a simple win32 dialog based application that shows the animation ( GIF file ) on the transparent dialog box.

Screen Shot

Screenshot - Greeting_Card_0.gif
Screenshot - Greeting_Card_1.gif


This application uses the SetLayeredWindowAttributes to make the window transparent.

SetWindowLong: - It is used to change the attributes of the specified window.
SetLayeredWindowAttributes :- sets the opacity and transparency color key of a layered window.

For more detail on above API please refer to the MSDN.

Making the window transparent is vary easy. You just need to perform following two things.
1) Paint the window with any color you wish. ( I have used dialog box and has colored it black)
2)Make that color (Black color in my case )Transparent using the SetLayeredWindowAttributes API.

Using the code

Following is the line of code used to make the windows transparent:

        //Will Set the Dialog Color to Black
         return (LRESULT)CreateSolidBrush(RGB(0,0,0));

         //Set the Style of the window to layered window.
         SetWindowLong(hWndDlg,GWL_EXSTYLE,GetWindowLong(hWndDlg,GWL_EXSTYLE)| WS_EX_LAYERED ) ;  
         //Set  the black color transparent.

And following is the line of the code used to show the animation ( GIF file ) on the dialog box. Showing GIF file on the dialog box is also too simple. Open the any GIF file you wish to display in Picture Control in Adobe Image ready ( or in any other software that lets you separate the layered picture file in the GIF file) then separate the files and store it as bitmap file.

Now the second part is easy. Take the array of Bitmap handles ( HBITMAP [] ) and load all the bitamaps ( earlier seprated from gif file) into this handles. Then Show all the file in the picture control after some small interval ( say 200 msec ). Interval should be small enough to create the animation effect.

Following is the code that shows how to do it. I have take the picture of the firecracker and showing it in the picture control.

            //Array of Bitmaps require to Create the Animation.
            Cracker[0]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP2));
            Cracker[1]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP3));
            Cracker[2]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP4));
            Cracker[3]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP4));
            Cracker[4]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP6));
            Cracker[5]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP7));
            Cracker[6]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP8));
            Cracker[7]        =    LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP9));

    X= GetSystemMetrics(SM_CXSCREEN);  //Store the screen X and Y axis
    Y= GetSystemMetrics(SM_CYSCREEN);

    Width    =    rect.right    -    rect.left;
    Height    =    rect.bottom    -;
    SetTimer(hWndDlg,0,150,0);     //Sets the Timer of the window

case WM_TIMER:
    SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)Cracker[Count]);
    if (Count++ > 8)
        Count =1;
        //After the animation over it change the position of the Dialog.
        MoveWindow(hWndDlg,rand()%(X - Width ),rand()%(Y -Height) ,Width,Height,TRUE);

Points of Interest

As the Diwali ( Its the biggest festival on india ) is coming near everybody is sending the greeting cards to their friends and family members. So I just made this application to send it as greeting card. It is liked much by my friends. And so I think its better to put it on the code project so that others can also use it.


First submitted on Nov 03 2007


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

Written By
Tester / Quality Assurance
India India
His name is Gaurang Shah. He has completed his bachelor in computer science.Has worked as a System programmer. Currently working as QA Analyst in Pune.

Comments and Discussions

QuestionGreetings?? Pin
Not Active3-Nov-07 14:28
mentorNot Active3-Nov-07 14:28 
AnswerRe: Greetings?? Pin
GauranG Shah5-Nov-07 17:24
GauranG Shah5-Nov-07 17:24 
GeneralVERY CUTE Pin
MrGoodly3-Nov-07 6:37
MrGoodly3-Nov-07 6:37 
GeneralNice Pin
The Wizard of Doze3-Nov-07 6:18
The Wizard of Doze3-Nov-07 6:18 

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.