geekay
29-08-2011 21:46:51
I would like to set the cursor of my mogre generated render window.
I think this is what I need, I have found this:
http://www.ogre3d.org/tikiwiki/Custom+Icon+and+Cursor&highlight=change%20cursor
#ifdef WIN32
HWND hwnd;
mRenderWindow->getCustomAttribute("WINDOW", &hwnd);
HINSTANCE hInst = (HINSTANCE)GetModuleHandle(NULL);
SetClassLong (hwnd, GCL_HCURSOR,
(LONG)LoadCursor (hInst, MAKEINTRESOURCE (IDC_POINTER)));
#endif
but I have no idea how to translate this from c++ into c#
I am sure that the code itself is not all that hard to figure out--- but im just not getting it.
If anyone knows how to go about doing this, please let me know.
Thank you kindly for your time!
~GK
Zonder
30-08-2011 10:30:22
you are better off just using a WinForms window to render to instead of letting ogre create one then you don't need to get involved with the win32 api.
smiley80
30-08-2011 11:58:31
Add 'System.Windows.Forms' as a reference to your project.
In your main loop:
Cursor.Current = newCursor;
Where 'newCursor' is an instance of
Cursor.
The built-in cursors are static properties of the
Cursors class.
geekay
30-08-2011 21:36:11
So, when I Initialize() the Root to automatically generate the render window, there is no way to set the cursor of that returned RenderWindow?
smiley80
30-08-2011 22:25:10
You have to use P/Invoke for that:
public static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
if (IntPtr.Size != 4)
return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
else
return new IntPtr(SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
}
[DllImport("user32.dll", EntryPoint = "SetClassLong")]
public static extern uint SetClassLongPtr32(IntPtr hWnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetClassLongPtr")]
public static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
Usage:
IntPtr windowHnd;
this.window.GetCustomAttribute("WINDOW", out windowHnd);
SetClassLong(windowHnd, -12, newCursor.Handle);
Cursor.Position = Cursor.Position; //forces Cursor graphic update
geekay
30-08-2011 22:44:59
You have to use P/Invoke for that:
public static IntPtr SetClassLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
if (IntPtr.Size != 4)
return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
else
return new IntPtr(SetClassLongPtr32(hWnd, nIndex, unchecked((uint)dwNewLong.ToInt32())));
}
[DllImport("user32.dll", EntryPoint = "SetClassLong")]
public static extern uint SetClassLongPtr32(IntPtr hWnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetClassLongPtr")]
public static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
Usage:
IntPtr windowHnd;
this.window.GetCustomAttribute("WINDOW", out windowHnd);
SetClassLong(windowHnd, -12, newCursor.Handle);
Cursor.Position = Cursor.Position; //forces Cursor graphic update
You are wonderful, im going to give it a go right now. Thanks so very much for your time on this!
geekay
30-08-2011 23:51:10
You have to use P/Invoke for that: ...
You are wonderful, im going to give it a go right now. Thanks so very much for your time on this!
tested it out, works perfectly, Thank you so very much!