Page 1 of 1

How to get the handle of an Irrlicht window?

Posted: Tue Sep 19, 2006 8:11 pm
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.

Posted: Wed Sep 20, 2006 6:44 am
by matiae
hi, in .NET every control (and form) has the .Handle property that gets the IntPtr.. it's not a method :)

Posted: Thu Sep 21, 2006 9:30 am
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.

Posted: Thu Sep 21, 2006 10:50 am
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
            }
        }
    }
}

Posted: Thu Sep 21, 2006 2:16 pm
by mrpingwin
Thanks, I'll play around with windows API stuff and see if I can that working. :)