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

📄 ch11.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
	<P><HR><strong>TIP:</strong> When both icons are present, you can switch between them using the	combo box at the top of the Icon Editor window. <HR></BLOCKQUOTE><H4>Icon Editing Options</H4><P>The Delete item on the Icon menu enables you to delete either the large or thesmall icon from the icon resource. You cannot delete the last icon in the icon resource.</P><P>The Test item on the Icon menu displays the Icon Tester dialog box, which showsyou what the icon will look like when displayed. Figure 11.5 shows the Icon Testerdialog box in action.</P><P><A HREF="javascript:popUp('28671105.gif')"><B>FIGURE 11.5.</B></A><B> </B><I>TheIcon Tester dialog box.</I></P><P>The Icon Tester enables you to change the background color so that you can viewthe effect that different backgrounds have on the appearance of your icon. If youare currently editing the large icon, the large icon appears in the Icon Tester.If you are currently editing the small icon, the Icon Tester dialog box displaysthe small icon.</P><P><H3><A NAME="Heading9"></A>Working with Cursors</H3><P>Working with cursors is not much different than working with icons. A cursor hasonly two colors: white and black. (Multicolor and animated cursors are not supportedby the Image Editor.) Draw the cursor as you want it to appear.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> A peculiarity of the Cursor Editor is that the transparent color	is set to the color of your system's background color instead of the dark green color	used for the Icon Editor. If you have your Windows background color set to a very	light color, it can be difficult to see what is transparent and what is white. If	you are having difficulty distinguishing the background color from white, set your	Windows background color to a different value (such as dark green).<HR></BLOCKQUOTE><P>As when editing bitmap files and icons, the Image Editor menu displays a menuitem called Cursor when you are editing a cursor. This menu item has two items: SetHot Spot and Test.</P><P>The Set Hot Spot item enables you to specify the cursor's hot spot. The <I>hotspot</I> is the specific pixel of the cursor that Windows uses to report the mousecoordinates when your cursor is being used. For example, the hot spot on a crosshaircursor is the exact center of the crosshairs. For a pointer cursor, the hotspot isset to the tip of the arrow's point. To set the hot spot, choose Cursor|Set Hot Spotfrom the main menu. The Set Cursor Hot Spot dialog box appears, where you can enterthe x and y coordinates of the hot spot.</P><BLOCKQUOTE>	<P><HR><strong>TIP:</strong> You must enter the exact x and y coordinates for the hot spot. To	make this easier, before setting the hot spot, place the editing cursor over the	point on the cursor where you want the hot spot. The Image Editor status bar will	display the x and y coordinates of the point under the cursor. Make note of the x	and y coordinates, and then choose Cursor|Set Hot Spot from the main menu and enter	those x and y coordinates.<HR></BLOCKQUOTE><P>The Test item on the Cursor menu gives you the opportunity to try out your newcursor. Choose Cursor|Test from the main menu and the Cursor Tester dialog box willbe displayed, as shown in Figure 11.6.</P><P><A HREF="javascript:popUp('28671106.gif')"><B>FIGURE 11.6.</B></A><B> </B><I>Testingthe cursor.</I></P><P>Hold down either mouse button to draw on the Cursor Tester window. If you haven'tyet set the hot spot, you will probably notice that the hot spot is set to the upper-leftcorner of the cursor by default. You should always set the hot spot to a point onyour cursor that will be logical to users of your application.</P><P><H3><A NAME="Heading10"></A>Image Editor Context Menus</H3><P>The Image Editor has context menus for each editing mode (Bitmap, Cursor, andIcon). You might recall that the right mouse button is used for drawing, so you can'tbring up the context menus by clicking the mouse button while over the image. Todisplay the Image Editor context menus, right-click when the cursor is within theeditor window but outside the image. The context menus contain the same items foundon the individual menus, as discussed in the previous sections.</P><P><BR><B>Creating Resource Projects</B></P><P>The Image Editor also enables you to create a resource project file for storingall your bitmaps, icons, and cursors. To create a resource project, choose File|Newfrom the main menu and then choose Resource File from the pop-up menu. A projectwindow is displayed. The project window is a tree view control that shows the bitmaps,icons, and cursors in the project. Figure 11.7 shows the project window for a sampleproject.</P><P><A HREF="javascript:popUp('28671107.gif')"><B>FIGURE 11.7.</B></A><B> </B><I>TheImage Editor project window.</I></P><P>The project window has a context menu that can be used to create new resources,edit resources, rename resources, and delete resources. The items on the contextmenu are also duplicated on the main menu under the Resource menu item.</P><P>When you save the resource project, the Image Editor will compile it into a binaryresource file (.res). You can then add the binary resource file to your Delphi project.</P><P><H4>Creating New Resources</H4><P>To create a new resource for your project, choose New from the project windowcontext menu or Resource|New from the main menu. You can then choose to create anew bitmap, icon, or cursor, as you did before when creating an individual resourcefile. A resource editor window will be displayed where you can create the resourceusing the drawing tools as needed.</P><P><H4>Editing Resources</H4><P>When you have a resource created, you might need to edit it to make changes tothe resource. To edit a resource in a resource project, locate the resource in theproject window tree and double-click the resource name. A resource editor windowwill appear where you can edit the resource as needed.</P><P><H4>Renaming Resources</H4><P>Renaming resources can be accomplished using in-place editing on the tree view.To select the item you want to rename, just click it and then click on it again tobegin editing the item. You can also choose Rename from the context menu to beginthe in-place editing. After you have typed a new name for the resource, press Enteror click on another item in the tree view, and the name of the resource will change.</P><P><H4>Deleting Resources</H4><P>To delete a resource from the resource project, just click the resource name inthe project tree to select it and then choose Delete from the context menu. You willbe prompted to make certain you want to delete the item, after which it will be deleted.There is no undo for deleting a resource, so make sure a resource is no longer neededbefore you delete it.</P><P><H4>Adding Resources from Other Resource Files</H4><P>Unfortunately, there is no simple way to add a resource contained in a separatefile to a resource project. What you can do, however, is open your project file andthen open the individual bitmap, icon, or cursor file that contains the resourceyou want to add to the project. Go to the individual file and choose Edit|SelectAll from the main menu to select the resource; then choose Edit|Copy to copy theobject to the Clipboard. Create the new resource in the resource project. When theresource editor window is displayed, choose Edit|Paste from the main menu to pastethe resource into the new resource.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> If the object you are adding to the resource project is a bitmap,	be sure you check the bitmap attributes so that you know the width, height, and color	depth of the bitmap. You will need those settings when you create the new bitmap	in the resource project.<HR></BLOCKQUOTE><P>The Image Editor is not a high-end image editor, but it's good enough for manyimage-creation tasks. It's easy to use and is more than adequate for creating mosticons and cursors.</P><P><H2><A NAME="Heading11"></A>WinSight: Spying on Windows</H2><P>WinSight is a utility that enables you to spy on Windows. WinSight will show youevery application running and every window running under that application. (Remember:Controls are windows, too.) WinSight shows you every message generated by Windows(every message sent to a window, that is).</P><P>You can elect to view all messages or just messages sent to a specific window.To start WinSight, locate WS32.EXE from Windows Explorer and double-click the file(it's in the Delphi 4\Bin directory). WinSight, like the Image Editor, is a stand-aloneprogram that can be run outside the Delphi IDE. Figure 11.8 shows WinSight spyingon Windows Explorer.</P><P><A HREF="javascript:popUp('28671108.gif')"><B>FIGURE 11.8.</B></A><B> </B><I>WinSightin action.</I></P><P>As you can see in Figure 11.8, the WinSight window is split into two panes. Thetop pane lists the active windows, and the bottom pane shows the messages being sentto a particular window or to all windows. You can adjust the size of the panes bydragging the sizing bar between the two windows. The default is for the windows tobe split horizontally, but you can opt to split the windows vertically. To changethe window layout, choose either Split Horizontal or Split Vertical from the Viewmenu.</P><P>You'll examine each of the two windows in more detail in just a bit, but firstlet me take a moment to talk about Windows messages.</P><P><H3><A NAME="Heading12"></A>The Windows Messaging System</H3><P>Spying on Windows isn't helpful if you don't know what any of it means. (The thrillof being a legal Peeping Tom wears off quickly.) The truth is, you have to spenda fair amount of time at Windows programming before you can understand all the informationpresented by WinSight.</P><P>Delphi is great for enabling you to write true stand-alone Windows applicationsin the shortest time possible. If there is a disadvantage to this kind of programmingenvironment, it is that you do not have the opportunity to learn what really makesa Windows program run.</P><P>What makes a Windows program run is messages. Lots and lots of messages. Windowssends a window message to instruct the window to do something or to notify the windowthat some event has taken place. When a window is in need of repainting, for example,Windows sends it a WM_PAINT message. The WM_PAINT message instructs the window torepaint itself.</P><P>When a window is resized, Windows sends a WM_WINDOWPOSCHANGING message to notifythe window that its size and/or position is changing. This message is followed byWM_WINDOWPOSCHANGED and WM_SIZE messages after the window has been sized. The sendingof messages happens dozens or even hundreds of times each second in an average Windowsenvironment.</P><P>There are more than 100 messages that Windows can send to an application. I talkeda little about that on Day 5, &quot;The Visual Component Model,&quot; when I discussedevents in VCL. Many events that a Delphi program responds to are Windows messages.The OnCreate event is generated in response to a WM_CREATE message, the OnSize eventis generated in response to a WM_SIZE message, and the OnMouseDown event correspondsto both the WM_LBUTTONDOWN and WM_RBUTTONDOWN messages. The list goes on and on.Delphi enables you to deal with messages at a higher level, thus freeing you to writethe more important parts of your application.</P><P>Eventually you will want to learn more about what makes Windows tick. The greatbenefit of Delphi, though, is that you can write Windows programs immediately andgradually learn about all the low-level stuff.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> Some very good Windows programmers would argue that you should first	learn to write Windows programs in C like in the good old days. The theory is that	this kind of foundation is necessary for a Windows programmer to be effective in	any programming environment. Although I would agree that that is the optimum scenario,	I also recognize that few programmers these days have the time for that kind of learning	process.<HR></BLOCKQUOTE><P>With that primer on Windows messages behind you, let's get back to WinSight andhow it works.</P><P><BR><B>The Window Tree</B></P><P><B><BR></B>The top pane of WinSight is called the Window Tree. The Window Tree shows youall windows currently open. It also tells you some details about the window classof a specific window. The detail looks like this (except that onscreen it all appearson one line):</P><P><PRE>Overlapped 00000D74 {ExploreWClass}  EXPLORER.EXE (730,14)-(935,460) `Exploring - aTemplate'</PRE><P>The first item in this line shows the window style of the window. In this caseit is an overlapped window (WS_OVERLAPPED for you old Windows hackers). Other possibilitiesinclude child and pop-up windows. (There are other window types, but overlapped,child, and pop-up are the most common.) The second column shows the window handle(HWND) of the window, which correlates to the Handle property of a VCL windowed component.</P><P>Next, you see the window class name in curly braces. This is the class name thatthe application used to register this particular window with Windows. Frequently,windows share a class name. The common button control, for example, has a class nameof Button. Dozens of buttons might exist in different applications at any given time,but they are all of the same window class. In the case of Delphi applications, formsand components show the VCL class that represents that component. For a button component,the class name in WinSight shows TButton.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> When Delphi 1 was in development, the code name for the project was	Delphi. The intended name for the product, however, was AppBuilder. The name Delphi	stuck and became the official product name. If you spy on the Delphi IDE with WinSight,	you will discover that the Delphi main window has a class name of TAppBuilder, thereby	lending credibility to this tale.<HR></BLOCKQUOTE><P>Following the class name is the module name of the process that created the window.Usually the module is an executable program. In this example, the module name isEXPLORER.EXE. After the module name, you see the window's size and position. Finally,you see the window text of the window. For overlapped windows, this usually meansthe text appearing in the title bar. For other types of windows, it means differentthings depending on the window type. For a button, for example, it will show thetext on the button.</P>

⌨️ 快捷键说明

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