Share via


Watch Window

Home Page (Debugger)OverviewHow Do I... Topics

Use the Watch window to specify variables and expressions that you want to watch while debugging your program. You can also modify the value of a variable using the Watch window.

The Watch window contains four tabs: Watch1, Watch2, Watch3, and Watch4 — Each tab displays a user-specified list of variables and expressions in a spreadsheet field. You can group variables that you want to watch together onto the same tab. For example, you could put variables related to a specific window on one tab and variables related to a dialog box on another tab. You could watch the first tab when debugging the window and the second tab when debugging the dialog box.

If you add an array, object, or structure variable to the Watch window, plus sign (+) or minus sign (–) boxes appear in the Name column. You can use these boxes to expand or collapse your view of the variable, as described in Spreadsheet Fields.

If the value of a variable appears in red, it indicates that the value has recently changed. Only the last value to change appears in red.

If the variable is an object, reference or a C++ pointer to an object, the Watch window automatically expands the variable to show the most important data at the top level. For example, suppose you had the following C++ object:

CString String  =   {...}
char *   m_pchData =0x7ffdf000 "abc"
   int          m_nDataLength=4
   int          m_nAllocLength=1244628

The Watch window displays the following:

String  =   {"abc"}

If the variable is a reference or a C++ pointer to an object, the Watch window automatically downcasts the reference or pointer. The Watch window adds an extra member to the expanded object. This extra member, which looks like another base class, indicates the derived subclass. For example, if a variable declared as a C++ pointer to CObject really points to a CComboBox, the Watch window recognizes this fact and adds an extra member so that you can access the CComboBox members.

The Watch window displays values in their default format. You can change the display format (to display Unicode characters, for example) using formatting symbols. For details, see Symbols for Watch Variables.

Tip   The Watch window does not display variable type information. You can view information for a variable type by using the window’s property page.

What do you want to do?

View the value of a variable

Modify the value of a variable