

Simulate clicking a button in another window in C #
source link: https://www.codesd.com/item/simulate-clicking-a-button-in-another-window-in-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Simulate clicking a button in another window in C #
I'd like to close a dialog that pops up automatically, but I'm having some trouble getting it to work. My Win32 programming is a bit rusty after several years of limited usage.
I'm using FindWindowEx to get handles to the dialog and the button I want to click. I was under the impression that sending a WM_COMMAND to the dialog, with the button handle in the wParam parameter would do the trick.
Window window = Window.FindWindow("TSomeDialog", null);
Window cancelButton = Window.FindWindow("TButton", "Cancel", window);
Message message = Message.Create(window.HWnd, 0x0111, cancelButton.HWnd, IntPtr.Zero);
PostMessage(message);
public void PostMessage(Message message)
{
// Win32 API import
PostMessage(message.HWnd, message.Msg, message.WParam, message.LParam);
}
Window is a class that implements IWin32Window and wraps some Win32 API calls. I have inlined the constant for WM_COMMAND (0x111).
What am I doing wrong? :)
Well, according to the documentation for WM_COMMAND, lParam should be the handle to the control's window (it looks like you're passing it in wParam).
wParam should have its high order word equal to BN_CLICKED and its low order word equal to the control's identifier.
(You can use GetWindowLong with GWL_ID to retrieve this, but presumably its IDCANCEL.)
Recommend
-
14
Matthew Miner Methodic: Run Functions by Clicking a Button June 17, 2017 Ages ago I bui...
-
13
Keep the div button in the static position when the window is resized advertisements I am fairly new to css and html and so I am having a litt...
-
6
How do I create a button in an Outlook window for mail from an inbox (double-click on mail)? advertisements I am programmer...
-
4
Hello 👋 In this post I will show you how to make Random Background, when you click a button in JavaScript. This is Part 1 of the 50 JS Project Challenge. So let's get into it. First, here is the video...
-
7
At the push of a button, and without a maintenance window! A web application only generates revenue if it is available to users. This is why changes are traditionally deployed when most users sleep. Th...
-
8
Moving a macOS window by clicking anywhere on it (like on Linux)Apr 16, 2022Today I learned that since macOS High Sierra onwards you can move a window by clicking on any part of it (just like on Linux):
-
9
Clicking through a Translucent Image Window
-
7
Windows 11 2022 Update lets you create quick notes by clicking button on Surface Pen...
-
9
Clicking on 'Comment' button with empty text field gives strange result...
-
7
No response when clicking close button on fragement in custom action of UI5 Element ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK