I have located my program from the processes
targetHandle = targetProcess.MainWindowHandle;
I now can get the Handle's hex which I use in spy++ (just preference)
hex = targetHandle.ToString("X");
I convert it to an integer
win = (int)targetHandle;
Now I want to use the handle info to retrieve general information as I would get with spy++.
Thanks.
What I have tried:
I tried the following...
string str = "";
int txtLength =
SendMessage(handle_get, WndMsg.WM_GETTEXTLENGTH, 0, 0);
StringBuilder sbText = new StringBuilder(txtLength + 1);
SendMessage(
handle_get, WndMsg.WM_GETTEXT, sbText.Capacity, sbText);
handle_Title[iIndex] = sbText.ToString();
Console.WriteLine("caption : " + handle_Title[iIndex]);
titleArrayList.Add(handle_Title[iIndex].ToString());
StringBuilder sb = new StringBuilder(256);
GetClassName(win, sb, sb.Capacity + 1);
handle_Classname[iIndex] = sb.ToString();
Console.WriteLine("classname : " + handle_Classname[iIndex]);
classnameArrayList.Add(handle_Classname[iIndex].ToString());
GetClientRect(handle_get, out handle_getRect);
if (IsRectEmpty(ref handle_getRect))
{
str = "\t\tRectangle : ";
}
else { Console.WriteLine("Handle has a rectangle"); }
if (GetClientRect(
handle_get, out handle_getRect))
{
Console.WriteLine("Rectangle exists");
handle_Rect[iIndex] = handle_getRect;
#region Convert Coordinates
pointTL = new Point(
handle_Rect[iIndex].Locaation.X,
handle_Rect[iIndex].Locaation.Y);
ClientToScreen(handle_get, ref pointTL);
Console.WriteLine("point top left = " + pointTL);
pointBR = new Point(
handle_Rect[iIndex].Locaation.X +
handle_Rect[iIndex].Right,
handle_Rect[iIndex].Locaation.Y +
handle_Rect[iIndex].Bottom);
ClientToScreen(handle_get, ref pointBR);
Console.WriteLine("point bottom right = " + pointBR);
handle_Rect[iIndex].Left += pointTL.X;
handle_Rect[iIndex].Right = pointBR.X;
handle_Rect[iIndex].Top += pointTL.Y;
handle_Rect[iIndex].Bottom = pointBR.Y;
handle_Rect[iIndex].Width += pointBR.X - pointTL.X;
handle_Rect[iIndex].Height += pointBR.Y - pointTL.Y;
handle_Rect[iIndex].Size = new Size(
handle_Rect[iIndex].Width, handle_Rect[iIndex].Height);
handle_Rect[iIndex].Locaation = new Point(
handle_Rect[iIndex].Left, handle_Rect[iIndex].Top);
str =
"\t\tRectangle : (" + handle_Rect[iIndex].Left +
", " + handle_Rect[iIndex].Top +
")-(" + handle_Rect[iIndex].Right +
", " + handle_Rect[iIndex].Bottom +
") " + handle_Rect[iIndex].Size.Width +
"x" + handle_Rect[iIndex].Size.Height +
"\tWidth " + handle_Rect[iIndex].Width +
"\tHeight " + handle_Rect[iIndex].Height +
"\tLocation - " + handle_Rect[iIndex].Locaation +
"\tSize - " + handle_Rect[iIndex].Size;
Console.WriteLine(str);
#endregion
#region Add to array list
rectangleArrayList.Add(handle_Rect[iIndex].Left);
rectangleArrayList.Add(handle_Rect[iIndex].Right);
rectangleArrayList.Add(handle_Rect[iIndex].Top);
rectangleArrayList.Add(handle_Rect[iIndex].Bottom);
rectangleArrayList.Add(handle_Rect[iIndex].Width);
rectangleArrayList.Add(handle_Rect[iIndex].Height);
rectangleArrayList.Add(handle_Rect[iIndex].Size);
rectangleArrayList.Add(handle_Rect[iIndex].Locaation);
#endregion
}
However, I dont get the Title, nor the Rectangle.
Spy++ shows that there is a title (caption) and rectangle.
So I must have done something wrong.