Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1] 2
  Print  
Author Topic: C# WPF HWND problems  (Read 1567 times)
adeebm
Community Member
*
Posts: 37


« on: July 15, 2008, 03:26:31 PM »

I've been using truevision in winforms for a while and just made the switch to wpf. Everything works except rendering. Because truevision requires a handle to render I used a hack to extract the handle from the wpf windows. The problem is, because of wpf's rendering technique thing rendered to the handle go on top so all my controls are covered. Controls in wpf don't have handles so I cant render to an image(picturebox). I tried using interop to render to a winforms control, but because of wpf it still covers all the control(Interop control are always on top) I even tried having the winforms picturebox hidden, rendering then capturing the picture and copying to a wpf image but it comes up black. Has anyone used truevision with wpf before? Maybe if i knew how truevision rendered to the HWND i could get the image. or is there a way for truevision to render to a bitmap or something?

--Adeeb
Logged
adeebm
Community Member
*
Posts: 37


« Reply #1 on: July 17, 2008, 01:43:00 PM »

Anyone? It kind of urgent...
Logged
Raine
Customers
Community Member
*****
Posts: 1189


« Reply #2 on: July 18, 2008, 04:54:36 PM »

I think you'll get far more results over at codeproject.com, I'm sure one of the WPF gurus has your solution...
Logged

adeebm
Community Member
*
Posts: 37


« Reply #3 on: July 19, 2008, 02:06:02 PM »

I posted here because I'm wondering if truevision has another way to render, like to a bitmap?
Logged
kcs_aug
Community Member
*
Posts: 2


« Reply #4 on: September 05, 2008, 02:00:03 PM »

new on the site...
you can use 
<WindowsFormsHost Canvas.Left="10" Canvas.Top="75" Height="450"
                          Name="whPanel" Width="326" Visibility="Visible" />
this will Host Windows Forms controls...ie. winfoms picbox..

  Dim xpanel As New PictureBox
    Dim host2 As New WindowsFormsHost()

        xpanel.Width = gWidth
        xpanel.Height = gHeight
        xpanel.BackColor = Color.Black
        host2.Child = xpanel
        whPanel.Child = host2.Child

        now the Render Window is a WinForms Picture Box...

I have tested 'other' 3d sdks in it.. works.. am going to try
TV3d now.. good luck..
Logged
kcs_aug
Community Member
*
Posts: 2


« Reply #5 on: September 05, 2008, 02:06:23 PM »

forgot to mention in above.. you probably realize..
since the host is now a winforms picture box it HAS a handle.. just use
it like a non WPF control.. because it is.. therefore , I assume,  any and all
WPF AND WinForms controls can be used in a WPF application....
Logged
DP-John
Customers
Community Member
*****
Posts: 120


« Reply #6 on: September 26, 2008, 07:49:12 PM »

The proper way to do this is to reference System.Runtime.InteropServices

In VB.Net it goes like this...

Code:
Dim mainWindowPtr As Integer = New WindowInteropHelper(Me).Handle

This returns the window reference (hwnd) of a WPF window.
Logged

adeebm
Community Member
*
Posts: 37


« Reply #7 on: October 25, 2008, 02:36:06 PM »

I already found the WindowInteropHelper, but the problem is that Truesion for some reason renders on top so all my controls get covered up. Is there any way for truevision to render to something other than a handle, like an HBitmap?
Logged
adeebm
Community Member
*
Posts: 37


« Reply #8 on: October 29, 2008, 04:13:08 PM »

Hasn't anyone used Truevision with WPF?
Logged
aspurgeon
Customers
Community Member
*****
Posts: 161


« Reply #9 on: October 29, 2008, 04:44:09 PM »

Are you passing the handle of the WPF form, or of a control?  If you pass the handle to the form, I would expect that TV3D would render on top of everything else, because it's essentially repainting the form with whatever is rendered, every frame.  This happens in Windows Forms, too. 

In Windows Forms we use a PictureBox, and pass the handle of that control to TV.  Have you tried passing the handle of WPF control, like an Image (I don't think WPF has the "PictureBox")?  If you do that using Interop, I would expect it to work...

UPDATE (1) -- ok, use a "Windows Forms Host" control, not an image.  You can get a handle from that control.

UPDATE (2) -- Ok, you do use a WindowsFormsHost control (which you can add using the designer in Visual Studio).  Then, in code, you need to add a PictureBox control to the WindowsFormsHost as its child, and pass the handle of the PictureBox to TV.  Execute your render loop, and EUREKA!  You've got TV in WPF.  I just wrote a simple C# app to do this, so I know it works.  I did not do anything fancy (like test mouse picking, etc).

If you have trouble, let me know, and I'll post the sample project.

-Andy
 
« Last Edit: October 29, 2008, 05:03:55 PM by aspurgeon » Logged
adeebm
Community Member
*
Posts: 37


« Reply #10 on: October 29, 2008, 06:04:06 PM »

That works, but then It also stays on top of wpf controls due to mircosoft's laziness. So I would not be able to put my gui over the picturebox. I need a way to get truevision to render to something other than a handle.

I've been using truevision in winforms for a while and just made the switch to wpf. Everything works except rendering. Because truevision requires a handle to render I used a hack to extract the handle from the wpf windows. The problem is, because of wpf's rendering technique thing rendered to the handle go on top so all my controls are covered. Controls in wpf don't have handles so I cant render to an image(picturebox). I tried using interop to render to a winforms control, but because of wpf it still covers all the control(Interop control are always on top) I even tried having the winforms picturebox hidden, rendering then capturing the picture and copying to a wpf image but it comes up black. Has anyone used truevision with wpf before? Maybe if i knew how truevision rendered to the HWND i could get the image. or is there a way for truevision to render to a bitmap or something?

So those options don't work. Maybe if I knew how truevision uses a handle, I could give it a fake handle and extract the image from it onto a bitmap?
« Last Edit: October 29, 2008, 06:07:51 PM by adeebm » Logged
tagget
Customers
Community Member
*****
Posts: 186


« Reply #11 on: October 29, 2008, 07:07:49 PM »

Can I ask why you want to use TV with a WPF Application? Why not just make your own UI in TV instead?
Logged
aspurgeon
Customers
Community Member
*****
Posts: 161


« Reply #12 on: October 29, 2008, 08:11:56 PM »

I misunderstood what you were trying to accomplish.  But I taught myself something about WPF. Wink

I don't think you can put controls on top like you want.  I use windows forms for my editor, with TV rendering in a picture box, but I'm using nUI within my project.  I think you're going to need to use one of the UI libs that are other there, or roll your own...
Logged
adeebm
Community Member
*
Posts: 37


« Reply #13 on: October 29, 2008, 09:45:03 PM »

What bothers me is that it works in winforms, and the reason I switched to wpf is because of wpf's gui improvements. There must be some way...

How exactly does Truevision render using the handle. There are some methods to "get" an image from a handle which works with regular forms, but returns a black screen for handles used by truevision.
« Last Edit: October 29, 2008, 09:53:03 PM by adeebm » Logged
Craigomatic
Customers
Community Member
*****
Posts: 78


« Reply #14 on: October 30, 2008, 05:30:44 AM »

You've come across the airspace issue, the most annoying part of WPF.

See here (especially the links from that post) for the correct way to do it: http://www.truevision3d.com/forums/tv3d_sdk_65/wpf_d3dimage_tv3d-t18357.0.html

I'm yet to actually make it work with TV3D
Logged
adeebm
Community Member
*
Posts: 37


« Reply #15 on: October 30, 2008, 08:56:18 PM »

So is there any way to get a D3D object from Truevision?
Logged
aspurgeon
Customers
Community Member
*****
Posts: 161


« Reply #16 on: October 30, 2008, 08:58:08 PM »

Yes.  Have a look at the TVInternals object.
Logged
adeebm
Community Member
*
Posts: 37


« Reply #17 on: October 30, 2008, 09:38:16 PM »

Is it TVInternalObjects.GetDirect3D ? And Truevision would still require a handle to render, so how would I overcome that?
Logged
tagget
Customers
Community Member
*****
Posts: 186


« Reply #18 on: October 31, 2008, 05:37:32 PM »

Quote
And Truevision would still require a handle to render, so how would I overcome that?

TVGlobals.CreateWindowHandle() As System.IntPtr?
Logged
adeebm
Community Member
*
Posts: 37


« Reply #19 on: November 03, 2008, 01:31:27 PM »

It doesn't seem to be working. the D3DImage needs an IDirect3DSurface9 and neither GetDevice3D nor GetDirect3D return that. How do I do this?

I think I need to get the surface from GetDevice3D(). Is there any managed way to do that? If not then how would I go about this?
« Last Edit: November 03, 2008, 01:45:18 PM by adeebm » Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks