Wątki

[ Pobierz całość w formacie PDF ]
.What is the difference between an OnIdle task and a thread?4.What are the four thread synchronization objects?5.Why shouldn t you specify a higher than normal priority for the threads in yourapplication?Exercises1.If you open a performance monitor on your system while the application that youbuilt today is running, you ll find that even without any of the threads running, theprocessor usage remains 100 percent, as shown in Figure 18.11.The OnIdle func-tion is continuously being called even when there is nothing to be done.Modify the OnIdle function so that if there s nothing to be done, neither of theOnIdle tasks are active.Then, the OnIdle function will not continue to be calleduntil one of these threads is active, at which time it should be continuously calleduntil both threads are once again turned off.This will allow the processor to dropto a minimal utilization, as shown in Figure 18.12. 024 31240-9 CH18 4/27/00 12:59 PM Page 472472 Day 18FIGURE 18.11.Processor utilization at100 percent.FIGURE 18.12.Processor utilization atnormal levels.2.When starting the independent threads, give one of the threads a priority ofTHREAD_PRIORITY_NORMAL and the other a priority of THREAD_PRIORITY_LOWEST. 025 31240-9 CH19 4/27/00 1:00 PM Page 473WEEK 3DAY 19Building Your OwnWidgets CreatingActiveX ControlsThe software industry has seen a revolution over the past couple years.Howsoftware is built and packaged has moved from a model where all applicationsare large, monolithic pieces of executable code to a model where most applica-tions consist of small building blocks.These small building blocks, often calledcomponents, can be created using any of several different languages and cantake many different forms.One of the most popular components is the ActiveXcontrol.If you know how to create your own ActiveX controls, you can buildyour own components and provide them to other programmers.Today, you willlearnHow to use the Visual C++ wizards to build ActiveX controls.How to add properties and methods to your controls using the ClassWizard.How to test your control using the tools provided with Visual C++. 025 31240-9 CH19 4/27/00 1:00 PM Page 474474 Day 19What Is an ActiveX Control?An ActiveX control is a set of functionality packaged in a COM (Component ObjectModel) object.This COM object is self-contained, although it does not have the abilityto run by itself.An ActiveX control can only run within a ActiveX container, such as aVisual C++ or Visual Basic application.As you learned on Day 9,  Adding ActiveX Controls to Your Application, ActiveX con-trols provide a series of interfaces used by the container application to trigger the varioussets of functionality contained in the control.Many of these interfaces are used for trig-gering events in the control or in the containing application.Others are for specifyingthe property page of the control or for communicating whether the control has beenactivated.All in all, so many interfaces are built into most ActiveX controls that codingthe functionality for each of these interfaces yourself would take quite some time.Luckily, the Visual C++ App and Class Wizards add much of this functionality for you,allowing you to focus on the specific functionality that the control is supposed to have.Among the aspects of the control you create that you still must plan yourself are whatproperties, methods, and events you will expose for your control.You can add these ele-ments to your control through the Class Wizard, but if any of the properties or eventsrequire special code on your part, then you must add it yourself.As should be expectedwith any methods that you add to your controls, you have to supply all of the code.TheClass Wizard will add the surrounding structure and code to allow the containing appli-cation to see and call the method, just as it will add all the code necessary to call anyevent handlers for your applications.PropertiesProperties are attributes of controls that are visible to, and often modifiable by, the con-tainer application.The four basic types of properties are ambient, extended, stock, andcustom.Ambient properties are provided by the container application to the controlsuch things as background color or the default font to be used so that the control lookslike part of the container application.Extended properties are not actually properties ofthe control but instead are provided and implemented by the container application, suchas tab order.The control may extend these properties somewhat; for example, if thecontrol contains two or more standard controls, it may control the tab order within theoverall control, returning the tab order control to the application once the control hascompleted its internal tab order.Stock properties are implemented by the ActiveX controldevelopment kit, such as control font or control background color.The final type ofproperties, custom properties, are what you are most concerned with because these 025 31240-9 CH19 4/27/00 1:00 PM Page 475Building Your Own Widgets Creating ActiveX Controls 475properties are specific to your control and are directly related to the functionality of yourcontrol.You can specify any properties you need in your control using the Automation tab on theClass Wizard.When you add a new property to your control through the Class Wizard,you ll specify several aspects of the property.The first aspect is the external property name, which is the name shown to the containingapplication for the property.Another aspect that you can specify is the internal variablename, which is used in your code, but only if the property is implemented as a membervariable.You also specify the variable type for the property [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • mikr.xlx.pl
  • Powered by MyScript