📄 ch11.htm
字号:
<BLOCKQUOTE> <P><HR><strong>NOTE:</strong> A common practice with commercial applications is to create hidden windows to accomplish a specific task in the application. Hidden windows just show the text (hidden) after the module name. Because the window is hidden, there is no size and position information, nor is there any window text.<HR></BLOCKQUOTE><P>The Window Tree is hierarchical. At the top of the tree is the Windows Desktop.Under that are any windows created as children of the desktop. An executable file,for example, appears under the desktop node. A given window can have other childwindows under it. Lines connect the parents, their children, and any siblings.</P><P>You will notice back in Figure 11.8 that a diamond appears to the left of eachitem in the Tree Window. If a window has children, the diamond contains either aplus sign or a minus sign. If the diamond has a plus sign, it means the node is contractedand can be expanded to reveal the child windows. If the node has a minus sign, theplus is already expanded. You can expand or contract a node by clicking anywhereto the left of the item. Blank diamonds indicate a window without children.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> If a particular window is enabled in the Window Tree, the diamond next to the item flashes whenever the window receives a message from Windows. <HR></BLOCKQUOTE><H3><A NAME="Heading13"></A>The Message Trace Window</H3><P>The Message Trace window shows the individual messages as they are generated byWindows. A typical Message Trace item looks like this:</P><P><PRE>000684:00000854 {TMemo} WM_KEYDOWN Dispatched 48h 72d VK_H Scan 23h Down</PRE><P>It doesn't pay to analyze this in detail because the exact details vary so muchfrom message to message. In this case, a memo component received a WM_KEYDOWN messagewith a parameter of VK_H. In other words, the user pressed the <I>h</I> key withthe cursor in a memo component. As you can see, some of the information shown ina Message Trace item also appears in the Window Tree. For example, the window handleis displayed as well as the class name.</P><P>You begin the message trace by choosing the Start! item in the main menu. Themessages will begin appearing in the Message Trace window as they are received bythe window or windows you have selected. To stop the message trace, choose the Stop!item in the main menu.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The Stop! and Start! items in the main menu occupy the same place on the menu bar. If the message trace is off, the menu item reads Start! If the trace is running, the menu item reads Stop!.<HR></BLOCKQUOTE><P>Messages scroll through the Message Trace window as they are received. You canalways stop the message trace and scroll back through the list to view any messagesthat have scrolled out of view. Another option is to send the message output to alog file. WinSight options are discussed later in the section "Message TraceOptions."</P><P><H3><A NAME="Heading14"></A>Spying on a Window</H3><P>WinSight enables you to view all messages sent to all windows or messages sentto a particular window. To view all messages, choose Messages|All Windows from themain menu. Although you can choose to view all messages sent to all windows, it isn'tusually productive. There are so many messages flying around that it is hard to pickout the specific ones you are looking for.</P><P>A better method is to select a specific window and then watch the messages forjust that window. That will keep the clutter in the Message Trace window to a manageablelevel. To view the messages for a specific window, locate the window in the MessageTree and click on it to select it. Now choose Messages|Selected Windows from themain menu. Choose Start!, and any messages sent to the selected window will showup in the Message Trace window.</P><BLOCKQUOTE> <P><HR><strong>TIP:</strong> It's best to have a specific idea of what you are looking for when you are using WinSight. Because there are so many messages sent to an individual window, the message you are looking for will probably scroll off the screen very quickly. To maximize the effectiveness of WinSight, select the window for which you want to see messages, start the message trace, manipulate the window any way you need to, and turn off the message trace again. <HR></BLOCKQUOTE><H3><A NAME="Heading15"></A>Message Trace Options</H3><P>You can control the messages displayed in the Message Trace window via the MessageTrace Options dialog box (see Figure 11.9). You can also change the way the messageis displayed. To view the Message Trace Options dialog box, choose Messages|Optionsfrom the main menu.</P><P><BR><A HREF="javascript:popUp('28671109.gif')"><B>FIGURE 11.9.</B></A> <I>The MessageTrace Options dialog box.</I></P><P><BR>The section entitled Messages to Trace comprises the bulk of this dialog box. Thissection shows several message groups on the left and a list box displaying all Windowsmessages on the right. As you select or deselect message groups, the correspondingmessages will be selected or deselected in the list box.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> The list box messages that are all uppercase are the standard Windows messages. The lowercase messages are <I>undocumented</I> Windows messages. Undocumented messages are messages that are used by Windows, usually for internal use, but are not documented in the Windows API help files. <HR></BLOCKQUOTE><P>When the All Messages option is checked, WinSight will trace all Windows messages.To further specify your messages and thus to reduce clutter in the Message Tracewindow, you can elect to view only certain groups of messages. If, for example, youwant to view only mouse messages, you can turn off the All Messages check box andturn on the Mouse check box. To further specify, you can turn off all options andthen choose a specific message from the list box on the right of the dialog box.For example, if you want to see only the WM_LBUTTONDOWN message, you can turn offall options and then select just the WM_LBUTTONDOWN message from the list box. Onlythe WM_LBUTTONDOWN messages will be reported in the Message Trace window.</P><P>Another group of options on the Message Trace Options dialog box controls howthe messages are displayed in the Message Trace window. The Interpret Values optiontells WinSight to break down each message's parameters into a more readable format.For example, given a WM_KEYDOWN message, would you rather see</P><P><PRE>0000309:00000474 {TMemo} WM_KEYDOWN Dispatched</PRE><P>or</P><P><PRE>0000309:00000474 {TMemo} WM_KEYDOWN Dispatched 44h 68d VK_D Scan 20h Repeat</PRE><P>Most of the time I opt to see more detail, so I generally leave the InterpretValues option on.</P><P>The Hex Values option tells WinSight to display the values in the Message Tracewindow in hexadecimal format. This is useful in some situations but probably notuntil you've been programming for a while. The Show Times option is of limited usebecause it shows a system time that isn't generally meaningful.</P><P>The Log file option enables you to send the message trace output to a file ondisk. When this option is on, the messages are still displayed in the Message TraceWindow. This option is useful when you need a hard copy of the messages being generated.</P><BLOCKQUOTE> <P><HR><strong>TIP:</strong> Creating a log file has another advantage. After you create a log file and load it into a text editor, you can use the text editor's Find function to search for specific messages or message parameters you want to review.<HR><B></B></P></BLOCKQUOTE><P><H3><A NAME="Heading16"></A>Other WinSight Features</H3><P>WinSight has other features that make finding and examining windows easier.</P><P><H4>Viewing Window Details</H4><P>The Detail feature of WinSight shows you all the pertinent details of a particularwindow. To view a window's details, select the window in the Window Tree and thenchoose Spy|Open Detail from the main menu. You can also double-click the window inthe Message Tree or press Enter on the keyboard. Figure 11.10 shows the details ofWindows Explorer.</P><P><BR><A HREF="javascript:popUp('28671110.gif')"><B>FIGURE 11.10.</B></A> <I>The WinSightDetail window.</I></P><P><BR>As you can see, the Detail window shows you a great deal about the window you areexamining (probably more than you want to know!).</P><P><H4>Follow Focus</H4><P>This option enables you to select a window in an application and have that windowbecome the active window in the Window Tree. The Window Tree usually contains dozensof windows. It is often difficult to find the window you are looking for, so theFollow Focus feature really comes in handy.</P><P>To use this feature, choose Spy|Follow Focus from the main menu. Next, switchto the application that contains the window for which you want to view messages and,if needed, click the specific control within that window that you want to spy on.WinSight automatically selects the window in the Window Tree. To begin spying onthe window, choose Start! from the main menu.</P><BLOCKQUOTE> <P><HR><strong>TIP:</strong> The Follow Focus option stays on until you turn it off. Unless you want to view other windows or controls in your application, you should turn off Follow Focus as soon as you locate the window you want to spy on.<HR></BLOCKQUOTE><H4>Find Window</H4><P>The Find Window feature of WinSight is the opposite of Follow Focus: In the WindowTree, you locate the window you're searching for and then choose Spy|Find Windowfrom the main menu. WinSight will place a thick frame around the window and willflash the frame.</P><P>The frame stays around the window until you click the window or choose anotherwindow from the Window Tree. The thick frame is drawn on top of all windows so thatyou can find a window even if it's hidden under other windows. A window located withFind Window doesn't come to the top or gain input focus; it is merely identifiedfor you.</P><BLOCKQUOTE> <P><HR><strong>NOTE:</strong> Find Window cannot find hidden windows or windows that are minimized.<HR></BLOCKQUOTE><P>The Find Window mode shuts off as soon as focus leaves the Window Tree. If youclick on another application or anywhere else in WinSight, the Find Window mode willturn off.</P><P><H4>Switch To</H4><P>The Switch To feature enables you to switch to a particular window in an application.To switch to a window, just find the window in the Window Tree and then choose Spy|SwitchTo from the main menu. The window will come to the top and will have input focus.If the window is minimized, it will be restored to its previous location. SwitchTo has no effect on hidden windows.</P><P>It will take time working with WinSight before you understand each message andits significance. In time, though, you will pick it up.</P><P><H2><A NAME="Heading17"></A>TDUMP</H2><P>TDUMP is a command-line program that outputs the structure of an .exe or .dll(and other file types as well). By default, the output from TDUMP goes to the console,but it can be redirected to a text file that you can later examine to obtain informationabout the program. TDUMP will tell you about the structure of the file, what DLLsthe program uses, what functions in those DLLs the program calls, and other information.For example, here is part of the file dump results on a program produced by Delphi:</P><P><PRE>Portable Executable (PE) FileHeader base: 00000200CPU type 80386Flags 818E [ executable 32bit ]DLL flags 0000 [ ]Linker Version 2.19Time stamp 00000000O/S Version 1.0User Version 0.0Subsystem Version 4.0Subsystem 0002 [ Windows GUI ]Object count 00000008Symbols offset 00000000Symbols count 00000000Optional header size 00E0Magic # 10BCode size 0003C000Init Data size 00009000Uninit Data size 00001000...(other information)... Imports from OLEAUT32.dll SysAllocStringLen SysStringLen VariantChangeTypeEx VariantClear VariantCopyIndImports from MPR.dll WNetGetConnectionAImports from USER32.dll
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -