📄 ch13.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</head>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//--> </SCRIPT><link rel="stylesheet" href="/includes/stylesheets/ebooks.css"> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"> <TITLE>Teach Yourself Borland Delphi 4 in 21 Days -- Ch 13 -- Beyond the Basics</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"></H1></CENTER><CENTER><H1><BR>Teach Yourself Borland Delphi 4 in 21 Days</H1></CENTER><CENTER><P><A HREF="../ch12/ch12.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch14/ch14.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1>- 13 -</H1></CENTER><CENTER><H1>Beyond the Basics</H1></CENTER><UL> <LI><A HREF="#Heading1">Creating Window Decorations</A> <UL> <LI><A HREF="#Heading2">Toolbars</A> <LI><A HREF="#Heading3">The CoolBar Component</A> <LI><A HREF="#Heading4">The ToolBar Component</A> <LI><A HREF="#Heading5">Dockable Toolbars</A> <LI><A HREF="#Heading6">Status Bars</A> </UL> <LI><A HREF="#Heading7">Adding Functionality with Command Enabling</A> <UL> <LI><A HREF="#Heading8">Command Enabling with TActionList and TAction</A> <LI><A HREF="#Heading9">Implementing Command Enabling</A> </UL> <LI><A HREF="#Heading10">Printing in Delphi Applications</A> <UL> <LI><A HREF="#Heading11">The Common Printing Dialog Boxes</A> <LI><A HREF="#Heading12">Printing the Easy Way</A> <LI><A HREF="#Heading13">Printing via QuickReport</A> <LI><A HREF="#Heading14">Printing the Hard Way</A> <LI><A HREF="#Heading15">Putting It to Work</A> <LI><A HREF="#Heading16">Printing a Bitmap</A> </UL> <LI><A HREF="#Heading17">Using Cursors</A> <UL> <LI><A HREF="#Heading18">Cursor Basics</A> <LI><A HREF="#Heading19">Loading and Using Stock Cursors</A> <LI><A HREF="#Heading20">Loading and Using Custom Cursors</A> </UL> <LI><A HREF="#Heading21">Summary</A> <LI><A HREF="#Heading22">Workshop</A> <UL> <LI><A HREF="#Heading23">Q&A</A> <LI><A HREF="#Heading24">Quiz</A> <LI><A HREF="#Heading25">Exercises</A> </UL></UL><P><HR SIZE="4"><CENTER><H1></H1></CENTER><P>Today you learn ways to turn a good Windows application into a great Windows application.Specifically, I discuss the following:</P><UL> <LI>Window decorations: toolbars and status bars <P> <LI>Command enabling <P> <LI>Printing in Delphi applications <P> <LI>Using cursors</UL><P>This discussion continues tomorrow as you look at implementing advanced Windowsprogramming features in your Delphi applications.</P><P><H2><A NAME="Heading1"></A>Creating Window Decorations</H2><P>No, I'm not talking about pretty lights around the front window of your house.What I am talking about are features such as toolbars and status bars. These featuresare often called <I>window decorations</I>. This section deals with these types ofdecorations and how to implement them in your application.</P><P><H3><A NAME="Heading2"></A>Toolbars</H3><P>A toolbar (also called a control bar or a speedbar) is almost standard equipmentfor Windows programs today. Users expect certain amenities, and a toolbar is oneof them. A top quality toolbar should have the following features and capabilities:</P><UL> <LI>Buttons representing tasks that are also available on the application's menus. <P> <LI>Enabling and disabling of buttons when appropriate. <P> <LI>Tooltips describing a button's function. <P> <LI>Additional hint text that is displayed in the application's status bar. <P> <LI>Docking capability. <P> <LI>Other controls such as combo boxes or drop-down menu buttons.</UL><P>Some of the features in this list are optional features that not every toolbarneeds to have. With Delphi, implementing these toolbar features is easy to accomplish.A little later in the chapter I talk about command enabling in the section "AddingFunctionality with Command Enabling." I'll save discussion of command enablingfor toolbar buttons for that time.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> It is considered good practice to place on the toolbar only buttons that have corresponding menu items. The toolbar is an alternative to using the menu. It should not contain items found nowhere else in the program. <HR></BLOCKQUOTE><P>On Day 8, "Creating Applications in Delphi," I said that the easiestway to construct a toolbar is to use the Application Wizard. Even if you alreadyhave a partially written application, you can still use the Application Wizard tocreate a toolbar. Just generate an application with the Application Wizard, copythe panel with the toolbar to the Clipboard, reopen your original application (don'tbother saving the Application Wizard application), and paste the toolbar into yourapplication from the Clipboard. Slick and easy.</P><P>However, the Application Wizard doesn't give you everything you could possiblyneed in a toolbar. Most notably, the Application Wizard uses the old method of creatinga toolbar--with a panel and speed buttons. The preferred way of creating a toolbaris to use the ToolBar and CoolBar components (found on the Win32 tab of the Componentpalette). Let's take a look at those components next.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The CoolBar and ToolBar components require version 4.72.2106.4 or later of COMCTL32.DLL, which should have been installed as part of the Delphi installation. If you don't have the latest version of this DLL, you can find it at Microsoft's Web site (http://www.microsoft.com). When you deploy your applications using these components, you should install COMCTL32.DLL version 4.70 or later. Be sure you are using a good installation program so that you don't overwrite a new version of this DLL when you install your application. <HR></BLOCKQUOTE><H3><A NAME="Heading3"></A>The CoolBar Component</H3><P>The CoolBar component is an encapsulation of the Win32 <I>cool bar</I> (sometimescalled a rebar). This component is a specialized container control. Most of the timethe CoolBar is used as a container for toolbars, but its use isn't limited strictlyto toolbars.</P><P><H4>Cool Bar Bands</H4><P>A cool bar has bands that can be moved and resized at runtime. The bands showa sizing grip on the left side, giving the user a visual cue that the band can bemoved or sized. Cool bar bands are represented by the TCoolBand class. A cool barband can contain only one component. Usually that component is a toolbar, but itcan be a combo box or any other component. Let's do an exercise to better understandhow the CoolBar component works:</P><DL> <DT></DT> <DD><B>1. </B>Start with a new application and drop a CoolBar component on the form. <P> <DT></DT> <DD><B>2. </B>Drop a ComboBox component on the cool bar. Delphi creates a new band to hold the combo box. Notice that the combo box fills the width of the cool bar. <P> <DT></DT> <DD><B>3. </B>Drop another ComboBox component on the cool bar. Another band is created and is placed below the first band. <P> <DT></DT> <DD><B>4. </B>Place your mouse cursor between the sizing grip and the combo box on the second band. The cursor will change to a pointing hand, indicating that you can move the band. (You can also use the sizing grip to drag the band.) Drag the band up into the band above it. As you do, the first band will shrink to make room for the band you are dragging. Drop the band near the middle of the cool bar. You can now use the sizing grips to resize either band. <P> <DT></DT> <DD><B>5. </B>Place a Panel component on the cool bar. A new band is created to hold the panel. <P> <DT></DT> <DD><B>6. </B>Select the cool bar and change its AutoSize property to True. <P> <DT></DT> <DD><B>7. </B>Place a Memo component on the form below the cool bar. Set its Align property to alClient. <P></DL><P>Now your form looks like Figure 13.1.</P><P><A HREF="javascript:popUp('28671301.gif')"><B>FIGURE 13.1.</B></A><B> </B><I>Theform with a cool bar and three bands.</I></P><P>Now run the program. Experiment with the cool bar bands. Drag them up or downor resize them. Notice that as you drag the bands up or down, the cool bar resizesas needed and the memo always fills the remaining client area.</P><P>Cool bar bands are accessed through the Bands property. This property is a TCoolBands,which is a list of TCoolBand components. If you want to hide the second band, youcan do this:</P><P><PRE>CoolBar.Bands[1].Visible := False;</PRE><P>You can add bands in two ways. As you have already seen, you can create a bandby dropping any component on the cool bar, but you can also use the Bands Editor.To invoke the Bands Editor, double-click the cool bar or click the ellipsis buttonnext to the Bands property in the Object Inspector. You add bands by clicking theAdd button; you delete bands by clicking the Delete button. The Move Up and MoveDown buttons enable you to change the order of the bands.</P><BLOCKQUOTE> <P><HR><STRONG>NOTE: </STRONG>If the AutoSize property is set to True, you will have to turn it off temporarily if you want to add new bands by dropping components on the cool bar. Set the AutoSize property to False, make the cool bar higher, drop a component on the cool bar, and set the AutoSize property to True again. <HR></P> <P><HR><strong>NOTE:</strong> When you select a band in the Bands Editor, the Object Inspector displays the band's properties. Figure 13.2 shows the Bands Editor and the Object Inspector when a band is selected. <HR></P></BLOCKQUOTE><P><A HREF="javascript:popUp('28671302.gif')"><B>FIGURE 13.2.</B></A><B> </B><I>Thecool bar Bands Editor.</I></P><P>The Bitmap property enables you to set a background bitmap for a band. To selectan image that will appear to the left of the band, you use ImageIndex. ImageIndexrequires the ImageList property of the cool bar to be set to a valid TImageList.You can set a band's minimum height and width through the MinHeight and MinWidthproperties. To make a band immovable, set the FixedSize property to True.</P><P><H4>Other CoolBar Properties</H4><P>A cool bar can be either vertical or horizontal. By default the Align propertyis set to alTop. To make a vertical cool bar, change the Align property to alRightor alLeft. Some components, when placed on a cool bar, automatically orient themselves
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -