65.9K
CodeProject is changing. Read more.
Home

Loading AVI Resources from Shell32.dll file

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.95/5 (19 votes)

Mar 22, 2003

1 min read

viewsIcon

100192

downloadIcon

2602

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...