PDC05: Day Four (Windows Presentation Foundation "Avalon" in Win32/MFC Applications"

If you have an existing application and you want to be able to add Avalon objects to it, then you make use of HwndSource to place Avalon objects into an existing HWND. A good example of this would be taking an existing dialog, removing the UI code and replacing it with XAML and managed code. This is a great way to add Avalon to an existing application, particular for us here at DeLorme. If you are going to do this, be sure to associate "[System:STAThreadAttribute]" with the "main()" method to ensure it loads the CLR properly at startup. Another caveat is that you cannot have compiled XAML and unmanaged code in the same assembly. You could have uncompiled XAML and then compile it at runtime, you could have two assemblies to separate the two, or you could create the WPF controls by hand rather than with XAML.
// WPF inside an HWND.
HwndSource source = new HwndSource(…);
source.RootVisual = myWpfStuff;
HWND hwnd = source.Handle;
If, on the other hand, you want to write a new Avalon application, but draw your special Win32/MFC controls into it, then you would use HwndHost. It is worth noting that though Avalon supports HRGNs, it does not support layered windows.
0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home