For me, the problem is that the MSPaintApp window needs to be searched with FindWindow("MSPaintApp", null) , because MSPaintApp is the name of the class, not the window title.
Then Afx:00007FF765740000:8 not a child of MSPaintApp , but is a child of MSPaintView , which is a child of MSPaintApp .
Also you do not need to "simulate" BM_CLICK, but you must simulate WM_LBUTTONDOWN and then WM_LBUTTONUP
Please consider this example which seems to work (on Windows 7)
class Program { private const uint WM_LBUTTONDOWN = 0x201; private const uint WM_LBUTTONUP = 0x202; private const uint MK_LBUTTON = 0x0001; public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr parameter); [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); [DllImport("user32.dll", SetLastError = true)] public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); static IntPtr childWindow; static void Main(string[] args) { IntPtr hwndMain = FindWindow("MSPaintApp", null); IntPtr hwndView = FindWindowEx(hwndMain, IntPtr.Zero, "MSPaintView", null);
source share