[ Pobierz całość w formacie PDF ] .NET will take off immediatelyand that everyone will instantly move their applications to it.The reality is that mostcompanies will begin experimenting with.NET in the near future and won t beginmoving applications to it for several years.As a developer, you need to prepare forfuture application programming needs as well as keeping abreast of today s technology.Managed components present one view of programming in the future.MFC ActiveX Control ExampleI can t think of a single application on my machine that doesn t rely on a pushbutton or two.In fact, the pushbutton is one of the very few Windows controls that you could say everyapplication has.Even an application that displays information in a simple dialog usuallyrelies on an OK button to close the dialog.Suffice it to say then that the pushbutton is theone control on your machine that has to work well.The control has to provide all of thefeatures you need, and it s the one that programmers change the most.With this much emphasis on the utility of one control by programmers, it didn t take me toolong to figure out which control to show you how to modify in this section of the chapter.Ialso wanted to add a unique feature something that everyone will need eventually.That swhy I chose an on/off button as the basis for the control in this chapter.NoteThe example on the source code CD has modified forms of the About Box,control icon, version information, string table, and control bitmap.Oneespecially important change is to modify the IDS_PBUTTON1 string to read On/Off Pushbutton Control (MFC). We ve already discussed these issuesas part of the Working with Resources section of Chapter 2.See theresource file in the \Chapter 06\PButton1 folder of the source code CD forideas on how you can change the resources for your own controls.Writing the CodeIt s time to look at a simple coding example.Let s begin with a new C++ project.However,unlike other projects you may have created, you ll want to start with the MFC ActiveX Controlproject to create your workspace.The MFC ActiveX Control Wizard provides you with aframework that you can build on to create the final version of this example.This exampleuses PButton1 for a project name.You ll see the MFC ActiveX Control Wizard dialog afteryou create the application.The Application Settings tab enables you to add a runtime licenseand automatically generate help files.The Control Names tab contains a complete list of thefilenames and registry name entries for the control.Generally, you can leave these tabsalone for a simple control.However, you ll want to select the Control Settings tab shownnext.Select the BUTTON class on the Control Settings tab to create the example in this chapter.Otherwise, look through the list of available classes to determine what you want to use as abasis for your control.Notice that Visual C++ allows you to create your own basic class.Click on Finish to create the project.Some of the options on the Control Settings tab can have unforeseen consequences whenused in the wrong environment.For example, Visual Basic requires controls that create awindow; otherwise you can t interact with them.The Windowless Activation option doesprovide a performance boost for your control, but at the cost of compatibility.The Optimizeddrawing code option also enhances performance, but can cause flicker in some situations.The Unclipped device context option not only enables you to create irregularly shapedcontrols, but also allows your control to draw outside its window, making it possible to trashthe screen.The Flicker-free activation option does eliminate most causes of flicker, a plus forgraphics controls, but your control will take a performance hit when using this option.Theother Control Settings tab options enable your control to perform special tasks, such asappearing within a compound document.Adding Properties and EventsLet s get down to the business of creating an ActiveX control.The first thing you ll want to dois make some of the button control properties and events visible to someone using theActiveX control.For example, it might be nice to be able to detect when the user clicked thebutton.You ll definitely want to be able to change default properties, such as the captiondisplayed on the button front.There aren t very many properties visible when you first createa button.To make these various elements visible, you ll need to use the Add PropertyWizard.You can access the Add Property Wizard by right-clicking _DPButton1 (found in thePButton1Lib folder in Class View) and choosing Add Property from the context menu.We ll use two different kinds of properties in this example Microsoft provides access to a lotmore.The first type is a stock property.You ll find that things like the Caption property thatwe all take for granted aren t visible when you first create an ActiveX control.A stockproperty is one that the parent class supports by default.Visual C++ enables you to selectstock properties using the Property Name field in the Add Property Wizard dialog, as shownhere.The second type is a custom property.A custom property is one that you ve added to aparticular class when you subclass it.One of them is the OnOff property that we ll use tocreate an OnOff control.We ll look at the process for doing this later in this chapter.Thefollowing table shows all the properties that we ll create in this example and tells you ifthey re custom or stock implementations.Property TypeCaption StockEnabled StockFront StockModalResult CustomOnOff CustomStdButtonType CustomTo add a stock property, select its name from the Property Name field of the Add PropertyWizard, verify that you have the Stock implementation type selected, then click Finish.Create all of the stock properties for this example program now.We ll also need three custom properties: ModalResult, OnOff, and StdButtonType.To createthese properties, type the names I ve just mentioned into the Property Name field.You llneed to select a data type in the Property Type field as well
[ Pobierz całość w formacie PDF ] zanotowane.pldoc.pisz.plpdf.pisz.plmikr.xlx.pl
|