OSDN Git Service

8f091db337131e49598a61a4788669eee82b7d5a
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / NativeMethods.cs
1 using System;\r
2 using System.Runtime.InteropServices;\r
3 using System.Windows.Forms;\r
4 \r
5 namespace AppliStation.Util\r
6 {\r
7         public sealed class NativeMethods\r
8         {\r
9                 private NativeMethods()\r
10                 {\r
11                 }\r
12                 \r
13                 \r
14                 /// <summary>\r
15                 /// WindowsVista\8cü\82¯\81A\83v\83\8d\83O\83\8c\83X\83o\81[\83X\83e\81[\83^\83X(\90F)\82ð\90Ý\92è\82·\82é\r
16                 /// </summary>\r
17                 /// <param name="progBar">\91Î\8fÛ\82Ì\83v\83\8d\83O\83\8c\83X\83o\81[</param>\r
18                 /// <param name="state">\8fó\91Ô\81B(1:Normal,2:Error,3:Paused)</param>\r
19                 public static void ProgressBar_SetState(ProgressBar progBar, uint state)\r
20                 {\r
21                         try {\r
22                                 // status := (PBST_NORMAL | PBST_ERROR | PBST_PAUSED)\r
23                                 // SendMessage(progressBar.Handle, PBM_SETSTATE, state, 0);\r
24                                 SendMessage(progBar.Handle, 0x410, state, 0);\r
25                         } catch (Exception) {\r
26                         }\r
27                 }\r
28                 \r
29                 #region \83^\83X\83N\83o\81[\82¨\82æ\82Ñ\83^\83C\83g\83\8b\83o\81[\82Ì\83t\83\89\83b\83V\83\85\r
30                 \r
31                 /// <summary>\r
32                 /// \83^\83X\83N\83o\81[\82¨\82æ\82Ñ\83^\83C\83g\83\8b\83o\81[\83{\83^\83\93\82Ì\83t\83\89\83b\83V\83\85\82Ì\90Ý\92è\83t\83\89\83O\r
33                 /// </summary>\r
34                 public enum FlashFlag : uint {\r
35                         /// <summary>\r
36                         /// \93_\96Å\82Ì\92â\8e~\r
37                         /// </summary>\r
38                         Stop = 0,\r
39                         /// <summary>\r
40                         /// \83^\83C\83g\83\8b\83o\81[\82ð\93_\96Å\r
41                         /// </summary>\r
42                         Caption = 1,\r
43                         /// <summary>\r
44                         /// \83^\83X\83N\83o\81[\83{\83^\83\93\82ð\93_\96Å\r
45                         /// </summary>\r
46                         Tray = 2,\r
47                         /// <summary>\r
48                         /// \83^\83C\83g\83\8b\83o\81[\82Æ\83^\83X\83N\83o\81[\83{\83^\83\93\82ð\93_\96Å\r
49                         /// </summary>\r
50                         All = 3,\r
51                         /// <summary>\r
52                         /// Stop\82ª\90Ý\92è\82³\82ê\82é\82Ü\82Å\93_\96Å\82·\82é\r
53                         /// </summary>\r
54                         Timer = 4,\r
55                         /// <summary>\r
56                         /// \83t\83H\83A\83O\83\89\83E\83\93\83h\82Ì\8fó\91Ô\82É\82È\82é\82Ü\82Å\93_\96Å\r
57                         /// </summary>\r
58                         TimerNoFG = 12,\r
59                 }\r
60                 \r
61                 [StructLayout(LayoutKind.Sequential)]\r
62                 struct FLASHWINFO\r
63                 {\r
64                     public int cbSize;\r
65                     public IntPtr hWnd;\r
66                     public FlashFlag dwFlags;\r
67                     public uint uCount;\r
68                     public uint dwTimeout;\r
69                 }\r
70                 \r
71                 /// <summary>\r
72                 /// \83^\83X\83N\83o\81[\82¨\82æ\82Ñ\83^\83C\83g\83\8b\83o\81[\83{\83^\83\93\82ð\93_\96Å\82³\82¹\82é\r
73                 /// </summary>\r
74                 /// <param name="form">\91Î\8fÛ\83t\83H\81[\83\80</param>\r
75                 /// <param name="flag">\93_\96Å\83p\83\89\83\81\81[\83^\83t\83\89\83O</param>\r
76                 /// <param name="count">\93_\96Å\89ñ\90\94</param>\r
77                 /// <param name="timeout">\93_\96Å\82Ì\8aÔ\8au(\83~\83\8a\95b)</param>\r
78                 /// <returns></returns>\r
79                 public static bool Form_FlashWindow(Form form, FlashFlag flag, uint count, uint timeout)\r
80                 {\r
81                         try {\r
82                                 FLASHWINFO info = new FLASHWINFO();\r
83                                 info.cbSize = Marshal.SizeOf(typeof(FLASHWINFO));\r
84                                 info.hWnd = form.Handle;\r
85                                 info.dwFlags = flag;\r
86                                 info.uCount = count;\r
87                                 info.dwTimeout = timeout;\r
88                                 \r
89                                 return FlashWindowEx(ref info) == 0;\r
90                         } catch (Exception) {\r
91                                 return false;\r
92                         }\r
93                 }\r
94                 \r
95                 [DllImport("user32.dll")]\r
96                 static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);\r
97                 \r
98                 #endregion\r
99                 \r
100                 #region ColumnHeader\82Ì\83\\81[\83g\82Ì\8eO\8ap\88ó\97p\r
101                 \r
102                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]\r
103                 internal struct HD_ITEM\r
104                 {\r
105                         public uint    mask;\r
106                         public int     cxy;\r
107                         [MarshalAs(UnmanagedType.LPTStr)]public string   pszText;\r
108                         public IntPtr   hbm;\r
109                         public int     cchTextMax;\r
110                         public int     fmt;\r
111                         [MarshalAs(UnmanagedType.LPTStr)]public string  lParam;\r
112                         public int     iImage;        // index of bitmap in ImageList\r
113                         public int     iOrder;\r
114                 }\r
115                 \r
116                 internal static IntPtr ListView_GetHeader(ListView listview)\r
117                 {\r
118                         // SendMessage(hWnd, LVM_GETHEADER, 0, NULL);\r
119                         return SendMessage(listview.Handle, 0x101E, 0, 0);\r
120                 }\r
121                 \r
122                 /// <summary>\r
123                 /// WinXP\88È\8d~\81A\83\\81[\83g\82Ì\96î\88ó\82ð\95\\8e¦\r
124                 /// </summary>\r
125                 /// <param name="listView">\91Î\8fÛ\82ÌListView</param>\r
126                 /// <param name="column">\95\\8e¦\82·\82é\96î\88ó\82Ì\83w\83b\83_</param>\r
127                 /// <param name="order">\83\\81[\83g\82Ì\8f¸\8f\87\81E\8d~\8f\87</param>\r
128                 public static void ColumnHeader_SetSortState(ListView listView, int column, SortOrder order)\r
129                 {\r
130                         try {\r
131                                 // SendMessage(hWnd, LVM_GETHEADER, NULL, NULL);\r
132                                 IntPtr hWnd = SendMessage(listView.Handle, 0x101F, 0, 0);\r
133                                 \r
134                                 HD_ITEM hdi = new HD_ITEM();\r
135                                 hdi.mask = 0x0004; // HDI_FORMAT;\r
136                                 for (int i = 0; i < listView.Columns.Count; i++) {\r
137                                         // SendMessage(hWnd, HDM_GETITEMW, i, &hdi);\r
138                                         SendMessage(hWnd, 0x120b, i, ref hdi);\r
139                                         \r
140                                         const int HDF_SORTUP = 0x400;\r
141                                         const int HDF_SORTDOWN = 0x200;\r
142                                         \r
143                                         if (i != column || order == SortOrder.None) {\r
144                                                 hdi.fmt = hdi.fmt & ~(HDF_SORTUP | HDF_SORTDOWN);\r
145                                         } else if (order == SortOrder.Ascending) { // \8f¸\8f\87\r
146                                                 hdi.fmt = hdi.fmt & ~HDF_SORTDOWN | HDF_SORTUP;\r
147                                         } else if (order == SortOrder.Descending) { // \8d~\8f\87\r
148                                                 hdi.fmt = hdi.fmt & ~HDF_SORTUP | HDF_SORTDOWN;\r
149                                         }\r
150                                         \r
151                                         // SendMessage(hWnd, HDM_SETITEMW, i, &hdi);\r
152                                         SendMessage(hWnd, 0x120c, i, ref hdi);\r
153                                 }\r
154                         } catch (Exception) {\r
155                         }\r
156                 }\r
157                 \r
158                 #endregion\r
159                 \r
160                 #region EnableWindow(\83R\83\81\83\93\83g\83A\83E\83g)\r
161 //              /// <summary>\r
162 //              /// \8ew\92è\82³\82ê\82½\83R\83\93\83g\83\8d\81[\83\8b(\83E\83B\83\93\83h\83E)\82Ö\82Ì\81A\r
163 //              /// \83L\81[\83{\81[\83h\93ü\97Í\82¨\82æ\82Ñ\83}\83E\83X\93ü\97Í\82ð\97L\8cø\89»\82Ü\82½\82Í\96³\8cø\89»\r
164 //              /// </summary>\r
165 //              /// <param name="control">\91Î\8fÛ\82Ì\83R\83\93\83g\83\8d\81[\83\8b\82Ì\83n\83\93\83h\83\89</param>\r
166 //              /// <param name="bEnable">\97L\8cø\82É\82·\82é\82©\96³\8cø\82É\82·\82é\82©\82ð\8ew\92è</param>\r
167 //              /// <returns>\92¼\91O\82É\83E\83B\83\93\83h\83E\82ª\96³\8cø\8fó\91Ô\82¾\82Á\82½\8fê\8d\87\82Ítrue\82ð\95Ô\82·</returns>\r
168 //              public static bool Control_EnableWindow(Control ctrl, bool bEnable)\r
169 //              {\r
170 //                      try {\r
171 //                              return EnableWindow(ctrl.Handle, bEnable);\r
172 //                      } catch {\r
173 //                              ctrl.Enabled = bEnable;\r
174 //                              return true;\r
175 //                      }\r
176 //              }\r
177 //              \r
178 //              /// <summary>\r
179 //              /// \8ew\92è\82³\82ê\82½\83R\83\93\83g\83\8d\81[\83\8b(\83E\83B\83\93\83h\83E)\82Ö\82Ì\81A\r
180 //              /// \83L\81[\83{\81[\83h\93ü\97Í\82¨\82æ\82Ñ\83}\83E\83X\93ü\97Í\82ð\97L\8cø\89»\82Ü\82½\82Í\96³\8cø\89»\r
181 //              /// </summary>\r
182 //              /// <param name="control">\91Î\8fÛ\82Ì\83R\83\93\83g\83\8d\81[\83\8b\82Ì\83n\83\93\83h\83\89</param>\r
183 //              /// <param name="bEnable">\97L\8cø\82É\82·\82é\82©\96³\8cø\82É\82·\82é\82©\82ð\8ew\92è</param>\r
184 //              /// <returns>\92¼\91O\82É\83E\83B\83\93\83h\83E\82ª\96³\8cø\8fó\91Ô\82¾\82Á\82½\8fê\8d\87\82Ítrue\82ð\95Ô\82·</returns>\r
185 //              [DllImport("user32.dll")]\r
186 //              public static extern bool EnableWindow(IntPtr hWnd, bool bEnable);\r
187                 #endregion\r
188                                 \r
189                 [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
190                 internal static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);\r
191                 \r
192                 [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
193                 internal static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, int wParam, ref HD_ITEM lParam);\r
194         }\r
195 }\r