Win32 Animation Control Help

Pages: 12
So I was reading this: http://msdn.microsoft.com/en-us/library/bb761881(v=VS.85).aspx

I'm pretty sure I wrote all the code correctly, and yet my avi file does not play. I have the correct file name and it is in the correct location for my executable file to read it, but it doesn't play. If anyone can take a look at my code and help me that would be great, thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <windows.h>
#include <CommCtrl.h>
HINSTANCE hInstance = GetModuleHandle (NULL);
HWND CreateAnimationControl (HWND hParent)
{
    HWND hAnimation = Animate_Create (hParent, ACS_AUTOPLAY, WS_BORDER | WS_CHILD, hInstance);
    Animate_Open (hAnimation, "Test.avi");
    ShowWindow (hAnimation, SW_SHOWNORMAL);
    return hAnimation;
}
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    static HWND hAnimation = NULL;
    switch (uiMsg)
    {
        case WM_DESTROY:
        PostQuitMessage (0);
        break;
        case WM_CREATE:
        hAnimation = CreateAnimationControl (hWnd);
        break;
        case WM_SHOWWINDOW:
        if (wParam)
        {
            MoveWindow (hAnimation, 0, 0, 300, 300, false);
            Animate_Play (hAnimation, 0, -1, -1);
        }
        break;
    }
    return DefWindowProc (hWnd, uiMsg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpsCmdLine, int iCmdShow)
{
    WNDCLASSEX WindowClass;
    WindowClass.cbClsExtra = 0;
    WindowClass.cbSize = sizeof (WNDCLASSEX);
    WindowClass.cbWndExtra = 0;
    WindowClass.hbrBackground = CreateSolidBrush (RGB (0, 0, 0));
    WindowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    WindowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    WindowClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    WindowClass.hInstance = hInstance;
    WindowClass.lpfnWndProc = WindowProcedure;
    WindowClass.lpszClassName = "1";
    WindowClass.lpszMenuName = NULL;
    WindowClass.style = 0;
    if (!RegisterClassEx (&WindowClass))
    {
        MessageBox (NULL, "Window class registration has failed!", "Error:", MB_OK | MB_ICONERROR);
        return 0;
    }
    HWND hWnd = CreateWindow ("1", "Win32 Animation Testing", WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
                              hInstance, NULL);
    if (!hWnd)
    {
        MessageBox (NULL, "Window creation has failed!", "Error:", MB_OK | MB_ICONERROR);
        return 0;
    }
    ShowWindow (hWnd, SW_SHOWMAXIMIZED);
    UpdateWindow (hWnd);
    MSG uMsg;
    while (GetMessage (&uMsg, NULL, 0, 0) > 0)
    {
        TranslateMessage (&uMsg);
        DispatchMessage (&uMsg);
    }
    return (int) uMsg.wParam;
}
The first thing I notice is that you aren't checking the returns from any of the Win32 functions. These often return values that can help you narrow down your point of failure, for example you should rewrite your CreateAnimationControl() function to something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*NOT TESTED*/
HWND CreateAnimationControl (HWND hParent)
{
    HWND hAnimation = Animate_Create (hParent, ACS_AUTOPLAY, WS_BORDER | WS_CHILD, hInstance);
    
   if(!Animate_Open (hAnimation, "Test.avi"))
     {
            std::string err = "Failed To Open AVI File" + GetLastError();
            MessageBox(hParent, &err[0], "Failure", MB_OK);
            return NULL;
      }
    

   ShowWindow (hAnimation, SW_SHOWNORMAL);
    return hAnimation;
}


I know that you were copying right from MSDN and that they have a habit of not teaching you how to evaluate their functions but you should make an effort if you know how.

EDIT: "MessageBox()" should work now.
Last edited on
Alright, I added in a few error checks, one being similar to what you posted, and another for CreateAnimationControl()'s return value.

1
2
3
4
5
6
7
8
9
10
11
12
HWND CreateAnimationControl (HWND hParent)
{
    HWND hAnimation = Animate_Create (hParent, ACS_AUTOPLAY, WS_BORDER | WS_CHILD, hInstance);
    if (!Animate_Open (hAnimation, "Test.avi"))
    {
        MessageBox (hParent, "Failed to open \"Test.avi\"!", "Error:", MB_OK | MB_ICONERROR);
        PostQuitMessage (0);
        return NULL;
    }
    ShowWindow (hAnimation, SW_SHOWNORMAL);
    return hAnimation;
}


Every time the program is ran the MessageBox() is called. I've read over the information on the Animate_Open() Macro and my AVI file seems to be fine, it doesn't have any audio to it.

Still confused and wondering why this isn't working.
This sounds like you don't have "Test.avi" in the correct path. Can you try putting in the fully qualified UNC path for that file and see if it makes a difference?

Also I edited this so that you would get an error code from the "GetLastError()" function, please do this and tell us what it returns.
Where is the link to the actual code you are copying?
The problem coul be this lne here -
Animate_Open (hAnimation, "Test.avi");
This macro simply takes the second parameter and convert it to a WPARAM.

If your program is running as unicode build then this will fail.

To prove this quickly one way or another is to write:
Animate_Open (hAnimation, L"Test.avi"); //use wide char



**make sure that your avi is in the correct directory and does not have sound**
Computergeek01 wrote:
This sounds like you don't have "Test.avi" in the correct path.
I'm 100% sure I have it in the correct path. I've been using Code::Blocks for the last year, and I've made multiple applications with file I/O, putting the file in the same place I always do.

Computergeek01 wrote:
Can you try putting in the fully qualified UNC path for that file and see if it makes a difference?
Tried it, same thing happened.

Computergeek01 wrote:
Also I edited this so that you would get an error code from the "GetLastError()" function, please do this and tell us what it returns.
When I run the code that you posted I only get a "Failed To Open AVI File" message, with no extra text of any kind.

Lamblion wrote:
Where is the link to the actual code you are copying?
http://msdn.microsoft.com/en-us/library/bb761889(v=VS.85).aspx

guestgulkan wrote:
The problem coul be this lne here -
Animate_Open (hAnimation, "Test.avi");
This macro simply takes the second parameter and convert it to a WPARAM.

If your program is running as unicode build then this will fail.

To prove this quickly one way or another is to write:
Animate_Open (hAnimation, L"Test.avi"); //use wide char



**make sure that your avi is in the correct directory and does not have sound**


I tried:

Animate_Open (hAnimation, L"Test.avi");
and:
Animate_Open (hAnimation, (WPARAM) "Test.avi");

and it still didn't work.

And I am 100% sure my AVI file is in the correct path. I used camstudio to record it, I set the "Record sound" option off, when I play it there is no sound, so I'm assuming that the sound isn't the problem.








Thanks for all the replies, but still not working =/
Last edited on
Are you using MSVC ??.

Could be your avi file.


EDITED
Last edited on
Oh right because the termination character is automatically appended. Try returning the "GetLastError()" the shell that Code::Blocks uses should tell you "Application ran for... and exited with error code X".
guestgualkan wrote:
Are you using MSVC ??
Does that stand for MS Visual C++? If so no, I'm using the Win32 API

Computergeek01 wrote:
Oh right because the termination character is automatically appended. Try returning the "GetLastError()" the shell that Code::Blocks uses should tell you "Application ran for... and exited with error code X".


If you mean the "Logs & Others" shell then the only thing it says is:

Process terminated with status 0 (0 minutes, 8 seconds)


If not, then I don't know where that shell would be.
I've never used this function before, but looking at the description of it in MSDN it seems that your second parameter in Animate_Create() should be a UINT identifier and the ACS_AUTOPLAY is defined instead as a window style.

You haven't copied the MSDN code exactly. I usually find that if I don't do it EXACTLY as it is written that it doesn't work. Therefore, I copy the code EXACTLY as it is written, and if it works, then I start changing things to see if those will work as well. It's much better to start off with whole enchilade then modify stuff rather than the other way around.
Last edited on
Lamblion wrote:
I've never used this function before, but looking at the description of it in MSDN it seems that your second parameter in Animate_Create() should be a UINT identifier and the ACS_AUTOPLAY is defined instead as a window style.

You haven't copied the MSDN code exactly. I usually find that if I don't do it EXACTLY as it is written that it doesn't work. Therefore, I copy the code EXACTLY as it is written, and if it works, then I start changing things to see if those will work as well. It's much better to start off with whole enchilade then modify stuff rather than the other way around.


I just tried copying the exact code and I get three errors. The following three things:

IDC_ANIMATE
CX_FRAME
CY_FRAME

are not defined in my library, can you guys please tell me what values these are defined as in your libraries?
Just a minute - In your original code - did the animation show a picture but just did not actually play??
Last edited on
guestgulkan wrote:
Just a munite - does the animation show a picture but just does not actually play??
There's only a white rectangle in the window, not the size of the window either. MSDN says that the first frame of the AVI should be in the control, but that isn't happening.




Would you guys like to see my code and my AVI file?
personally, I'm more interested in your avi file - because I can get the your original code you posted to work (with one minor line change) using an avi files on my pc (one of those little avi files that come with windows)
I just tried copying the exact code and I get three errors. The following three things:

IDC_ANIMATE
CX_FRAME
CY_FRAME

are not defined in my library, can you guys please tell me what values these are defined as in your libraries?


You have to #define those controlds yourself, and you have to associate the IDC_ANIMATE to your control.

I would to this --

1
2
#define IDC_ANIMATE 301
int CX_FRAME, CY_FRAME;
Last edited on
Here's my AVI file: http://www.sendspace.com/file/84o3d0

Lamblion, I used those two lines and the window shows up, but there's nothing in the window. No animation control, no frames, nothing.
Did you add those declarations to your own code, or did you add it to the EXACT code in MSDN?

If you didn't do the latter, it probably won't work, whereas if you added it the EXACT code in the example and associated the IDC_ANIMATE with the control, it will probably work.
I tried both, and it still didn't work. So now I believe it is my AVI file, if you guys can try the AVI file with your own code to see if it works for you that would be cool.
How, EXACTLY, did you associate IDC_ANIMATE with your control?
Pages: 12