HOWTO: Setting the icon of a RenderWindow.

NxJonny

26-02-2009 00:17:18

Here is my tiny contribution to the community :)

[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern int DrawMenuBar(int currentWindow);

private const int WM_SETICON = 0x80;
private const int ICON_SMALL = 0;

/// <summary>
/// Sets the icon of a window using it's handle.
/// </summary>
/// <param name="icon">The System.Drawing.Icon you wish to use as the window's icon.</param>
/// <param name="hwnd">The window's handle.</param>
public static void SetIcon(System.Drawing.Icon icon, IntPtr hwnd)
{
if (icon == null || hwnd == null || hwnd == IntPtr.Zero) // check parameters
return;
SendMessage(hwnd, WM_SETICON, (IntPtr)ICON_SMALL, (IntPtr)icon.Handle); // Set the icon with SendMessage
DrawMenuBar((int)hwnd); // Force windows to update the icon
}

You can get the handle of a RenderWindow instance like this:

IntPtr hwnd = new IntPtr();
MyRenderWindow.GetCustomAttribute("WINDOW", out hwnd);

Then it's just a matter of

SetIcon(new System.Drawing.Icon("myicon.ico"), hwnd);


Another interesting thing you could do is create an extension method for RenderWindow...

I'd put this on the wiki, but I wasn't sure where it should go...Is there a code snippets page for Mogre? Should I create one?

Beauty

28-02-2009 02:46:55

Nice that you want to support the community :)

There is no snippet page for Mogre.
Just create a page. E.g. Set icon of Window (Mogre)

Maybe in future we create a page for Mogre snippet overview.
(This time there are only less snippets for Mogre in the wiki)