1
2
3
4
5
6 using System;
7 using System.Windows.API;
8
9 namespace System.Windows
10 {
11 public enum StandardIconId : int
12 {
13 IDI_APPLICATION = 32512,
14 IDI_ASTERISK = 32516,
15 IDI_ERROR = 32513,
16 IDI_EXCLAMATION = 32515,
17 IDI_HAND = 32513,
18 IDI_INFORMATION = 32516,
19 IDI_QUESTION = 32514,
20 IDI_SHIELD = 32518,
21 IDI_WARNING = 32515,
22 IDI_WINLOGO = 32517
23 }
24
25 public class Icon : Resource
26 {
27 public nothrow Icon() : iconHandle(null), standard(false)
28 {
29 }
30 public nothrow Icon(void* iconHandle_) : iconHandle(iconHandle_), standard(false)
31 {
32 }
33 public nothrow Icon(void* iconHandle_, bool standard_) : iconHandle(iconHandle_), standard(standard_)
34 {
35 }
36 public nothrow Icon(Icon&& that) : iconHandle(that.iconHandle), standard(that.standard)
37 {
38 that.iconHandle = null;
39 that.standard = false;
40 }
41 public ~Icon()
42 {
43 if (iconHandle != null && !standard)
44 {
45 WinDestroyIcon(iconHandle);
46 }
47 }
48 public default nothrow void operator=(Icon&&);
49 suppress Icon(const Icon&);
50 suppress void operator=(const Icon&);
51 public nothrow void* Handle() const
52 {
53 return iconHandle;
54 }
55 public nothrow bool IsStandard() const
56 {
57 return standard;
58 }
59 public nothrow void SetStandard()
60 {
61 standard = true;
62 }
63 private void* iconHandle;
64 private bool standard;
65 }
66
67 public Icon LoadStandardIcon(StandardIconId iconId)
68 {
69 void* iconHandle = WinLoadStandardIcon(cast<int>(iconId));
70 if (iconHandle == null)
71 {
72 throw WindowsAPIException(WinGetLastError());
73 }
74 return Icon(iconHandle, true);
75 }
76
77 public Icon LoadIcon(const string& iconName)
78 {
79 return Icon(LoadIcon(iconName.Chars()));
80 }
81 }