Microsoft Knowledge Base

How to Use ScnCaptureWindow & ScnCompFile in Microsoft Test

Last reviewed: July 25, 1996
Article ID: Q136081
The information in this article applies to:
  • Visual Test for Windows 95, version 4.0
  • Visual Test for Windows NT, version 4.0

SUMMARY

It is often useful when testing to compare and contrast a window's visual appearance (bitmap) at various stages of a product's development. TestBasic offers a family of functions prefixed with Scn that provide the functionality necessary for such a test. The functions ScnCaptureWindow and ScnCompFile are demonstrated in this article. More information on Scn* functions and statements is available through the Help menu.

MORE INFORMATION

While testing a window's appearance, you need to determine if the window has been altered by development, operating system variables, or logic errors in the construction of the test code.

This article will:

  • Identify operating system variables that affect a window's bitmap image.
  • Demonstrate a technique useful in minimizing the chance of the test code affecting a window's appearance thereby allowing a tester to quickly determine when a window's appearance has been altered by development.

Why a Window's Appearance May Vary

The following is a list of variables that will alter a window's appearance that are not development related.

Most windows contain child windows and/or controls. Most child windows or controls indicate to a user that they have input focus by altering their appearance. For example: a command button draws a dotted rectangle around its caption, a child window's borders take on the active window border color.

An MDI parent window alters its title bar content (caption) depending on whether or not a child window is maximized.

A change in video resolution will cause a window to look different.

How to Minimize the Chance of Varying Window Appearance

The sample function CaptureCompWindow demonstrates a technique that minimizes the chance of non-development related variables affecting a window's appearance. Copy the following code into a new window and save it as UsefulTools.inc:

   Declare Function CaptureCompWindow _
      (fCapture As Integer, strFileName As String, _
      strImageName As String, hwnd As Long, fHide As Integer, _
      fCheckLoc As Integer) As Integer

   Function CaptureCompWindow _
      (fCapture As Integer, strFileName As String, _
      strImageName As String, hwnd As Long, fHide As Integer, _
      fCheckLoc As Integer) As Integer

      Dim strImageNameOrg As String

      ' The image name is suffixed with '[Original]' for ease of
      identification,
      ' and will be used in later comparisons.
      strImageNameOrg = strImageName + " [Original]"

      If fCapture Then
         ' This logical flow is followed only when making an original or
         ' over-writing the original.
         ScnCaptureWindow( strFileName, strImageNameOrg, hwnd, fHide )

      Else
         ' The image name is suffixed with a date/time stamp for ease of
         ' identifying the new image and documenting when the image was
         ' created.
         Dim strImageNameNew As String

         strImageNameNew = strImageName + " [" + DateTime$ + "]"

         ' The new image is saved to the same file,
         ' but uses the new image name.
         ScnCaptureWindow( strFileName, strImageNameNew, hwnd, fHide )

         ' The comparison is performed on the original and
         ' new images from the file.
         ' This allows the tester to view what made the images vary at a
         ' later time using 'Screen Utility.'
         If ScnCompFiles( strFileName, strImageNameOrg, strFileName, _
            strImageNameNew, fCheckLoc ) Then

            ' The images vary--report it to the ViewPort.
            Print "CaptureCompWindow Error: '" + strImageNameNew + _
               "' varies from original."

            ' Return False
            CaptureCompWindow = False
            Exit Function
         End If
      End If

      ' Everything went fine return True.
      CaptureCompWindow = True
   End Function

What CaptureCompWindow Does

The CaptureCompWindow function benefits a tester by allowing a capture or comparison to be performed at the same point in a TestBasic script. This minimizes the chance that the window being tested varies in state at the time of capture and the time of comparison. CaptureCompWindow documents, to the ViewPort, an unsuccessful comparison of the new image to the original image. Also, CaptureCompWindow saves the original and new image to the same screen file for later viewing.

Step-by-Step Sample Using CaptureCompWindow

This procedure makes use of the Visual Test tool called Screen Utility. Books Online documents the Screen Utility under "Visual Test Utilities User's Guide."

  1. Copy the following code into a new window:

       '$Include 'Declares'
       '$Include 'UsefulTools'
       Dim g_fCapture As Integer
    
       g_fCapture = True
       hwndWordPad& = WFndWnd( "ReadVT4", FW_PART or FW_FOCUS )
       Print CaptureCompWindow( g_fCapture, "c:\TestSCN.scn", _
          "ReadVT4 - WordPad", hwndWordPad, False, False )
    
    

  2. Run WordPad if running on Windows 95 or Write if running on Windows NT and load the ReadVT4.wri document found in the \MSDEV\VT4Setup directory.

  3. Run the sample code. This code creates a screen file in the root directory of the C: drive called TestSCN.scn.

  4. On the Visual Test Menu, click Test.Screen Utility... and open the TestSCN file. Notice that there is currently one image in the file. Keep Screen Utility running, you'll use it again.

  5. Alter this line of sample code:

          g_fCapture = True
    

    to this:

          g_fCapture = False
    

  6. Run the sample code. This will add an image to the TestSCN file. Make the Screen Utility active. It will have a message box indicating that the files contents have changed. Click OK to load the changed file. There are now two image files. Compare the images, they should be identical. For more information on comparing file images, refer to "Contents.Comparing Screen Images.Comparing Screen Images" in the Help menu on the Screen Utility application.

  7. Modify the ReadVT4 file by changing the first word from README to EADME.

  8. Run the sample code. This time an error message will be printed to the viewport. It will read "CaptureCompWindow Error: 'ReadVT4 - WordPad [8/25/95 3:33:35 PM]' varies from original." Your date and time will vary.

  9. Use Screen Utility to compare the new image to the original. This time

        they will not be identical.
    


Additional reference words: 4.00 Win32
KBCategory: kbprg kbwebcontent
KBSubCategory:


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 25, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.