Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native Win32 window in WPF Control

Tags:

c++

c#

.net

wpf

winapi

I am developing an application that needs to a host native Win32 window and somehow i have no clues how to do that.

I need to create a WPF dialog window that could display native Win32 control on it. This dialog window will have WPF controls on it as well, so i am looking for some sort of Grid that i could take HWND of and send it to the unmanaged C++ control, so it could draw on it. Is that possible ?

I don't need to know what happens within that surface, just need to let C++ dll to draw on it and all i need to do is to pass HWND that has proper size (which i know).

I am kinda new to WPF (used to do win32 programming) and quite lost (but i now how to interface it to C# .NET etc)

Would be great if you could send me any hints :)

like image 318
pablox Avatar asked Sep 20 '11 23:09

pablox


People also ask

Does WPF use Win32?

WPF and Win32 Interoperation BasicsHost WPF content in a Win32 window. With this technique, you can use the advanced graphics capabilities of WPF within the framework of a standard Win32 window and application.

How do I navigate to another window in WPF?

NavigationService is for browser navigation within WPF. What you are trying to do is change to a different window TrainingFrm . To go to a different window, you should do this: private void conditioningBtn_Click(object sender, RoutedEventArgs e) { var newForm = new TrainingFrm(); //create your new form.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.


1 Answers

you can start by following the instructions/steps here: Hosting Win32 Content in WPF

from the article introduction:

A Walkthrough of Win32 Inside Windows Presentation Framework (HwndHost)

To reuse Win32 content inside WPF applications, use HwndHost, which is a control that makes HWNDs look like WPF content. Like HwndSource, HwndHost is straightforward to use: derive from HwndHost and implement BuildWindowCore and DestroyWindowCore methods, then instantiate your HwndHost derived class and place it inside your WPF application.

If your Win32 logic is already packaged as a control, then your BuildWindowCore implementation is little more than a call to CreateWindow.

then if you have a specific issue ask here in SO and people will help you on specific points.

like image 89
Davide Piras Avatar answered Oct 05 '22 07:10

Davide Piras