Context
In a C# Windows Forms application for Win7 we host an ActiveX control. So far, so good.
Need: prevent ActiveX to receive mouse events
Actually, the ActiveX has too much functionality. It is not very customizable to turn off features we don't need.
It would be nice if we just prevented it from receiving mouse events.
The ideal would be to just treat events as if the ActiveX was not there, that is the mouse clicks go right through to the underlying (or containing) Control.
But if we just prevent the ActiveX from getting events that would be okay with us.
Search before you ask
Some answers to previous questions mention to protected override void WndProc(ref Message m), e.g. c# - Pass-through mouse events to parent control - Stack Overflow
Other mentions to implement IMessageFilters, e.g.:
winforms - C# Application-Wide Left Mouse Click Event - Stack Overflow
winforms - Handling a click event anywhere inside a panel in C# - Stack Overflow
winforms - C# Application-Wide Left Mouse Click Event - Stack Overflow
Capturing Mouse Events from every component on C# WInForm - Stack Overflow
Experiment: ActiveX still gets events
I have fairly extensively tried both override WndProc and IMessageFilter ways, filtering (opt-in and opt-out) a number of events. In some cases I can prevent events to reach native C# controls, but the ActiveX still got its share.
Filtering too much, prevented controls and ActiveX to paint, or even application to draw properly or caused crash on exit. This can be averted by selecting opt-in or opt-out options carefully.
Is there another way?
Is there another way from C#/.NET to host an ActiveX Control while preventing it from getting mouse events? Perhaps at application start time?
Try to do a EnableWindow(hand,FALSE) on the uppermost hwnd of the ActiveX Control after has been created. See Using Window Handle to disable Mouse clicks using c# how to do this in c#.
I just faced the same issue (with a different ActiveX).
#GunnarRoth's answer and the page Using Window Handle to disable Mouse clicks using c# - Stack Overflow imply platform-specific magic with window handle, which is better avoided when possible.
A hint, still, is that it has Enabled in its name.
The ActiveX host object is a Windows Forms Control. I just set Enabled=false and the effect is exactly what I want : no mouse clicks or keyboard events are seen by the ActiveX, yet it still displays fine.
I don't even know if this would answer my initial question with the initial ActiveX Control, but this time it does! :-)
Related
I'm completely new to C# and the .NET framework so forgive me if this is a silly question.
Is there any way of viewing a list of all of the events that have happened on a Windows system as a result of keystrokes and mouse movements etc.? So for example when I click on the Start menu, the Start menu is displayed or when I click the "Apply" button within a settings sub-menu, the settings are applied.
Is there any part of the .NET framework that will allow me to view all of these events/actions and record them via a C# program? Any help would me greatly appreciated! Thanks in advance.
UI Automation API is what you need. For listening automation events there are few kinds of handlers: AutomationEventHandler, StructureChangedEventHandler and 2 others.
There is another way for native windows: global mouse and keyboard hooks. See SetWindowsHookEx function.
C# in visual studio designer gives you the ability to respond to all kinds of events, like mouse moves and clicks. If you click on the object you want events from, then go to the events pane, you will see a list of all the events for that object. double click in the textbox next to it and it will auto-generate an event handler in your code. When the event is triggered, it will go to this method and do any code you provide there; IE log the action however you choose.
I have a WebBrowser control shown in a custom task pane in an Microsoft Office Application-level add-in created in Visual Studio. The web page shown in the WebBrowser doesn't receive keyboard events that can be handled by JavaScript code, such as KeyUp. The same page shown in a comparable WebBrowser in a Form does receive keyboard events. The WebBrowser control itself doesn't seem to expose any events related to keyboard input, and I don't seem to be able to handle keyboard events by adding event handlers to the UserControl added as a custom task pane.
I have created a minimal example – a Visual Studio solution – which recreates the problem.
Is there any way to pass on keyboard events to the web page?
Yup, you can do it. You'll have to hook into the HTML DOM events (like onclick, onmouseover, etc.). Take a look here: http://www.w3schools.com/jsref/dom_obj_event.asp.
And there's an example here:
http://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values
I think you'll have to add a reference to the MSHTML library. BTW, put the WebBrowser control in a Panel control or it will act goofy - especially with keyboard events.
Actually I found a solution is to use the WebBrowser under Excel namespace
https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.controls.webbrowser.aspx
Obviously it is subclassing the windows form WebBrowser and fix the keyboard issues by handing some windows message manually.
I have a form (having Taskbar button shown in Taskbar) and I want to handle left/right clicks of this Task-bar button. I searched everywhere but could find the right answer. There are some related queries posted in stack-overflow as well:
Using wndproc in C# to minimize form on leftclick of taskbar
How to Detect Right Click on the Taskbar
But, nobody seems to have given a proper answer to "How to do" it?
Is there any pointers or code snippet how to do it?
Please note that I am talking about Task-bar app button (please don't confuse with Systray menu or Notification area). I have explicitly stated it because I have seen this confusion several places.
Your application doesn't get a say in how the task bar button is handled. The task bar is owned by windows, and is used by windows to control display and positioning of your application's windows. Basically your request is out-of-bounds in the windows playground.
Sorry.
what you can do is to use TaskbarManager out of the ApicodePack library
Windows 7 Taskbar C# Quick Reference
where you are able to handle such events.
I am doing a UI automation for a WPF application using the Microsoft UI Automation library and it works well.
However my app has four screens in a TabControl. Even when I click the tab item through code its child control tree isnt populated. The only control I can see is the "thumb" Control. Same happens when I see the control tree with UISpy.
However if the window is clicked then all the controls appear. As a Workaround I am simulating a mouseclick through code and it works. I wanted to know if there is some better way of doing it.
I ran into a problem similar to this. What was happening was some data was being retrieved on threads and the controls were not generated at the point automation peers were generated. I would suggest if you have access to the code base for the application you are attempting to automate looking into whether threading is being used. In my specific case it was because BeginInvokes were used to retrieve the data, I switched them to Invokes and it worked fine.
Also from what I could tell the reason the controls were being show on mouse over was because the tool tip generated a popup and caused the automation peers to be updated.
Why don't you click the control using mouse events if that is what works.
(Now, if you still are having that problem..)
How to simulate Mouse Click in C#?
I have a similar problem to this question regarding painting of wpf controls
The application I work on is a rather large Windows forms threaded application with several wpf user controls throughout the application. The problem occurs in a plugin of the application where a third party c++ library is called on a separate thread, WndProc is overriden to get the progress updates from the third party library. I have yet to determine the exact scenario that causes the problem but similar to the above mentioned question, after a few runs the wpf controls fails to paint and update.
Setting the width of the elementhosts does solve the painting issue for most of the controls but after this all the wpf controls in the application seems to become 'unresponsive' - visually... the progress bars fails to show progress (though the value does change), scrollbars does not respond, selecting an item in the listview does not highlight it(it does get highlighted after resizing and it does actually get selected - you just can see it is selected) the treeviews does not paint after the resizing, it only shows a black background where the treeview should be (though when I click on the items where they should be in the treeview, the events does get trigerred)
I know I should probably find out the root of the problems that causes this first (its hapening rather randomely and is hard to trap) - allthough putting a breakpoint in the WndProc method does seem to cause it to fail on a regualar base...
What I was hoping for is a way to 'reactivate'/refresh all the other controls throughout the application... I am an intermediate wpf, c# developer and dont really know enough yet about the messaging and events that happens in the background to use them effectively ... my thought is that some event or message that tells wpf to redraw must be broken or interrupted or something - how can I determine what is broken and maybe reactivate it??
Any advice will be much appreciated...
Thank You
It could be that the event that causes the WPF control graph render is never being processed because of that WndProc override.
Since you are inter-oping with WinForms, you can force the events to process by performing a call to Application.DoEvents(); somewhere. Perhaps after you update the progress bar.