How to get the handle of an Irrlicht window?

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
mrpingwin
Posts: 3
Joined: Tue Sep 19, 2006 8:00 pm

How to get the handle of an Irrlicht window?

Post by mrpingwin »

I need to be able to get the window handle of my Irrlicht app but there does not seem to be any method for doing this in Irrlicht.NET.

Is there any way to do this?

Thanks for any assistance.
matiae
Posts: 16
Joined: Wed May 31, 2006 8:06 am
Location: Chile

Post by matiae »

hi, in .NET every control (and form) has the .Handle property that gets the IntPtr.. it's not a method :)
mrpingwin
Posts: 3
Joined: Tue Sep 19, 2006 8:00 pm

Post by mrpingwin »

matiae wrote:hi, in .NET every control (and form) has the .Handle property that gets the IntPtr.. it's not a method :)
This will only work if you are running Irrlicht inside a .NET form which is not the case here. I am getting Irrlicht to create its own window rather than creating a .NET window and getting Irrlicht to run inside it so I need to be able to get the handle back from the window that Irrlicht has created.
matiae
Posts: 16
Joined: Wed May 31, 2006 8:06 am
Location: Chile

Post by matiae »

haa, I see.. :o I don't know if there is a better way to do it in .NET but you could use window api functions, e.g.

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using Irrlicht;
using Irrlicht.Core;
using System.Runtime.InteropServices;

namespace Project1
{
    class Class1
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        public static void Main(string[] args)
        {
            IrrlichtDevice device = new IrrlichtDevice(
                Irrlicht.Video.DriverType.DIRECT3D9, new Dimension2D(640, 480), 16, false, false, false);
            device.WindowCaption = "Irrlict window!!";
            IntPtr WindowHandle = FindWindow(null, "Irrlict window!!");
            while(device.Run())
            {
                // loop
            }
        }
    }
}
mrpingwin
Posts: 3
Joined: Tue Sep 19, 2006 8:00 pm

Post by mrpingwin »

Thanks, I'll play around with windows API stuff and see if I can that working. :)
Locked