I have an application which is in normal mode, now from that application i want to send click message to another window (say internet explorer). I want to click where mouse cursor is pointing right now with respect to screen and that click should be handled by internet explorer.
You can use the Win32 API call mouse_event -- I do not know if there is a .NET equivalent, but it can be used to do just what you want, i.e. fake a mouse click at the current location. To do this call it with the LEFTDOWN and LEFTUP flags.
Look it up on pinvoke.net for how to call from C# and VB.NET.
Related
Here is my scenario:
A user has two applications open. Let's say one application is Notepad with some text in it and the other one is my C# application.
A user now positions the mouse cursor somewhere inside the Notepad text and then clicks a button in my C# application. As a result, a text string from my application gets pasted in Notepad where the cursor was positioned.
My question is: what would a general approach be to accomplish the above, and possibly what classes etc. are recommended?
I would look into using interop calls to accomplish this. Look at specifically GetWindow() and SendMessage with the WM commands (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined) and GetDesktop().
GetDesktop will allow you to obtain all of the top level child windows of the desktop (all top level windows are children of the Desktop window).
You should then be able to use GetWindow to obtain the window handle you are looking for and then SendMessage to set the text into the textbox.
Well, the project has moved along rather nicely and we have a pretty darn good product, but a wrench has been thrown into the gear works.
We have a C# 2012 application that interacts with another application (written in VB 6 of all things) and we can do a good bit with it so far, but we have a problem.
We need to select a button on a toolbar at the top of this particular application's window, but the button is not available through an API search. We have the main window's handle and can see all of its children, but I think the Toolbar is a User type control that we can't access through the API Calls. This application is very poorly designed and we had to do a LOT of work just to discover TWO User ID text boxes on the logon screen.
Anyway, my question is this: How would I set up a call to the main window and click a certain X, Y coordinate of that window's viewable area? I am using SendMessage to send mouse clicks to press a button control already, but if I can't get access to that button control, the idea was to send mouse clicks to a specific coordinate of the window.
Any ideas folks? Thanks!
It looks like the solution will be to get the Window's rectangle and add the offset in order to use the mouse event API call.
Thank you to #Idle_Mind for the suggestion. It is at least working on our test environment. It will be next week before we can test the solution out in our client's environment.
I'm writing an application that needs to record a click location on the screen, over the top of another window using the mouse. Is there anyway to disable the mouse click so that it doesn't affect the window that is being clicked over?
e.g. I want to set a point over the top of my browser, but I don't want to click anything within my browswer whilst setting it.
You have a couple options:
Write a plugin/extension for the browser you're talking about. Maybe the browser's interface allows you to record such information
Use windows hooks. Using SetWindowsHookEx and WH_MOUSE_LL, you can get all mouse activity on the computer fairly simply. You will just need to check if the mouse activity is happening in the browser, using WindowFromPoint.
I need to create a application which is similar to those we will get when we buy a laptop. It will be visible only when the mouse pointer reaches the top of the window. So how can I able to do this using C# 4.0 ?
http://www.notebookcheck.net/uploads/pics/win2_12.jpg
this link u can see the application. I need to create such type
Any idea pls share. Thanks
I suppose there are several different ways to achieve this effect:
You can place part of the window of your application above the visible screen, so only a part of it is visible (let's say you can see only it's bottom). Then you need to handle events when mouse enters (MouseEnter) and leaves (MouseLeave) the form to move the form up and down.
You can use a background thread to call GetCursorPos method at a set interval (i.e. each 500ms) second to check where currently the mouse is. See this link for more information about it and a sample code: http://www.pinvoke.net/default.aspx/user32.getcursorpos.
(If you need only to check the mouse position, you can use a timer to simplify you application.)
When you hit what's possible with C#, you can always start invoking native code - such as the windows API. Since you don't ask a specific question, I'll leave you with:
Position your app where you want it to appear and hide it.
Capture mouse position with windows api (see this SO answer)
When mouse is at screen corner / top, etc; make your app visible.
Now make sure all this works with dual screen setup, and you are done.
I have a NotifyIcon in the system tray. How can I detect when the user has left-clicked down on it? I assumed the MouseDown event would be what I want to use but it only handles right click and middle-button click. For left-click, it only fires after the user has let go (as in they've just performed a normal click). Is there a way to get the MouseDown event only?
This is by design, the shell synthesizes the MouseDown message from the up event. You'll see why it works this way when you click and hold the button down and then start dragging. Note how the notification area overflow window pops up and lets you drag the icon into it to remove it from the visible area. It can't work both ways.
Technically you could hook the window owned by Explorer.exe to get a crack at the messages before Explorer does with SetWindowsHookEx(). That however requires a kind of DLL that you cannot write in C#, it needs to be injected into Explorer. Very destabilizing and hard to beat the competition that is trying to do the same thing. Also the kind of code that causes sleepless nights for the Microsoft appcompat team.
It appears that the underlying Win32 API Shell_NotifyIcon sends a WM_LBUTTONDOWN message when the user clicks the icon. According to MSDN anyway.
Examining the Windows Forms source code for NotifyIcon reveals standard mouse down event handling, so if the Win32 message was being sent at the "correct" time it would work as you want/expect.
I have to agree with a previous comment that NotifyIcon will be swallowing WM_LBUTTONDOWN since it needs to do mouse capture to allow the user to drag the icons about.
It's possible that this article about creating a tray icon for WPF will be useful since it shows how to use SetWindowsHookEx etc from C#.