⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第七课 库 和 microsoft foundation classes (mfc).htm

📁 ARM开发环境ADS1.2使用指南,网页格式
💻 HTM
📖 第 1 页 / 共 3 页
字号:
            <P>Using someone else's library changes things a bit. Libraries 
            provided by third-party vendors contain several files: the library 
            file itself (usually with a name ending in .lib), a header file 
            (.h), and (hopefully) some documentation (.doc). The header file is 
            required so that the compiler can match function calls in your 
            program to functions within the library. You include the header file 
            in your source file and then simply call the library functions as if 
            they were part of the operating system. In most cases, you place the 
            .h and .lib files in your source path, as defined by CodeWarrior. 
            This path is usually in the directory where your project file is 
            located, or inside a subdirectory of this directory. Note that 
            certain libraries CodeWarrior provides, such as its MSL, reside in a 
            different directory from the one your project lives in. In fact, 
            CodeWarrior has its own special access paths, called <B>system 
            paths,</B> which point to the directories of its own libraries and 
            header files.</P>
            <P><B><FONT size=+1>Using a Shared Library</FONT></B></P>
            <P>Third-party vendors ship library files with their products so 
            that they don't have to part with their source code. If you're the 
            vendor, it's much safer to include the library and a header file (as 
            opposed to a C or C++ source file and a header file), especially if 
            you want to protect your intellectual property. The problem with 
            this approach is that if there's a bug in the library you've gotten 
            from a third-party vendor, you'll be unable to fix it yourself. 
            You'll have to obtain a fix for the library from that vendor, and 
            who knows how easy that will be?</P>
            <P><B><FONT size=+1>Sharing DLLs</FONT></B></P>
            <P>A DLL is very similar to a library file. In fact, the only 
            difference is that a library file usually gets compiled and linked 
            <I>into</I> your application, while a DLL is a separate file that 
            either sits in your system directory or in the same directory as 
            your compiled application. When your application runs, it locates 
            the DLL and uses its services on the fly. DLLs are typically 
            identified by the .dll extension.</P>
            <P><B><FONT size=+1>Benefits of Sharing DLLs</FONT></B></P>
            <P>The benefit of a DLL is that it can be shared. OK, that was 
            pretty obvious. What is the benefit of sharing? First, more than one 
            application can make use of a DLL. This can be especially useful 
            when several programs use a large DLL that takes up lots of disk 
            space and/or memory. Also, if a DLL contains a bug and is updated, 
            all programs that share it will be automatically updated. This saves 
            you and your run-time processing large amounts of time. So what kind 
            of library would need to be shared by multiple applications? Oh, 
            stuff like the very windows you see in your operating system 
            environment.</P>
            <P><B><FONT size=+1>Note on Using Shared DLL files</FONT></B></P>
            <P>The CodeWarrior IDE CD-ROM contains dozens of libraries, and 
            hundreds more are available on the Internet. Always, always, always 
            run a virus check or disinfectant program before incorporating third 
            party code into your product. It's a good habit, like locking the 
            door every time you leave the house.</P>
            <P>The libraries included with CodeWarrior fall into two categories. 
            The first is the MSL, which provides ANSI C/C++ standard functions. 
            The MSL has been ported to many platforms, so its functions are 
            available in various flavors of Windows, the Mac OS, and Solaris. A 
            second set of libraries is intended for platform-specific uses. For 
            example, on the Windows CD, you'll find Windows 32 support libraries 
            that interface to the Windows APIs and the MFC libraries, which 
            provide an object-oriented application framework for writing Windows 
            applications. When you gain more programming experience, you will 
            find more uses for the specialized libraries.</FONT><BR></P>
            <P><FONT face="Arial, Helvetica, sans-serif" color=#000000 
            size=3><B><B>What is MFC?</B></B><BR></FONT><BR></P><FONT 
            face="Arial, Helvetica, sans-serif" size=2>
            <P>The Microsoft Foundation Classes (MFC) provides a set of 
            functions that let you quickly write Windows applications. While 
            you're free to call the Win32 APIs directly, it's easier to use the 
            MFC because the classes provide basic services such as creating a 
            window or writing a file along with intelligent default settings and 
            error-checking code. MFC is available on the Windows CodeWarrior CD 
            but may not be the very latest version of the classes. Check with 
            the Metrowerks help desk for that information, as Microsoft will 
            send update patches between CodeWarrior releases.</P>
            <P>For the sake of platform parity, Macintosh developers can use 
            Metrowerks' own PowerPlant class libraries. PowerPlant is an 
            object-oriented application framework designed for writing Mac 
            applications. Although we will not discuss PowerPlant here, it and 
            MFC are similar in many ways, and what you learn here will help you 
            to understand PowerPlant as well. When I discuss MFC, it is safe to 
            assume that the same concepts apply to PowerPlant.</P>
            <BLOCKQUOTE><B>
              <P>Note:</B> There is also a library version of MFC on the 
              CodeWarrior Macintosh CD, but unlike the Windows CD, the source 
              code is not included for the Macintosh. Using MFC, you can write 
              cross-platform code. Once you have written the code, you can 
              compile it for both the Macintosh (using PowerPlant) and the PC 
              (using MFC) at one time. Pretty cool, huh?</P></BLOCKQUOTE>
            <P><B><FONT size=+1>Application Framework</FONT></B></P>
            <P>As mentioned earlier, MFC is an application framework. This means 
            that MFC is a collection of C++ classes in source code or library 
            format. The framework can create a complete application that 
            supports advanced operating system features in a fraction of the 
            time it would take to do it all by hand. Note also that MFC contains 
            tools to facilitate building your user interface. These tools, 
            specifically the Image Editor, Dialog Editor, and Resource Compiler, 
            help you build the graphic elements of the user interface (the last 
            section of the lesson explains how to install these useful 
            components). An application framework concerns itself primarily with 
            the standard user interface of the application, as opposed to the 
            specific content of the application. Put another way, the framework 
            helps you build a robust application interface to interact with the 
            user, giving you more time to write the other functions that 
            implement the application's purpose. So you don't have to worry 
            about spending time and energy coding a scroll bar or close box from 
            scratch to appear like all other applications running in the 
            operating system environment. You can just use the libraries and get 
            on with the real creative stuff.</P>
            <TABLE cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
              <TR>
                <TD><IMG height=447 
                  alt="Figure 7-1 MFC's user interface builder." 
                  src="第七课  库 和 Microsoft Foundation Classes (MFC).files/icwL7_Fig1.jpg" 
                  width=585 align=left> </TD></TR>
              <TR>
                <TD align=middle><FONT size=1><I>Figure 7-1 MFC's user 
                  interface builder.</I></FONT> </TD></TR></TBODY></TABLE>
            <P>Application frameworks also handle the dispatching of messages 
            (such as user keystrokes, mouse clicks, drawing messages, etc.) to 
            the many buttons, lists, windows, and controls in your application. 
            This allows you to keep your application's code focused on its own 
            features rather than on addressing interface questions like "How do 
            I tell when the user pressed the Enter key?" or "How do I know when 
            I need to redraw the contents of a window?" It's really the little 
            things that mean the most once you are actually using the 
            application.</P>
            <P>Application frameworks provide many benefits over the old-style 
            roll-your-own approach. For one thing, the code is mature and well 
            tested. Hundreds of applications are being built by hundreds of 
            developers using MFC every single day. It is constantly being 
            updated as new features are added to the Windows operating system. 
            In many cases, you can recompile your application with a new version 
            of MFC and take advantage of all the new features with few if any 
            changes to your source code.</P>
            <P>Application frameworks also provide reusable code. Code reuse is 
            one of the main reasons object-oriented coding methodologies like 
            C++ were developed. By writing code in reusable classes, you can 
            easily build upon existing classes to add necessary features. Code 
            reuse allows you to depend on well-tested code throughout your 
            application and feel confident that the code will work as expected. 
            It is also very easy to share classes that you build with others who 
            may need the same features.</P>
            <P>Application frameworks can sometimes make your programs a bit 
            larger than they might be if you were to create them completely from 
            scratch. Since modern computers are usually equipped with 
            substantial amounts of memory, and since the framework can be used 
            as a DLL, it's fairly easy to justify the added bulk. PowerPlant and 
            MFC are both very powerful tools that you should consider using.</P>
            <P>Your best bet now is to focus on learning more about MFC and how 
            it can assist you -- and you can make the decision on how much you 
            want done for you, or how much you want to dig in and do yourself. 
            </P>
            <P><B><FONT size=+1>How to Install and Use MFC Interface 
            Tools</FONT></B></P>
            <P>The MFC interface tools (including Dialog Editor and Image 
            Editor) are located on the CodeWarrior CD. Unfortunately, they're 
            not part of the CodeWarrior Installation, so after the initial 
            CodeWarrior installation, you won't find them on your hard drive. In 
            order to install the tools, simply perform the following steps:
            <UL>
              <LI>You need to locate the file named iTOOLS.Exe. This is the 
              installation program you will use to install the MFC Interface 
              Tools. The iTools.Exe file should be located at C:\Program 
              Files\Metrowerks\CodeWarrior\BinSDK\bin\. If you can't find the 
              file there, then go to the CodeWarrior CD. The file iTOOLS.Exe can 
              be located in the folder Extras\SKDs\Win32\Microsoft Win32 SDK 
              Tools\. </LI></UL>
            <BLOCKQUOTE><B>
              <P>Note:</B> The Installation program (iTOOLS.Exe) will ask you 
              where you want to save the MFC Interface Tools. Unfortunately, 
              there is no Browse button to locate a folder location, so you will 
              have to manually type in a directory path. If you are unsure of 
              the exact path for where you want to save the tools, locate a file 
              that resides in the folder where you want to save the tools and 
              retrieve the complete path for this folder by examining the file's 
              properties (right-click on the file and select Properties). Here's 
              a quick tip: you can actually copy the path from this Properties 
              box and then paste the path when prompted by the installation 
              program.</P></BLOCKQUOTE>
            <UL>
              <LI>The tools will be located in the \bin\ folder of the target 
              installation folder. The \bin\ folder is where you'll find the 
              Dialog Editor (DlgEdit.Exe), Image Editor (ImagEdit.Exe), and 
              other useful tools. 
              <LI>If you're developing applications for Windows 95 or Windows 
              NT, the necessary tools are available in the folders \bin\win95 
              and \bin\winnt, respectively. 
      </FONT></LI></UL></TD></TR></TBODY></TABLE></CENTER></DIV></TD></TR>
  <TR>
    <TD width="100%">
      <P align=right><NOBR><INPUT onclick=self.close(); type=button value="关闭此窗口 "></NOBR> 
      </P></TD></TR>
  <TR>
    <TD width="100%">
      <HR width="96%" color=#000000 noShade SIZE=1>
    </TD></TR>
  <TR>
    <TD class=font width="100%">
      <P align=center>Copyright(C) 2000 <A 
      href="http://www.tsinghua-solution.com.cn/" 
      target=_blank>北京清华北方思路信息技术有限公司</A> 版权所有<BR>未经许可,不得转载、摘登、结集出版<BR>联系电话:(8610)-62978899-146</P></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -