Is there a way to register a handler to be notified when my application's windows change visibility based on the OS (or anyone else) accessing the HWND directly via something like ShowWindow() with SW_HIDE, etc.?
Assuming your application is WinForms based. Yes, that should be possible by overriding the WndProc of your main Form.
See WndProc MSDN documentation for details.
Related
I have a third party application I'm writing an add-in for and I need to be able to modify a specific dialog if possible. That dialog has many controls and groups that are .. it seems, owner drawn and thus don't expose window handles to tools like spy++ and others. I welcome any insight into how I might disable controls on the this dialog.
Since I am running in-process, I can use detours (https://www.microsoft.com/en-us/research/project/detours/) to intercept functions and use calls like enumwindows/enumchildwindows to find handles to controls that I can then use techniques like NativeWindow (C#) to override wndproc messages and do manipulation. I'm also familiar with setwindowshookex and hooking the message queues.
Just looking for some ideas and patterns for working with owner drawn controls. Thanks!
[Edit1] I am also familiar with the UI Automation (C#/C++) and IAccessible frameworks. Those will allow me some control (potentiall), like detecting mouse clicks and such, but I was hoping for something more elegant. For example: with a normal combobox, if I have a handle, I can use sendmessage() to send it CB_* messages to manipulate its contents. How do you do that with a combobox if you can't get the handle ... given that it is owner drawn (presumably) and part of another owner drawn parent.
thus don't expose window handles to tools like spy++ and others
Then they are not real controls as far as the OS is concerned, and so there is nothing you can do to access/manipulate them directly. The app would have to expose an API or UI Automation interface for them. Presumably the app will not provide more access than it really wants an add-on to have.
You should contact the app author for help fulfilling your goal.
I have an application whose UI is custom rendered with a theme. I also want to add new non-default-cursors (like the resize cursors when the user intends to resize the window) to match that theme.
With the WinAPI function SetCursor I am only able to change the default pointer for the application, but this is not enough, so I looked up SetSystemCursor which works just fine. Problem is: The latter version changes the cursors system-wide permanently, but I only want them to be changed for my application only.
I thought about copying the previous cursors before I do the SetSystemCursor and re-set them at application exit, but even when I implement a terminate handler it may not be called if the process e.g. just crashes. Also the cursors would still be changed system-wide as long as the application is running.
Specifically for the resize-cursors, I could just drop the window style, make a borderless window, and render/implement the resizing grips and logic myself (then I could just hook the mouse-over events), but that is really just my last resort - I'd rather like to know if it is possible achieve my goal before I do this cumbersome task...
For anyone who is interested: The UI is rendered with WPF, but WPF doesn't provide this functionality either (again, they have it, but just for the default pointer). It's no concern for me to use the WinAPI or other "low-level" calls if I have to, but at the moment it seems there are none that are fitting my needs :(
So if anybody knows how to change the other system cursors (not the default pointer) in WPF or WinAPI just for my application without having to implement custom cursor-logic to my window just for that, you would make my day.
I don't know how to implement this in WPF, but if you want to set the cursor to something other than default, then your window procedure should handle the WM_SETCURSOR message.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx
I have to write an application that observes another application and extracts information from the window. What is the best way to access windows from other applications and get data from their controls?
You'll need to P/Invoke the FindWindow and FindWindowEx functions to retrieve a handle to the other application's parent window and child controls.
Then you will need to use something like GetWindowText to access the text for a particular control.
Visit pinvoke.net for the definitions you'll need to call these functions from C#.
Be warned that this is not a completely straightforward pursuit. You should stop to consider whether you really have a good reason for wanting to do this, and if your goal couldn't be achieved in a simpler way.
I feel like I'm missing something really obvious here.
I know that forms in general have a Handle property, but I am using a System.Windows.Controls.TextBox and it does not have a Handle property.
How do I access the TextBox's handle? I noticed that RichTextBox has the Handle property, so why not the regular TextBox?
You can just call Handle on the TextBox. It is an inherited property from System.Windows.Forms.Control.
Edit: Question was updated to ask about WPF
WPF doesn't use handles like a typical Win32 application or WinForms application. Each control is not its own Window in WPF. You can verify this with Spy++, it cannot differentiate between each control. Therefore you cannot SendMessage to the individual controls like you can with WinForms and Win32 apps.
You can use WindowInteropHelper to get the parent window handle of a WPF window.
My C# application includes an embedded web browser, which is made possible by the System.Windows.Forms.WebBrowser class. Users are able to navigate to websites using the app, however, when they encounter a page that includes a pop-up window, the pop-up window is opened by Internet Explorer.
Does anyone know how to suppress that behavior?
NOTE: I'm new to C#, so please take that into consideration when responding.
Are you looking to actively block popups or handle them in your application? If you're wanting to customize the blocking, then you'll have to implement the DWebBrowserEvents2 interface, specifically the NewWindow3 method. NewWindow3 method has specific functionality for blocking window popups (i.e. setting the Cancel parameter to true). These methods will also let you show your own window if you wish, though you'll have to provide your own Form to host yet another WebBrowser.
If you'd like to see some real C# source code providing advanced functionality with the WebBrowser control, I'd have to say that this article on CodeProject provided almost everything I know about the WebBrowser control. Be sure to download the source!
#Kramii is correct that you can also use the NewWindow2 event to prevent the popup. NewWindow3 provides additional parameters for if you're looking to inspect the URL or other data about the navigate to actually sometimes block and sometimes handle the popup yourself.
IIRC you can trap the NewWindow2 event on the WebBrowser control and set Cancel = true to prevent the pop-up.
This article may help:
http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx#GoalBlock