The first part is C:
Call:
System. Collections. Queue q = new Queue ();
Q. Enqueue (new QueueItem ("ThunderRT6FormDC", "Spy ++ Lite V2.1 "));
Q. Enqueue (new QueueItem ("SSTabCtlWndClass ",""));
Q. Enqueue (new QueueItem ("ThunderRT6CommandButton", "Save (& S )"));
Int I = NativeWin32.ClickOnWindow (q );
MessageBox. Show (I. ToString ());
The Tab page is found step by step from the form. When the button is selected, the click is triggered.
The final return value I will reflect the level of successfully searched.
PINVOKE encapsulation: using System;
Using System. Runtime. InteropServices;
Namespace RemoteCam
{
Public class QueueItem
{
Public string ClassName;
Public string WindowCaption;
Public bool IsParent = true;
Public QueueItem (string className, string windowCaption)
{
ClassName = className;
WindowCaption = windowCaption;
}
Public QueueItem (string className, string windowCaption, bool isParent)
{
ClassName = className;
WindowCaption = windowCaption;
IsParent = isParent;
}
}
Public class NativeWin32
{
// Get Text/Set Text/Click
Public const int WM_GETTEXT = 0x000D;
Public const int WM_SETTEXT = 0x000C;
Public const int WM_CLICK = 0x00F5;
Public const int SW_MAXIMIZE = 0x0003;
Public const int SW_SHOWNORMAL = 0x0001;
[DllImport ("User32.dll", EntryPoint = "FindWindow")]
Public static extern IntPtr FindWindow (string lpClassName, string lpWindowName );
[DllImport ("user32.dll", EntryPoint = "find1_wex")]
Public static extern IntPtr find1_wex (IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow );
[DllImport ("User32.dll", EntryPoint = "SendMessage")]
Public static extern int SendMessage (IntPtr hwnd, int Msg, IntPtr wParam, string lParam );
[DllImport ("user32.dll", EntryPoint = "SetForegroundWindow")]
Public static extern void SetForegroundWindow (IntPtr hwnd );
[DllImport ("user32.dll", EntryPoint = "ShowWindow")]
Public static extern void ShowWindow (IntPtr hwnd, int size );
Public static int ClickOnWindow (System. Collections. Queue queue)
{
Int result =-1;
IntPtr ParenthWnd = new IntPtr (0 );
IntPtr ChildhWnd = new IntPtr (0 );
QueueItem q = (QueueItem) queue. Dequeue ();
// Check the form to obtain the entire form
ParenthWnd = FindWindow (q. ClassName, q. WindowCaption );
// Determine whether the form is valid
If (! ParenthWnd. Equals (IntPtr. Zero ))
{
ShowWindow (ParenthWnd, SW_SHOWNORMAL );
SetForegroundWindow (ParenthWnd); // activate the form
Result ++;
While (queue. Count> 0)
{
Q = (QueueItem) queue. Dequeue ();
ChildhWnd = find1_wex (ParenthWnd, (IntPtr) 0, q. ClassName, q. WindowCaption );
If (! ChildhWnd. Equals (IntPtr. Zero ))
{
If (q. IsParent)
ParenthWnd = ChildhWnd;
Result ++;
} Else
Break;
}
// Get the Button? Click Event
If (! ChildhWnd. Equals (IntPtr. Zero) & queue. Count = 0)
{
SendMessage (ChildhWnd, WM_CLICK, (IntPtr) 0, "0 ");
}
}
Return result;
}
}
}