WPF and Windows Forms Interoperation
Description on MSDN:
In a WPF user interface, you can change the z-order of elements to control overlapping behavior. A hosted Windows Forms control is drawn in a separate HWND, so it is always drawn on top of WPF elements.
*But I would like to know there is no private way to solve it?
No, this is known as the airspace problem (because WinForms elements take all of it).
There was supposed to be a fix around .NET 4.5/4.6 but it never made it to production (source; there are others if you google it). There has been no word as of yet that Microsoft plans on addressing it.
This article might help with ways to get around it: MSDN
My first recommandation would be to replace the Windows Form control by an equivalent WPF control.
Second recommandation would be to accept the limitation and do not overlap any WPF control over the Windows Form control.
In some case, you might be able to use multiple top-level Windows to work around the limitation. You then have to write some code to properly synchronize the location or the apparent activation state of Windows...
I have never done that between Windows Form and WPF but I have done 2 top-level windows in Windows Form so that part of the UI could be semi-transparent (the purpose was to be able to overlap another application (maybe a PDF viewer) so that we can "copy" curves from existing charts).
Related
I want to create a level editor, using a Windows Forms Application.
Here is the layout that i want to achieve:
BLUE -> Windows form control
PURPLE -> Canvas, handled differently (Yeah, Windows forms controls too, but not for the same use of it)
I have a problem though, how to render the Canvas in a proper way without using a thread ?
(Look at my other thread here: Access object from other thread)
I thought about a timer, but I don't know if it's reliable.
Ideally a thread would be nice but Windows doesn't like the fact that you want to interact between thread so it's messed up to be polite.
If you know how to achieve that, well, thanks ! :)
I am integrating a webcam in a WPF application. I can see the camera feed in the main window, as I pass its HANDLE on to the DirectShow functions. But this is not what I want.
The main form has a Image control, where I'd like to see the output. However, in order to do this, I need the control's Handle.
Any hint on how to do this?
Thanks in advance,
Gianluca.
An Image Control in WPF, unlike Windows Forms, doesn't actually have an HWND.
WPF works differently than Windows Forms - each control is not a wrapper around a native "window" with a handle, but rather composed together using Direct3D at runtime by the layout system.
If you need to actually host output from a Webcam inside of a WPF window, you should look at using HwndHost (or a subclass). The simplest way is often to just host a Windows Forms control inside of a WindowsFormsHost, though managing an HWND yourself via HwndHost is more efficient.
Using an WindowsFormsHost and a picture box inside is a good solution that I used for a similar problem where I needed a handle to display a video stream. But be careful, in order to work, the Window that is hosting the WindowsFormsHost control must have AllowsTransparency="false"!
I've seen from the Windows API Code Pack that it is possible to enable custom glass in a winforms application, but I've been unable to ascertain how to get child windows to show as separte thumbnails for aero peek (in much the same manner that IE displays the contents of its tabs as separate windows)
Is it possible to do this from a Winforms application, or will it involve lots of P/Invoke voodoo?
The Windows API Code Pack contains what you need for this. Check out the Microsoft.WindowsAPICodePack.Taskbar.TabbedThumbnailManager class and related classes in the documentation.
These classes allow you to provide custom thumbnails and peek images to the taskbar, either from a Bitmap or created from a child control (presumably you can use an MDI child window for this as well, though I haven't tested it).
Assume i have an empty form 100px by 100px at 0,0 coordinates on the screen. It has no border style. Is there any way to have this positioned BEHIND the desktop icons?
I would assume this would involve the process Progman because thats what contains the desktop icons. But no matter what i try... getting window handles and changing parents etc, i cant seem to get the window to appear behind the icons.
Any ideas?
Essentially you want to draw on the desktop wallpaper. The desktop hierarchy looks like this:
"Program Manager" Progman
"" SHELLDLL_DefView
"FolderView" SysListView32
It's the SysListView32 that actually draws the desktop icons, so that's what you have to hook. And you can't just stick your form on top of it; you have to grab a WindowDC to that handle and draw on the DC.
It can be done - it has been done, but you're going to be using a lot of interop. Forget about doing this with a traditional Winforms Form. I don't think I've even seen it done in C#, although somebody did it in python, if that helps. I'm not a python coder myself, but the code is pretty short and easy to understand.
There is a solution to this problem, at least for Windows 8. I postet it in form of an article on CodeProject, so you can read about it here:
http://www.codeproject.com/Articles/856020/Draw-behind-Desktop-Icons-in-Windows
This works for simple drawing, windows forms, wpf, directx, etc. The solution presented in that article is only for Windows 8.
Google-fu led me to this MSDN forum question:
http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/c61d0705-d9ec-436a-b0a6-6ffa0ecec0cc
And this is a blog post regard the major pitfalls with using GetDesktopWindow() or dealing with the desktop handle (as per your other question: C# Position Window On Desktop)
http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx
You also don't want to pass GetDesktopWindow() as your hwndParent. If you create a child window whose parent is GetDesktopWindow(), your window is now glued to the desktop window. If your window then calls something like MessageBox(), well that's a modal dialog, and then the rules above kick in and the desktop gets disabled and the machine is toast.
Anyway, I suspect that it probably CAN be done, but whether you should is another question.
I'm working on an application, and I have a screen that in my mind, looks a lot like the Wireless Network List in Windows Vista. For those who are unaware, its basically a listview, but in each row, instead of a line of text, there's a large 'panel' that contains all sorts of useful information. Does anyone know if that's an actual UI control available on windows, or should I roll my own with some sort of autosizing table layout panel hosting a collection of custom controls?
I know this is pretty easy to make using WPF using the stackpanel layout along with a series of user controls containing grid controls for internal layout. Or are you using windows forms?
The wireless network dialog isn't using a standard Win32 control, it's using a custom control (effectively).
If you want to emulate that behavior, you're going to have to use WPF or roll your own.
Not an exact answer but you may want to look at the various Vista TaskDialog libraries and dialogs that have been based on that. You may be able to borrow some of the code since they share some UI functionality. I need to do the something similar with WPF.