So far, I have written the following code:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr IParam);
private const int BM_CLICK = 0x00F5;
// ...
IntPtr win = FindWindow("CalcFrame", "Calculator");
if (!win.Equals(IntPtr.Zero))
{
IntPtr win2 = FindWindowEx(win, IntPtr.Zero, "CalcFrame", null);
if (!win2.Equals(IntPtr.Zero))
{
MessageBox.Show("ok");
}
}
And my question is, how can I send BM_CLICK
to the Calculator's buttons.
I don't get it, how do I choose windows and buttons with the same class?
Can you explain to me how to do this, and maybe write some examples?
If there is two (or more) windows that have same class name and text, it's better to use EnumChildWindows API function. Since you are using C#, here is an example for this API function.
You can list all child windows and do whatever you want with them.