SendMessage を使用して、単純なマウス ダウン/アップ メッセージを Windows Calculator に送信しようとしています。メッセージをボタンに直接送信することで、ボタンを押すことができました。しかし、同じメッセージをメインの電卓ウィンドウ ハンドルに送信できませんでした。hWnd が電卓のウィンドウ ハンドルであることを考えると、これが私のコードです。
IntPtr fiveKey = FindWindowEx(hWnd, IntPtr.Zero, "Button", "5");
int x = 5; // X coordinate of the click
int y = 5; // Y coordinate of the click
IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
const uint downCode = 0x201; // Left click down code
const uint upCode = 0x202; // Left click up code
SendMessage(fiveKey, downCode, wParam, lParam); // Mouse button down
SendMessage(fiveKey, upCode, wParam, lParam); // Mouse button up
x/y オフセットを "5" キーの位置に変更して、fiveKey ではなく hWnd にメッセージを送信しても機能しない理由を誰かに説明してもらえますか? 最終的には、このコードを使用して、電卓などのボタンを持たない別のアプリケーションでのマウス クリックをシミュレートしたいと考えています。