Pokrewne
- Strona Główna
- Stalo sie jutro Zbior 24
- 24 K W Jeter Mandaloriańska Zbroja
- [eBook] DirectX 3D Graphics Programming Bible
- Advanced 3D Game Programming with DirectX 9
- (ebook pdf) Teach Yourself SQL in 21 Days
- Teach Yourself Database Programming with Visual C in 21 Da
- Melissa Marr przybysze
- Wstęp do filozofii A B Stępień
- Pieklo Gabriela (2)
- Forsyth Frederick Negocjator (2)
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- psmlw.htw.pl
[ Pobierz całość w formacie PDF ]
.We will be taking two departures from previous examples.First, we will be using the#import mechanism to simplify our COM interface handling with DirectAnimation.Second, we will use an MFC AppWizard generated application as our starting point forthe code.You don t really need to know or care about MFC to understand this example,33 1634xCH24 11/13/99 11:14 AM Page 495Integrating Media Into Web Pages and Applications with DirectAnimation 495but by going that route, we can use the DirectAnimation control easily and not have tocode a bunch of Windows and DirectDraw initialization code.To get started, you will need to run Visual C++ and select New from the File menu.Select the Projects tab, and select MFC AppWizard (exe) from the program options.Enter a location for the project, and enter a project name of DASample, and click OK asshown in Figure 24.2.FIGURE 24.2Creating theDASample project.24In the dialog that follows, select Single Document and press the Finish button.Thisaccepts the rest of the defaults for an MFC SDI application.We will only be making ourmodifications to the CDASampleView class generated by the AppWizard to avoid gettinginto much MFC.Some other code will be generated by the wizard for print preview, helpsupport, and other things, but we will just ignore that code.The reason for going this route is that the MFC CWnd class supports hosting of ActiveXcontrols with very little code.By using an MFC AppWizard project, everything isalready in place to allow us to use this class.We will be embedding a DAViewerControlin the CDASampleView class using this capability.That will allow us to focus just on theDirectAnimation code.Initializing DirectAnimationThere are basically two ways to get DirectAnimation initialized.Which way you choosedepends on whether you are going to let the DirectAnimation control do all the drawingon its own using the GDI, or whether you want to pass it a DirectDraw surface and con-trol updating the screen yourself.The first route is by far the easiest, and it is the one we will use in our sample applica-tion.The main drawback to this approach again is performance because the control is33 1634xCH24 11/13/99 11:14 AM Page 496496 Hour 24using the GDI for drawing the scene, you miss out on all the performance benefitsDirectDraw provides you.We will describe the process required to use DirectDraw at theend so that you know how to go further on your own, and a separate example project isincluded that uses raw COM interfaces and the DirectDraw/DAView approach to showyou how.We must add a couple of other things before we get down to the DirectAnimation codeso that we have somewhere to put that code.We will add a handler to the CDASampleViewclass for the Windows WM_CREATE message and will put all our DirectAnimation initial-ization code there to insulate you from the MFC architecture as much as possible in thisexample.To add this handler from Visual Studio, you can simply right-click theCDASampleView class in the ClassView pane, and select Add Windows Message Handleras shown in Figure 24.3.Select the WM_CREATE message from the list in the resulting dia-log box, and press the Add and Edit button.This plops you into the handler function withthe focus on the line where you should start adding your code.FIGURE 24.3Adding the Windowsmessage handler.We ll come back to this handler in a moment, but there are a few other initializationsteps to take first.We are going to want a child window to host the DirectAnimation con-trol that won t go out of scope when the WM_CREATE handler finishes.To do this, just adda CWnd member to the CDASampleView class with the code in Listing 24.1 as a publicmember of the class.33 1634xCH24 11/13/99 11:14 AM Page 497Integrating Media Into Web Pages and Applications with DirectAnimation 497LISTING 24.1 CWnd Member Variable in DASampleView.h1: public:2: CWnd m_ctl;We also need to add the DirectAnimation library to our application.If we were going tocode straight C++ COM code, we would #include the danim.h file and add thedaguid.lib static link libraries to the project link settings.But because we are going touse the #import directive, all we do is add Listing 24.2 to the top of ourDASampleView.h file.LISTING 24.2 #import Declaration in DASampleView.h1: #pragma warning(disable: 4192)242: #import rename_namespace( DAnim )3: using namespace DAnim;The #pragma just avoids a bunch of warnings about redefinition exclusions that you don tneed to worry about.The #import statement allows the compiler to pull in the typelibrary information out of the danim.dll file and automatically generates smart pointerwrapper classes for the DirectAnimation interfaces for you.The namespace parts just letyou use the generated classes and definitions without having to qualify each one with anamespace.After you have added this, you basically have full access to theDirectAnimation interfaces through smart pointer wrapper classes.When you haveadded this and compile your project, the compiler will generate two files in your outputdirectory: danim.tlh and danim.tli.These files contain the header and implementationcode for the classes the compiler finds in the danim.dll type library.You can browsethrough these files to see the classes generated if desired.Sometimes the Visual C++ compiler gets ahead of itself while generating the.tlh and.tli files and starts trying to compile using those files before it hasfully closed them.This results in a compile error saying fatal error C1083:Cannot open include file.All you have to do is try to compile again, andit usually succeeds the second time.The CWnd::CreateControl() FunctionTo initialize the DAViewerControl, we will let MFC do a lot of work for us by using theCWnd::CreateControl() function.This function creates an ActiveX control from aCLSID or a ProgID string, and automatically makes the numerous connections requiredbetween an ActiveX control and its host container.SYNTAX,33 1634xCH24 11/13/99 11:14 AM Page 498498 Hour 24BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName,DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,UINT nID, CFile* pPersist = NULL,BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );This function returns TRUE on success.Parameters:clsid A reference to a CLSID constant for the con-trol you are creating.An overloaded form ofthis function takes a ProgID string to identifythe desired class.lpszWindowName A string indicating the desired name for thenew window that will be created for the con-trol.This value can be NULL if the controlwill not be referenced elsewhere by name [ Pobierz całość w formacie PDF ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl agnieszka90.opx.pl
.We will be taking two departures from previous examples.First, we will be using the#import mechanism to simplify our COM interface handling with DirectAnimation.Second, we will use an MFC AppWizard generated application as our starting point forthe code.You don t really need to know or care about MFC to understand this example,33 1634xCH24 11/13/99 11:14 AM Page 495Integrating Media Into Web Pages and Applications with DirectAnimation 495but by going that route, we can use the DirectAnimation control easily and not have tocode a bunch of Windows and DirectDraw initialization code.To get started, you will need to run Visual C++ and select New from the File menu.Select the Projects tab, and select MFC AppWizard (exe) from the program options.Enter a location for the project, and enter a project name of DASample, and click OK asshown in Figure 24.2.FIGURE 24.2Creating theDASample project.24In the dialog that follows, select Single Document and press the Finish button.Thisaccepts the rest of the defaults for an MFC SDI application.We will only be making ourmodifications to the CDASampleView class generated by the AppWizard to avoid gettinginto much MFC.Some other code will be generated by the wizard for print preview, helpsupport, and other things, but we will just ignore that code.The reason for going this route is that the MFC CWnd class supports hosting of ActiveXcontrols with very little code.By using an MFC AppWizard project, everything isalready in place to allow us to use this class.We will be embedding a DAViewerControlin the CDASampleView class using this capability.That will allow us to focus just on theDirectAnimation code.Initializing DirectAnimationThere are basically two ways to get DirectAnimation initialized.Which way you choosedepends on whether you are going to let the DirectAnimation control do all the drawingon its own using the GDI, or whether you want to pass it a DirectDraw surface and con-trol updating the screen yourself.The first route is by far the easiest, and it is the one we will use in our sample applica-tion.The main drawback to this approach again is performance because the control is33 1634xCH24 11/13/99 11:14 AM Page 496496 Hour 24using the GDI for drawing the scene, you miss out on all the performance benefitsDirectDraw provides you.We will describe the process required to use DirectDraw at theend so that you know how to go further on your own, and a separate example project isincluded that uses raw COM interfaces and the DirectDraw/DAView approach to showyou how.We must add a couple of other things before we get down to the DirectAnimation codeso that we have somewhere to put that code.We will add a handler to the CDASampleViewclass for the Windows WM_CREATE message and will put all our DirectAnimation initial-ization code there to insulate you from the MFC architecture as much as possible in thisexample.To add this handler from Visual Studio, you can simply right-click theCDASampleView class in the ClassView pane, and select Add Windows Message Handleras shown in Figure 24.3.Select the WM_CREATE message from the list in the resulting dia-log box, and press the Add and Edit button.This plops you into the handler function withthe focus on the line where you should start adding your code.FIGURE 24.3Adding the Windowsmessage handler.We ll come back to this handler in a moment, but there are a few other initializationsteps to take first.We are going to want a child window to host the DirectAnimation con-trol that won t go out of scope when the WM_CREATE handler finishes.To do this, just adda CWnd member to the CDASampleView class with the code in Listing 24.1 as a publicmember of the class.33 1634xCH24 11/13/99 11:14 AM Page 497Integrating Media Into Web Pages and Applications with DirectAnimation 497LISTING 24.1 CWnd Member Variable in DASampleView.h1: public:2: CWnd m_ctl;We also need to add the DirectAnimation library to our application.If we were going tocode straight C++ COM code, we would #include the danim.h file and add thedaguid.lib static link libraries to the project link settings.But because we are going touse the #import directive, all we do is add Listing 24.2 to the top of ourDASampleView.h file.LISTING 24.2 #import Declaration in DASampleView.h1: #pragma warning(disable: 4192)242: #import rename_namespace( DAnim )3: using namespace DAnim;The #pragma just avoids a bunch of warnings about redefinition exclusions that you don tneed to worry about.The #import statement allows the compiler to pull in the typelibrary information out of the danim.dll file and automatically generates smart pointerwrapper classes for the DirectAnimation interfaces for you.The namespace parts just letyou use the generated classes and definitions without having to qualify each one with anamespace.After you have added this, you basically have full access to theDirectAnimation interfaces through smart pointer wrapper classes.When you haveadded this and compile your project, the compiler will generate two files in your outputdirectory: danim.tlh and danim.tli.These files contain the header and implementationcode for the classes the compiler finds in the danim.dll type library.You can browsethrough these files to see the classes generated if desired.Sometimes the Visual C++ compiler gets ahead of itself while generating the.tlh and.tli files and starts trying to compile using those files before it hasfully closed them.This results in a compile error saying fatal error C1083:Cannot open include file.All you have to do is try to compile again, andit usually succeeds the second time.The CWnd::CreateControl() FunctionTo initialize the DAViewerControl, we will let MFC do a lot of work for us by using theCWnd::CreateControl() function.This function creates an ActiveX control from aCLSID or a ProgID string, and automatically makes the numerous connections requiredbetween an ActiveX control and its host container.SYNTAX,33 1634xCH24 11/13/99 11:14 AM Page 498498 Hour 24BOOL CWnd::CreateControl( REFCLSID clsid, LPCTSTR lpszWindowName,DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,UINT nID, CFile* pPersist = NULL,BOOL bStorage = FALSE, BSTR bstrLicKey = NULL );This function returns TRUE on success.Parameters:clsid A reference to a CLSID constant for the con-trol you are creating.An overloaded form ofthis function takes a ProgID string to identifythe desired class.lpszWindowName A string indicating the desired name for thenew window that will be created for the con-trol.This value can be NULL if the controlwill not be referenced elsewhere by name [ Pobierz całość w formacie PDF ]