Added LoadIcon method.

Made SHFILEINFO non-public.
Modified WinGLNative.cs to use Icon.ExctractAssociatedIcon() to set the application icon (needs work).
This commit is contained in:
the_fiddler 2009-10-14 22:48:19 +00:00
parent a8231a5eb4
commit cb1c73e827
2 changed files with 33 additions and 19 deletions

View file

@ -813,11 +813,22 @@ namespace OpenTK.Platform.Windows
#endregion #endregion
#region IsWindowVisible
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr intPtr); public static extern bool IsWindowVisible(IntPtr intPtr);
#endregion #endregion
#region LoadIcon
[DllImport("user32.dll")]
public static extern HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName);
#endregion
#endregion
#region Display settings #region Display settings
#region ChangeDisplaySettings #region ChangeDisplaySettings
@ -2701,7 +2712,7 @@ namespace OpenTK.Platform.Windows
#region ShFileInfo #region ShFileInfo
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHFILEINFO struct SHFILEINFO
{ {
public IntPtr hIcon; public IntPtr hIcon;
public int iIcon; public int iIcon;

View file

@ -588,26 +588,29 @@ namespace OpenTK.Platform.Windows
// Gets the shell application icon for the executing process or the default icon, if not available. // Gets the shell application icon for the executing process or the default icon, if not available.
Icon GetApplicationIcon() Icon GetApplicationIcon()
{ {
IntPtr retval = IntPtr.Zero; //return Icon.FromHandle(Functions.LoadIcon(Process.GetCurrentProcess().Handle, ""));
try try { return Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().CodeBase); }
{ catch { return null; }
SHFILEINFO info = new SHFILEINFO(); //IntPtr retval = IntPtr.Zero;
info.szDisplayName = ""; //try
info.szTypeName = ""; //{
// SHFILEINFO info = new SHFILEINFO();
// info.szDisplayName = "";
// info.szTypeName = "";
int cbFileInfo = Marshal.SizeOf(info); // int cbFileInfo = Marshal.SizeOf(info);
ShGetFileIconFlags flags = ShGetFileIconFlags.Icon | ShGetFileIconFlags.SmallIcon | ShGetFileIconFlags.UseFileAttributes; // ShGetFileIconFlags flags = ShGetFileIconFlags.Icon | ShGetFileIconFlags.SmallIcon | ShGetFileIconFlags.UseFileAttributes;
string path = System.Reflection.Assembly.GetEntryAssembly().CodeBase; // string path = System.Reflection.Assembly.GetEntryAssembly().CodeBase;
retval = Functions.SHGetFileInfo(path, 256, ref info, (uint)cbFileInfo, flags); // retval = Functions.SHGetFileInfo(path, 256, ref info, (uint)cbFileInfo, flags);
return Icon.FromHandle(info.hIcon); // return Icon.FromHandle(info.hIcon);
} //}
catch //catch
{ //{
// Shallow exceptions and fall-back to default icon. // // Shallow exceptions and fall-back to default icon.
Debug.Print("SHGetFileInfo failed, return value: {0}", retval); // Debug.Print("SHGetFileInfo failed, return value: {0}", retval);
return null; // return null;
} //}
} }
#endregion #endregion