i want to clicked the save button of another application from my c# application.if there is data in that application then save dialogbox will appear while in absence of data message box will appear.After i want to give the filename as date and time similarly i want to click the ok button for messagebox.
i did it using 3 button save,enter filename button and ok button but the problem is when i clicked the save button window is changed to either save dialogbox or message box after that my c# application freezed. if i restart c# application it will work.how to solve this?
if possible i want to do it using single button.
What I have tried:
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]static public extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
[DllImport("user32.dll")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern int SendNotifyMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern int SetForegroundWindow(IntPtr points);
[DllImport("user32.dll")]
private static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private void saveBtn_Click(object sender, EventArgs e)
{
IntPtr maindHwnd = FindWindow(null, "app1");
IntPtr maindHwnd1 = FindWindow(null, "Error");
if (maindHwnd != IntPtr.Zero)
{
IntPtr panel = FindWindowEx(maindHwnd, IntPtr.Zero, "MDIClient", null);
IntPtr panel1 = FindWindowEx(panel, IntPtr.Zero, "TAveForm", null);
IntPtr panel2 = FindWindowEx(panel1, IntPtr.Zero, "TPanel", "Panel5");
IntPtr panel3 = FindWindowEx(panel2, IntPtr.Zero, "TPanel", null);
IntPtr childHwnd = FindWindowEx(panel3, IntPtr.Zero, "TBitBtn", "Save");
if (childHwnd != IntPtr.Zero)
{
SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
}
}
private void button4_Click(object sender, EventArgs e)
{
IntPtr hWnd = FindWindow(null, "Error");
if (hWnd != IntPtr.Zero)
{
IntPtr childHwnd = FindWindowEx(hWnd, IntPtr.Zero, "Button", "Ok");
if (childHwnd != IntPtr.Zero)
{
SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
else
{
textBox3.BackColor = Color.Yellow;
textBox3.Text = "error;
}
}
else
{
textBox3.BackColor = Color.Yellow;
textBox3.Text = "hmd is zero";
}
}
String textBox = DateTime.Now.ToString("yyyyMMdd_HH-mm-ss");
IntPtr maindHwnd = FindWindow(null, "save");
IntPtr hWnd = FindWindow(null, "Error");
if (maindHwnd != IntPtr.Zero)
{
{
IntPtr panel = FindWindowEx(maindHwnd, IntPtr.Zero, "ComboBoxEx32", null);
IntPtr panel1 = FindWindowEx(panel, IntPtr.Zero, "ComboBox", null);
IntPtr panel2 = FindWindowEx(panel1, IntPtr.Zero, "Edit", null);
if (panel2 != IntPtr.Zero)
{
SendKeys.Send(textBox);
}
}