Microsoft KB Archive/90370

= Microsoft Knowledge Base =

Edit Control Caret May Cause TESTSCRN Comparison to Fail
Last reviewed: October 19, 1994

Article ID: Q90370

The information in this article applies to:


 * Microsoft Test for Windows, versions 1.0 and 2.0

SUMMARY
If the focus is on an active edit box when you capture or compare a screen image (using the Test Screens program or TESTSCRN.DLL routines), the comparison may fail with a return code of ERR_SCR_IMAGEDIFF (error code 317) even though the two images appear identical. The failure is often caused by the presence of the &quot;caret&quot; (the vertical bar used to indicate the current position in the text edit control) in one screen image and not the other.

To avoid this problem, you can either:

 Explicitly change the focus to another control before performing the screen capture or comparison. This can be done by sending a tab key or mouse click to your application. -or- Use the Windows API routine SendMessage to send messages to your edit control that force the caret &quot;off&quot; before you perform your screen captures and comparisons and &quot;on&quot; again after the screen capture/compare. An example of this method is provided further below.

MORE INFORMATION
Screen comparisons performed with the Test Screens program and with the following functions may be affected by the presence of a caret in an edit box control:

FCompFiles FCompScreen FCompScreenActivate FCompWindowActivate

Workaround
The following example demonstrates using the Windows API routine SendMessage to control the visibility of the caret in an edit box control. The routines provided below can be used in any situation where you want to prevent the visibility of the caret from affecting screen comparisons.

'$Define TESTSCRN '$Include 'MSTEST.INC'

' WINUSER.INC contains declarations for SendMessage, WM_KILLFOCUS, ' and WM_SETFOCUS. '$Include 'WINUSER.INC' DECLARE FUNCTION FHideCaret% DECLARE SUB FShowCaret (hwnd%)

' Start Notepad. The focus will be in the main edit window and ' a caret should be present. RUN &quot;NOTEPAD.EXE&quot;, NOWAIT

' Hide caret, capture base line image, and restore caret. hwnd% = FHideCaret bool% = FDumpWindow(&quot;XTEST.SCN&quot;,0,0,0,FALSE) FShowCaret hwnd%

IF bool% THEN

PAUSE &quot;Error saving base line image:&quot; + STR$(bool%) ELSE

' Hide caret, compare window, and restore caret. hwnd% = FHideCaret bool% = FCompWindow(&quot;XTEST.SCN&quot;, 0, 1, FALSE, TRUE) FShowCaret hwnd%

IF bool% THEN PAUSE &quot;Error comparing window:&quot; + STR$(bool%) ELSE PAUSE &quot;Successful comparison&quot; END IF END IF

' Remove screen file. KILL &quot;XTEST.SCN&quot;

END

'*************************************************************** ' FHideCaret hides the caret in an edit control using the ' WM_KILLFOCUS message to remove the focus from the active ' control. FHideCaret returns the window handle (hwnd) of ' the control that had the focus so that it can be restored ' later. FShowCaret should be used after FHideCaret so that ' the focus is properly restored. '*************************************************************** FUNCTION FHideCaret% STATIC

hWnd% = GetFocus ret% = SendMessage(hWnd%,WM_KILLFOCUS,0,NULL) FHideCaret = hWnd% END FUNCTION

'*************************************************************** ' FShowCaret restores the focus to the control specified by the ' hwnd% parameter by sending it a WM_SETFOCUS message. '*************************************************************** SUB FShowCaret (hWnd%) STATIC

ret% = SendMessage(hWnd%,WM_SETFOCUS,0,NULL) END SUB

Reference(s):

&quot;Microsoft Windows Programmer's Reference,&quot; Microsoft Press, 1990