Introduction
This is a simple win32 dialog based application that shows the animation ( GIF file ) on the transparent dialog box.
Screen Shot
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:
return (LRESULT)CreateSolidBrush(RGB(0,0,0));
break;
case WM_INITDIALOG:
SetWindowLong(hWndDlg,GWL_EXSTYLE,GetWindowLong(hWndDlg,GWL_EXSTYLE)| WS_EX_LAYERED ) ;
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:
{
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);
Y= GetSystemMetrics(SM_CYSCREEN);
GetWindowRect(hWndDlg,&rect);
Width = rect.right - rect.left;
Height = rect.bottom - rect.top;
SetTimer(hWndDlg,0,150,0);
}
break;
case WM_TIMER:
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)Cracker[Count]);
if (Count++ > 8)
{
Count =1;
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