History: Set icon of Window (Mogre)
Source of version: 2 (current)
Copy to clipboard
This snippet is about how to set the icon of a RenderWindow.
For questions use [http://www.ogre3d.org/addonforums/viewtopic.php?f=8&t=9375|this thread].
{CODE(wrap="1", colors="c#")} [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
}{CODE}
You can get the handle of a RenderWindow instance like this:
{CODE(wrap="1", colors="c#")} IntPtr hwnd = new IntPtr();
MyRenderWindow.GetCustomAttribute("WINDOW", out hwnd);{CODE}
Then it's just a matter of
{CODE(wrap="1", colors="c#")} SetIcon(new System.Drawing.Icon("myicon.ico"), hwnd);{CODE}
Another interesting thing you could do is create an [http://msdn.microsoft.com/en-us/library/bb383977.aspx|extension method] for RenderWindow...
''If you know where to get free icons it would be nice if you add the link here'' (-;
A great place for free icons is [http://www.iconarchive.com/|Iron Archive]