First of all, have in mind that Im a beginner.
With that said, Im trying to press a button in an external application with user32.dll. I have tried a lot of solutions but cant find anything that works.
I am using 3 DllImport because I want to bring the window to the front aswell (This works fine)
It looks like this:
[DllImportAttribute("User32.dll")]
private static extern int FindWindow(String ClassName, String
WindowName);
[DllImportAttribute("User32.dll")]
private static extern IntPtr SetForegroundWindow(int fgr);
[DllImport("user32.dll")]
static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, int
lParam);
const int BN_CLICKED = 245;
When I click a button, it will bring the application to the front, like this:
private void button1_Click(object sender, EventArgs e)
{
int fgr = FindWindow("TAssistMainFrm", null);
if (fgr > 0) //If found
{
MessageBox.Show("Window found!");
SetForegroundWindow(fgr);
}
else //Not Found
{
MessageBox.Show("Window Not Found!");
}
}
As I said, this works absolutly fine! Heres the problem. I want to press a button with ClassNN TButton10
I have tried:
SendMessage(TButton10, BN_CLICKED, 0, 0);
And a lot of other things, but Im guessing that I need to find TButton10 and declare it first. How should I do that?
Anyone that can help me out with code that works, and an explanation of the code? Thanks a lot!