[ Pobierz całość w formacie PDF ]
.The newinterface makes this feature unnecessary because you can see the entireproject at a glance.However, as we progress through the chapter, you ll seethat the summary dialog would still be a welcome feature.You need to perform one more step before this project will be ready to go.It needs to useMFC classes.While you could have added this support as part of the wizard setup,converting DOS applications to Windows use requires less code rewriting if you go thisroute.Highlight Console in Solution Explorer.The object you select in this windowdetermines the results you obtain when using certain commands.Use the View | PropertyPages command to display the Console Property Pages dialog shown here:Notice that Visual C++.NET centralizes the settings for your application into a series ofhierarchical folders in the same dialog box.Choose the General folder of the dialog.Choosethe Use MFC in a Shared DLL option in the Use of MFC field.Click OK to complete theaction. Now it s time to add some code to our example.The first thing you ll need to do is add a fileto the project.Let s look at the process for doing that.1.Use the File | New | File command to open the New File dialog.Choose the Visual C++folder.You ll see a whole list of file types, including Resource Template File andvarious graphics files like Icon File.2.Highlight the C++ File option, and then click Open.You ll see a blank C++ source file.We need a C++ source file because we ll be adding classes to the sample code.3.Click Save.Select the correct directory for your source code files.Type Console in theFile Name field.(Visual C++ will automatically add the correct extension for you.)4.Click Save.This will add the file to our project directory.If you were using Visual C++6, this is where you d stop.However, when working with Visual C++.NET, you needto go one step further.5.Right-click Source Files in Solution Explorer and choose Add | Existing Item from thecontext menu.You ll see an Add Existing Item dialog box.6.Highlight Console.CPP, and then click Open.The file is now part of your project.Now that you have an empty file to use, it s time to add the code.Listing 2-1 contains theC++ source for our example.Notice that it includes straight C code mixed with the C++ code.I did that on purpose so that you could better see how things work in this environment.Listing 2-1#include // Provides access to MFC functions.class CDrawBox : public CObject{public:// Draws the box.void DoDraw(char* string);};void CDrawBox::DoDraw(char* cValue){size_t iCount; // Loop counter.size_t iSpaces; // Amount of spaces to add forstring.// Draw the top of the box.fprintf(stdout, "\311");for (iCount = 1; iCount GetMenuState(ID_VIEW_FORMATTOOLBAR, MF_CHECKED)){ShowControlBar(&m_wndToolBar2, FALSE, FALSE);poMenu->CheckMenuItem(ID_VIEW_FORMATTOOLBAR, MF_UNCHECKED);}else{ShowControlBar(&m_wndToolBar2, TRUE, FALSE);poMenu->CheckMenuItem(ID_VIEW_FORMATTOOLBAR, MF_CHECKED);}} As you can see, we begin by getting a copy of the CWnd class menu object.Once we havethe menu object, it s easy to figure out if the Format Toolbar option is currently checked.Ifthe option is checked, the toolbar is visible.You ll use the ShowControlBar() function withthe second and third parameters set to false to make the toolbar invisible.TheCheckMenuItem() function allows you to remove the check mark from the View | FormatToolbar menu option.Conversely, you use the opposite procedure to make the toolbarvisible and check the menu option again.Go ahead and compile the application one more time so you can check out the variousfeatures we ve just added.Make sure you try out all of the formatting options and the abilityto dock and hide toolbars.Obviously, this application isn t as complex as some of theprograms you ll see out there right now, but it does make good use of resources. Chapter 3: Working with ThreadsOverviewDevelopers are constantly looking for ways of using machine resources more efficientlywithout spending more time developing applications.One way to do this is to write anapplication to perform more than one task as a time.Windows provides this ability usingthreads.A thread is essentially a single subject of execution within an application (alsoknown as a single path of execution).In other words, a single application can do more thanone task at a time.For example, it could print and spell check a document in the backgroundwhile the user is typing in the foreground.NoteYou actually need to be aware of two entities when talking about threads.The term thread describes one set of contiguous instructions for performinga single task.A process, on the other hand, describes the application as awhole.Every executing application has at least one thread and one process.There s never more than one process for an application, but Win32applications can always produce more than one thread.The distinctionbetween processes and threads will become more clear as the chapterprogresses.Threads don t perform any kind of magic.They won t make the user s machine any faster,and the processor still can t perform more than one task at a time.In other words, threadsdon t allow a machine to perform more than one task simultaneously unless that machinehas the resources (that is, multiple processors) to perform multiple tasks simultaneously.What threads do allow is an application to use machine resources more efficiently.They alsoprovide better response times for the user by performing some application housekeepingtasks in the background.For example, a document can print in the background while theuser works in the foreground because the user isn t likely to require full use of the processorall of the time.Making use of idle time while the user thinks allows the machine to work moreefficiently.Since the processor only services a particular task during idle time, the userregains use of the machine immediately after requesting that the application perform thetask [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • agnieszka90.opx.pl