Click here to Skip to main content
Licence CPOL
First Posted 3 Nov 2007
Views 15,671
Downloads 196
Bookmarked 12 times

Greeting Card

By | 3 Nov 2007 | Article
This project uses the Transparent window to show the animation on the desktop.

Introduction

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

Background

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:

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

case  WM_INITDIALOG:
         //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.
         SetLayeredWindowAttributes(hWndDlg,RGB(0,0,0),0,LWA_COLORKEY);
         break;

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.

case  WM_INITDIALOG:
        { 
            //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);

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

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);
    }
    break;

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.

History

First submitted on Nov 03 2007

License

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

About the Author

GauranG Shah

Tester / Quality Assurance

India India

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGreetings?? PinmvpMark Nischalke14:28 3 Nov '07  
AnswerRe: Greetings?? PinmemberGauranG3317:24 5 Nov '07  
GeneralVERY CUTE PinmemberMrGoodly6:37 3 Nov '07  
GeneralNice PinmemberThe Wizard of Doze6:18 3 Nov '07  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 3 Nov 2007
Article Copyright 2007 by GauranG Shah
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid