I’m trying to programatically change the text of an edit control in a ‘Save As’ Dialog. The first part was easy – getting the “Save As” window’s handle. But finding the edit control’s? Not so easy.
Anyway, this is the code I’ve go to so far. Can someone tell me where I’m going wrong?
[DllImport("user32.dll")]
public static extern Int32 SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, String lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
IntPtr dialog = FindWindow(null, "Save As");
if (dialog.ToInt32() != 0)
{
IntPtr edit = FindWindowEx(dialog, IntPtr.Zero, "Edit", "");
SendMessage(edit, 0x000C /* WM_SETTEXT */, IntPtr.Zero, "...");
}
Thanks in advance!
I ended up using the functionality provided by the Autoit DLL, for it’s simplicity and efficiency.
But an alternative solution (and native C#) is Md. Rashim Uddin’s.