Forum Discussion

bxk81's avatar
bxk81
New Contributor
11 years ago

Is there any way to capture a screenshot with control highlighted with red box?

Hello,



I am currently developing an automation software using TC scripts.



Is there anyway to capture a screenshot with control name highlighted with red box? (something like below)







Thank you!

2 Replies

  • gid_216's avatar
    gid_216
    Frequent Contributor
    Hi,



    if test visualizer is enabled to capture screnshots during playback, it will automatically capture the screenshots with controls highlighted.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Beom,



    Long time ago the following code was posted by Support. Hope it will help.

    ================================

    If you know the coordinates, where the rectangle should be drawn, you can draw a rectangle on the screen and save the screen to Log. Here is an example:


     [DelphiScript]



     const

       LineWidth = 3;



     procedure DrawAndSave(Left, Top, Width, Height);

     var hdcScreen, hPen1, hOldPen1, hBrush1, hOldBrush1;

     begin

       hdcScreen := CreateDC('DISPLAY', nil, nil, nil);

       hPen1 := CreatePen(PS_SOLID, 1, clRed);

       hOldPen1 := SelectObject(hdcScreen, hPen1);

       hBrush1 := CreateSolidBrush(clRed);

       hOldBrush1 := SelectObject(hdcScreen, hBrush1);



       Rectangle(hdcScreen, Left - LineWidth,

         Top, Left + Width + LineWidth, Top - LineWidth);

       Rectangle(hdcScreen, Left + Width,

         Top - LineWidth, Left + Width + LineWidth, Top + Height + LineWidth);

       Rectangle(hdcScreen, Left + Width + LineWidth, Top + Height,

         Left, Top + Height + LineWidth);

       Rectangle(hdcScreen, Left, Top + Height + LineWidth,

         Left - LineWidth, Top - LineWidth);

       Log.Picture(Sys.Screen, 'Picture');



       SelectObject(hdcScreen, hOldPen1);

       DeleteObject(hPen1);

       SelectObject(hdcScreen, hOldBrush1);

       DeleteObject(hBrush1);

       DeleteDC(hdcScreen);

     end;



     procedure RefreshScreen;

     var

       TUser32, User32: OleVariant;

     begin

       TUser32 := DLL.DefineDLL('user32');

       TUser32.DefineProc('InvalidateRect', vt_int, vt_int, vt_int, vt_bool);

       User32 := DLL.Load('user32');

       User32.InvalidateRect(0,0,0);

     end;



     procedure Main;

     var p, w, obj: OleVariant;

         x, y: OleVariant;

     begin

       p := Sys.Process('notepad');

       w := p.Window('Notepad', '*');

       w.Activate;

       obj := w.Window('Edit');



       x := obj.Left;

       y := obj.Top;

       w.ClientToScreen(x, y);



       DrawAndSave(x, y, obj.Width, obj.Height);

       RefreshScreen();

     end;



     For more information on the Win32API functions, please see Win32API Plug-In help topic and the corresponding samples.

     Bobby Edgar

     AutomatedQA

     ================================