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

📄 body.tex

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 TEX
📖 第 1 页 / 共 3 页
字号:
suitability of this software for any purpose.  It is provided ``as is''without express or implied warranty.}\chapter{Multi-platform development with wxWidgets}\label{multiplat}\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%\setfooter{\thepage}{}{}{}{}{\thepage}%This chapter describes the practical details of using wxWidgets. Pleasesee the file install.txt for up-to-date installation instructions, andchanges.txt for differences between versions.\section{Include files}\label{includefiles}The main include file is {\tt "wx/wx.h"}; this includes the most commonlyused modules of wxWidgets.To save on compilation time, include only those header files relevant to thesource file. If you are using precompiled headers, you should includethe following section before any other includes:\begin{verbatim}// For compilers that support precompilation, includes "wx.h".#include <wx/wxprec.h>#ifdef __BORLANDC__#pragma hdrstop#endif#ifndef WX_PRECOMP// Include your minimal set of headers here, or wx.h#include <wx/wx.h>#endif... now your other include files ...\end{verbatim}The file {\tt "wx/wxprec.h"} includes {\tt "wx/wx.h"}. Although this incantationmay seem quirky, it is in fact the end result of a lot of experimentation,and several Windows compilers to use precompilation which is largely automatic forcompilers with necessary support. Currently it is used for Visual C++ (includingembedded Visual C++), Borland C++, Open Watcom C++, Digital Mars C++and newer versions of GCC.Some compilers might need extra work from the application developer to set thebuild environment up as necessary for the support.\section{Libraries}\label{libraries}Most ports of wxWidgets can create either a static library or a sharedlibrary. wxWidgets can also be built in multilib and monolithic variants.See the \helpref{libraries list}{librarieslist} for moreinformation on these.\section{Configuration}\label{configuration}When using project files and makefiles directly to build wxWidgets,options are configurable in the file\rtfsp{\tt "wx/XXX/setup.h"} where XXX is the required platform (such as msw, motif, gtk, mac). Some settings are a matter of taste, some help with platform-specific problems, andothers can be set to minimize the size of the library. Please see the setup.h fileand {\tt install.txt} files for details on configuration.When using the 'configure' script to configure wxWidgets (on Unix and other platforms whereconfigure is available), the corresponding setup.h files are generated automaticallyalong with suitable makefiles. When using the RPM packagesfor installing wxWidgets on Linux, a correct setup.h is shipped in the package andthis must not be changed.\section{Makefiles}\label{makefiles}On Microsoft Windows, wxWidgets has a different set of makefiles for eachcompiler, because each compiler's 'make' tool is slightly different.Popular Windows compilers that we cater for, and the corresponding makefileextensions, include: Microsoft Visual C++ (.vc), Borland C++ (.bcc),OpenWatcom C++ (.wat) and MinGW/Cygwin (.gcc). Makefiles are providedfor the wxWidgets library itself, samples, demos, and utilities.On Linux, Mac and OS/2, you use the 'configure' command togenerate the necessary makefiles. You should also use this method whenbuilding with MinGW/Cygwin on Windows.We also provide project files for some compilers, such asMicrosoft VC++. However, we recommend using makefilesto build the wxWidgets library itself, because makefilescan be more powerful and less manual intervention is required.On Windows using a compiler other than MinGW/Cygwin, you wouldbuild the wxWidgets library from the build/msw directorywhich contains the relevant makefiles.On Windows using MinGW/Cygwin, and on Unix, MacOS X and OS/2, you invoke'configure' (found in the top-level of the wxWidgets source hierarchy),from within a suitable empty directory for containing makefiles, object files andlibraries.For details on using makefiles, configure, and project files,please see docs/xxx/install.txt in your distribution, wherexxx is the platform of interest, such as msw, gtk, x11, mac.\section{Windows-specific files}\label{windowsfiles}wxWidgets application compilation under MS Windows requires at least oneextra file: a resource file.\subsection{Resource file}\label{resources}The least that must be defined in the Windows resource file (extension RC)is the following statement:\begin{verbatim}#include "wx/msw/wx.rc"\end{verbatim}which includes essential internal wxWidgets definitions.  The resource scriptmay also contain references to icons, cursors, etc., for example:\begin{verbatim}wxicon icon wx.ico\end{verbatim}The icon can then be referenced by name when creating a frame icon. Seethe MS Windows SDK documentation.\normalbox{Note: include wx.rc {\it after} any ICON statementsso programs that search your executable for icons (suchas the Program Manager) find your application icon first.}\section{Allocating and deleting wxWidgets objects}\label{allocatingobjects}In general, classes derived from wxWindow must dynamically allocatedwith {\it new} and deleted with {\it delete}. If you delete a window,all of its children and descendants will be automatically deleted,so you don't need to delete these descendants explicitly.When deleting a frame or dialog, use {\bf Destroy} rather than {\bf delete} sothat the wxWidgets delayed deletion can take effect. This waits until idle time(when all messages have been processed) to actually delete the window, to avoidproblems associated with the GUI sending events to deleted windows.Don't create a window on the stack, because this will interferewith delayed deletion.If you decide to allocate a C++ array of objects (such as wxBitmap) that maybe cleaned up by wxWidgets, make sure you delete the array explicitlybefore wxWidgets has a chance to do so on exit, since calling {\it delete} onarray members will cause memory problems.wxColour can be created statically: it is not automatically cleanedup and is unlikely to be shared between other objects; it is lightweightenough for copies to be made.Beware of deleting objects such as a wxPen or wxBitmap if they are still in use.Windows is particularly sensitive to this: so make sure youmake calls like wxDC::SetPen(wxNullPen) or wxDC::SelectObject(wxNullBitmap) before deletinga drawing object that may be in use. Code that doesn't do this will probably workfine on some platforms, and then fail under Windows.\section{Architecture dependency}\label{architecturedependency}A problem which sometimes arises from writing multi-platform programs is thatthe basic C types are not defined the same on all platforms. This holds truefor both the length in bits of the standard types (such as int and long) as well as their byte order, which might be little endian (typicallyon Intel computers) or big endian (typically on some Unix workstations). wxWidgetsdefines types and macros that make it easy to write architecture independentcode. The types are:wxInt32, wxInt16, wxInt8, wxUint32, wxUint16 = wxWord, wxUint8 = wxBytewhere wxInt32 stands for a 32-bit signed integer type etc. You can also checkwhich architecture the program is compiled on using the wxBYTE\_ORDER definewhich is either wxBIG\_ENDIAN or wxLITTLE\_ENDIAN (in the future maybe wxPDP\_ENDIANas well).The macros handling bit-swapping with respect to the applications endiannessare described in the \helpref{Byte order macros}{byteordermacros} section.\section{Conditional compilation}\label{conditionalcompilation}One of the purposes of wxWidgets is to reduce the need for conditionalcompilation in source code, which can be messy and confusing to follow.However, sometimes it is necessary to incorporate platform-specificfeatures (such as metafile use under MS Windows). The symbolslisted in the file {\tt symbols.txt} may be used for this purpose,along with any user-supplied ones.\section{C++ issues}\label{cpp}The following documents some miscellaneous C++ issues.\subsection{Templates}\label{templates}wxWidgets does not use templates (except for some advanced features thatare switched off by default) since it is a notoriously unportable feature.\subsection{RTTI}\label{rtti}wxWidgets does not use C++ run-time type information since wxWidgets providesits own run-time type information system, implemented using macros.\subsection{Type of NULL}\label{null}Some compilers (e.g. the native IRIX cc) define NULL to be 0L so thatno conversion to pointers is allowed. Because of that, all theseoccurrences of NULL in the GTK+ port use an explicit conversion such as{\small\begin{verbatim}  wxWindow *my_window = (wxWindow*) NULL;\end{verbatim}}%It is recommended to adhere to this in all code using wxWidgets asthis make the code (a bit) more portable.\subsection{Precompiled headers}\label{precompiledheaders}Some compilers, such as Borland C++ and Microsoft C++, supportprecompiled headers. This can save a great deal of compiling time. Therecommended approach is to precompile {\tt "wx.h"}, using thisprecompiled header for compiling both wxWidgets itself and anywxWidgets applications. For Windows compilers, two dummy source filesare provided (one for normal applications and one for creating DLLs)to allow initial creation of the precompiled header.However, there are several downsides to using precompiled headers. Oneis that to take advantage of the facility, you often need to include

⌨️ 快捷键说明

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