I've done some searching, but I can't find an exact answer on this. In my C# WPF app, I get the HWND pointer and pass it to a C dll. That C dll then attempts to use GDI calls to render an overlay of sorts on my window. There are no errors, but nothing appears. If I switch to a Windows Form, the dll can render over it fine. If I host a WindowsFormHost control and use the hwnd from there I have the same effect. I've seen information on the HwndHost control but it doesn't really look like what I want. Perhaps someone with more knowledge of that control can tell me differently. I read somewhere that an hwnd used for DirectX rendering (like WPF) can't also use GDI. Does this make my scenario impossible? I could fake it by overlaying a borderless form over the WPF window, but obviously that wouldn't be too pretty. Any thoughts or ideas?
Asked
Active
Viewed 1,929 times
1 Answers
5
You can't have WPF and GDI rendering to the same hwnd but you can easily have a child hwnd inside of your WPF app and let GDI render into it. Take a look at HwndHost for doing that. The section "Hosting a Microsoft Win32 Window in WPF" in this article has a little more details. It also talks about the various issues you'll run into (like airspace) when doing this type of interop.

Robert Levy
- 28,747
- 6
- 62
- 94
-
Thanks for responding! I came across this but it didn't look like what I was looking for. I don't actually have anything to host. I just want a "clean" hwnd to hand off to the GDI rendering dll. Sadly, I also need to be able to hand off mouse up/down to WPF, but that's secondary to the rendering. Can you give me any guidance? – Arian Kulp Feb 04 '11 at 21:52
-
1You need an HWND and that's what an HwndHost hosts. Handle WM_PAINT, get a device context and start drawing. – Rick Sladkey Feb 04 '11 at 23:09