Forum Discussion
Hello Ashish,
Please specify whether your tested application is recognized as Open by TestComplete, and with what programming language and IDE it was developed. The cursor state may be obtained via native properties of the application's objects. To learn how to determine whether your application is Open, please see the Open Applications - Overview Help topic.
I tried with code of ...
var pid = Win32API.GetWindowThreadProcessId(TargetWindow.Handle, null); var tid = Win32API.GetCurrentThreadId(); Win32API.AttachThreadInput(pid, tid, true); var crsr = Win32API.GetCursor(); But each time crsr gives different value, for different machines with same XP.
Does GetCursor return different values only for cursors in your tested application or for all cursors including Windows native cursors?
Also, please note that to get the cursor state, you can try using the following workaround:
1. Create a Regions collection in your project and add images of all cursors used in your application to the collection. Make sure that those images have a solid background. For more information on the Regions collection and on how to add images to it, please see the About Regions Collection and Adding Images to the Regions Collection Help topics.
2. Get a screenshot of the cursor whose state you want to check using the PictureUnderMouse property or the Picture method.
3. Iterate through the cursor images stored in the Regions collection and compare each of them (excluding their background by enabling the Transparency mode) with the screenshot. To compare images, you can use the Regions.Compare, Regions.Find, Regions.FindRegion and Region.Check methods. All these methods have the Transparent parameter. When this parameter is set to true, TestComplete treats the color of the baseline image's top-left pixel as transparent and excludes all pixels that have the same color from the comparison. For more information on the transparency mode, please see the "Transparent" Color section in the How Image Comparison Works Help topic.
For example, the following code obtains a cursor screenshot, iterates through the Regions collection and uses the Regions.Find method to check whether the screenshot contains the cursor image stored by the current collection item. If it finds a match, it posts the name of the item to the test log:
function GetCursor()
{
// Obtains the image of the mouse cursor
X = Sys.Desktop.MouseX;
Y = Sys.Desktop.MouseY;
var pic = Sys.Desktop.Picture(X-10, Y-10, 40, 40);
// Iterates through the Regions collection
count = Regions.Count();
for (var i = 0; i < count; i++)
{
// Searches for the image stored by the current collection item within the obtained image
// The Transparent parameter is set to true
if (Regions.Find(pic, Regions.GetPicture(i), 0 , 0, true) != null)
{
Log.Message(Regions.NameByIndex(i));
break;
}
}
}
Please let us know whether this information is useful and whether you have any additional questions.
Thank you.
Related Content
- 10 years agoshrey1686
- 9 years agotwhitehouse
Recent Discussions
- 2 hours agoMW_Didata