A
A
andrejfomenko2017-10-13 04:09:46
Automation
andrejfomenko, 2017-10-13 04:09:46

How to click on a button in c++ program?

Hello, I have a program with source code in c++. There are 3 buttons in the program, how do I make a click on them in c# or autoit. The problem is that I used Microsoft Spy++, Windows hack 3.0, autoit Info to identify the element(s). But none of the programs sees the buttons, there is only the handle of the program window. For example, to click on the "Open" button in another program, I used the following C# code:

[DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        //подключаем поиск окна
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string windowName);
        //подключаем SendMessage
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
        const int WM_LBUTTONDOWN = 0x0201;
        const int WM_LBUTTONUP = 0x0202;
        const int Enter = 13;
        const int Tab = 9;
        const int WM_CLOSE = 0x10;
        const int WM_ACTIVATE = 0x1C;
        const int WM_DESTROY = 0x2;
        [DllImport("User32.dll")]
        private static extern int SendMessage(IntPtr HWND, int Msg, int wParam, StringBuilder lParam);
        const int WM_GETTEXT = 0xD;
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, string lParam);
        const int WM_SETTEXT = 0x000C;
IntPtr button1 = FindWindowEx(calcWnd, IntPtr.Zero, "Button", "Открыть");
SendMessage(button1, WM_LBUTTONDOWN, 1, 0x150018);
SendMessage(button1, WM_LBUTTONUP, 0, 0x150018);

so how do i find the element? or mb there are other implementation options?
PS the program is not mine, I wanted to rebuild it by changing the button labels, but errors fly out (maybe not everything is fully installed in VS 2017)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Reshetnikov, 2017-10-19
@beevasya

As I understand it, you are looking for a button window and then you send pressing and releasing the button.
And try to immediately send BN_CLICKED to the parent window.
Because buttons are usually processed in the parent window (dialog)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question