Click here to Skip to main content
15,887,416 members
Articles / Desktop Programming / MFC
Article

Loading AVI Resources from Shell32.dll file

Rate me:
Please Sign up or sign in to vote.
3.95/5 (21 votes)
8 Apr 20031 min read 99.1K   2.6K   32   10
This program loads AVI animation clips from shell32.dll file and minimizes the executable file size (like for SFX).

Sample Image - AVI_Animation.jpg

Introduction

This is a simple Win32 API project which will load the AVI clips directly from the Shell32.dll file and you can minimize the file size, so that you will not have to include the animations like file copy or file move into your SFX.

I am a fan of building small sized, standalone exes which have minimum dependencies and don't need the setup programs. I hope this article will help those who want to minimize application size.

Here I have used the CreateWindowEx API function to create the animation control and to add it dynamically to the main dialog window.

Code

The global variables

//Handle and Instance
HWND AnimationCtrl;
HINSTANCE gInstance,avi;

Now just create the main dialog procedure and control and the program is ready for you. Here we are setting the instance of animation control to shell32.dll and so we will do not have to load the AVI form file. Just access the resources as regular example: 161,162 etc...

//Main Dialog procedure
BOOL CALLBACK MainDlgProc(HWND hDlg, UINT message, 
                          WPARAM wParam, LPARAM lParam)
{

    if(message==WM_QUIT||message==WM_CLOSE)
        PostQuitMessage(0);


    if(message==WM_INITDIALOG)
    {

        //Creates the animation control
        if((avi=LoadLibrary("Shell32.dll"))==NULL)
        {
            MessageBox(hDlg,"Unable to load library.","ANI",0);
        }
        else
        {
            //Library loaded now create the animation control
            AnimationCtrl=CreateWindowEx(0,  //Style   
                        ANIMATE_CLASS,             //Class Name   
                        NULL,                      //Window name   
                        WS_CHILD|WS_VISIBLE|       //Window Style   
                        ACS_TRANSPARENT|ACS_CENTER,
                        0,                         //Left   
                        0,                         //Top   
                        300,                       //Right   
                        60,                        //Bottom   
                        hDlg,                      //Handle of parent   
                        NULL,                      //Menu   
                        avi,                       //hInstance
                        NULL);                     //User defined style   

            //Control created Now open the avi resource
            if(SendMessage(AnimationCtrl,
                   ACM_OPEN,(WPARAM)avi,(LPARAM)161)==NULL)
                MessageBox(hDlg,"Cannot Load the avi resource","ANI",0);
            else
                SendMessage(AnimationCtrl,ACM_PLAY,
                             (WPARAM)-1,MAKELONG(0,-1));

        }

    }

    if(message==WM_COMMAND)
    {
        if(LOWORD(wParam)==IDCANCEL)
        {
            PostQuitMessage(0);
            EndDialog(hDlg,0);
        }
    }

    return 0;

}

And the WinMain

//Main WIndow
int WINAPI WinMain(HINSTANCE hInstance,
      HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
    InitCommonControls();
    gInstance=hInstance;
    DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,MainDlgProc);
    return 0;

}

In this way, with a small code you can access the AVI resources form the shell32.dll file or any DLL. Just change the LoadLibrary() function.

If you really like this article then mail me your comments at: yogmj@hotmail.com and if you are interested in using small size Win32 applications then visit my website which is being created. The SuperSplit application is based on this code, has a too much small size (less than few KB!) and good functionality and is a good example of using this control; you may download it form my home page.

Distribute this code freely but not for any profit. I am waiting for your reply...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer AVAYA India Pvt Ltd.
India India
I have completed my B.E. Degree in IT form Aditya Engineering College, Beed. (Maharashtra) India.

I have completed Diploma In Advanced Computing (DAC) in Feb 07.

Now I am working for AVAYA India Pvt. LTD as software engineer.
Platform : C/C++, Solaris 10, AIX and Windows

Comments and Discussions

 
QuestionTranslation Pin
paolo71xx11-Jul-18 7:54
paolo71xx11-Jul-18 7:54 
QuestionHow do you figure out the resource ID for the animation? Pin
ARB706-Jul-06 1:35
ARB706-Jul-06 1:35 
AnswerRe: How do you figure out the resource ID for the animation? Pin
ARB706-Jul-06 6:18
ARB706-Jul-06 6:18 
Well I sort of figured this myself by adding the following code before the main window proc ...

<code>
#include <windows.h>
#include <commctrl.h>
#include <string>
#include "resource.h"

//Handle and Instance
HWND AnimationCtrl, gDlg;
HINSTANCE gInstance,avi;

const int begin_resource_id = 160;
const int end_resource_id = 171;
const int change_avi = 1;

int current_resource_id = begin_resource_id;


void play_avi(HINSTANCE hinst, HWND avi_wnd, UINT resource_id)
{
	// if we have hit the end reset to the beginning!
	current_resource_id = (current_resource_id == end_resource_id) ? begin_resource_id : current_resource_id;
	if(SendMessage(avi_wnd, ACM_OPEN,(WPARAM)hinst,(LPARAM)resource_id) == NULL)
		MessageBox(gDlg,"Cannot Load the avi resource","ANI",0);
	else {
		char buff[128];
		sprintf_s(buff, "Playing clip for resource ID == %d", resource_id);
		SendMessage(avi_wnd, ACM_PLAY,(WPARAM)-1,MAKELONG(0,-1));
		if (HWND status_wnd = GetDlgItem(gDlg, IDC_CUSTOM_MESSAGE))
			SetWindowText(status_wnd, buff);
	}
}


VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	if (hwnd == gDlg && idEvent == change_avi)
		play_avi(avi, AnimationCtrl, current_resource_id++);
}
</code>

... and adding this to the window proc to get it to change the animation every 2.5 seconds ...
<code>
//Main Dialog procedure
BOOL CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	gDlg = hDlg;
...
			play_avi(avi, AnimationCtrl, current_resource_id++);
			SetTimer(gDlg, change_avi, 2500, TimerProc);
</code>


Oh and I changed the resource file and resource.h so that I could update the text for the static control above the progress bar.

Experimenting with values for begin_resource_id and end_resource_id suggests that valid ids go from 160 - 170 inclusive.
There are a lot of other animations in Windows that would be good to use. I wonder where I find them? I particularly like the one Visual Studio uses after it has crashed and is submitting the error report.

Does anyone know off hand if reusing these animations is within the terms of the Windows EULA?
AnswerRe: How do you figure out the resource ID for the animation? Pin
ryltsov5-Apr-07 8:32
ryltsov5-Apr-07 8:32 
Questionhow can i use it in c#? Pin
jabulino9-Jan-06 5:44
jabulino9-Jan-06 5:44 
AnswerRe: how can i use it in c#? Pin
Yogesh M Joshi22-Jan-06 21:36
Yogesh M Joshi22-Jan-06 21:36 
GeneralRe: how can i use it in c#? Pin
jabulino22-Jan-06 21:42
jabulino22-Jan-06 21:42 
GeneralToo much code Pin
WebFritzi26-Jan-04 13:16
WebFritzi26-Jan-04 13:16 
GeneralReformat... Pin
Kant22-Mar-03 4:32
Kant22-Mar-03 4:32 
GeneralRe: Reformat... Pin
Yogesh M Joshi23-Mar-03 1:13
Yogesh M Joshi23-Mar-03 1:13 

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.