S
SQACSharp
I'm trying to get the control name of an editbox in another window.
The following code set the value "MyPassword" in the password EditBox
but it fail to return the control name of the EditBox. I'm sure the
problem is the way i'm using the sendmessage API, the return string and
the lParam return 0....is anybody have a clue? any sendmessage api
expert here?
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName,String
lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam,
IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);
[DllImport("user32.dll")]
public static extern UInt32
RegisterWindowMessage([MarshalAs(UnmanagedType.LPTStr)] String
lpString);
// ....
int hwnd = 0;
IntPtr hwndChild = IntPtr.Zero;
hwnd = FindWindow(null, "Login");
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "TEdit", "");
SetControlText((int)hwndChild, WM_SETTEXT, 0, "MyPassword");
//the following is not working as expected to get the control name
uint SendMsg;
SendMsg = RegisterWindowMessage("WM_GETCONTROLNAME");
long ReturnMsg;
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
Marshal.WriteIntPtr(ptr, IntPtr.Zero);
ReturnMsg=SendMessage((int)hwndChild, (int)SendMsg, 65536, ptr);
IntPtr CtrlName = Marshal.ReadIntPtr(ptr);
MessageBox.Show(CtrlName.ToString());
MessageBox.Show(ReturnMsg.ToString());
Marshal.FreeCoTaskMem(ptr);
The following code set the value "MyPassword" in the password EditBox
but it fail to return the control name of the EditBox. I'm sure the
problem is the way i'm using the sendmessage API, the return string and
the lParam return 0....is anybody have a clue? any sendmessage api
expert here?
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName,String
lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam,
IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);
[DllImport("user32.dll")]
public static extern UInt32
RegisterWindowMessage([MarshalAs(UnmanagedType.LPTStr)] String
lpString);
// ....
int hwnd = 0;
IntPtr hwndChild = IntPtr.Zero;
hwnd = FindWindow(null, "Login");
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "TEdit", "");
SetControlText((int)hwndChild, WM_SETTEXT, 0, "MyPassword");
//the following is not working as expected to get the control name
uint SendMsg;
SendMsg = RegisterWindowMessage("WM_GETCONTROLNAME");
long ReturnMsg;
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
Marshal.WriteIntPtr(ptr, IntPtr.Zero);
ReturnMsg=SendMessage((int)hwndChild, (int)SendMsg, 65536, ptr);
IntPtr CtrlName = Marshal.ReadIntPtr(ptr);
MessageBox.Show(CtrlName.ToString());
MessageBox.Show(ReturnMsg.ToString());
Marshal.FreeCoTaskMem(ptr);