The use problem of Canimatectrl::open

Source: Internet
Author: User

Ask the question: When using Canimatectrl::open (LPCTSTR lpszfilename), the parameter lpszfilename is a string representing the AVI file name. Therefore, in addition to distributing executables, you must distribute AVI files separately when distributing applications. Is there a way to get AVI files from the resources?

In this program, if you want to get the file from the outside is quite inconvenient, in case who accidentally deleted or renamed the file .... So the best way to do this is to store the file as a resource in the executable file. Luckily the CAnimateCtrl class has a member function canimatectrl::open uint as the argument, which means that it uint can be the ID number of the resource.

But how to put AVI file into exe file? This is a skill to use. The animation control looks for AVI-type resources, so what you need to do is add code to the resource file (. rc):

Idr_myanimation AVI discardable "Res\\myanim.avi"

Idr_myanimation must be defined beforehand as an integer number (note that you cannot use a string name as a resource) and AVI files should be placed in the RES directory under the engineering directory. The resource compiler copies the Myanim.avi to the executable file one byte at a time so that the animation control can find it.

In addition, you can use the same method to put any file as a resource into an EXE file. The method is:

Idr_myfoofile FOO discardable "Res\\myanim.foo"

Once you have included the Foo type file in the exe file, how do you access it? Then you need to write some code yourself. First, you must call the FindResource function to get the resource handle.

HINSTANCE hinst = AfxGetResourceHandle ();

Hrsrc hrsrc =:: FindResource (Hinst,

Makeintresource (Idr_myfoofile),//ID

"FOO"); Type

ASSERT (HRSRC);

Suppose Hrsrc is not empty, and then call two functions to get the size of the resource (foo file) and the data itself.

DWORD len = Sizeofresource (hinst, HRSRC);

byte* lprsrc = (byte*) loadresource (hinst, HRSRC);

ASSERT (LPRSRC);

Now, in memory lprsrc to the Foo file, if you want to access this memory like a normal disk file, you can use the CMemFile of the class library to treat a storage area as a cfile.

CMemFile file (lprsrc, Len);

File. Read (...); etc.

You can even open a resource in cdocument like an overloaded onopendocument open a disk file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.