132
|
1 module tango.sys.win32.Macros;
|
|
2
|
|
3 /*
|
|
4 Module: Windows Utilities
|
|
5 Author: Trevor Parscal
|
|
6 */
|
|
7
|
|
8 /+ Imports +/
|
|
9 public
|
|
10 {
|
|
11 import tango.sys.win32.Types;
|
|
12 }
|
|
13 private
|
|
14 {
|
|
15 import tango.stdc.string;
|
|
16 import tango.sys.win32.UserGdi;
|
|
17 }
|
|
18
|
|
19
|
|
20 /+ Functions +/
|
|
21 ushort MAKEWORD(ubyte A, ubyte B)
|
|
22 {
|
|
23 return cast(ushort)(A | (B << 8));
|
|
24 }
|
|
25 uint MAKELONG(ushort A, ushort B)
|
|
26 {
|
|
27 return cast(uint)(A | (B << 16));
|
|
28 }
|
|
29 ushort HIWORD(uint L)
|
|
30 {
|
|
31 return cast(ushort)(L >> 16);
|
|
32 }
|
|
33 ushort LOWORD(uint L)
|
|
34 {
|
|
35 return cast(ushort)(L & 0xFFFF);
|
|
36 }
|
|
37 ubyte HIBYTE(ushort W)
|
|
38 {
|
|
39 return cast(ubyte)(W >> 8);
|
|
40 }
|
|
41 ubyte LOBYTE(ushort W)
|
|
42 {
|
|
43 return cast(ubyte)(W & 0xFF);
|
|
44 }
|
|
45 HANDLE GlobalDiscard(HANDLE h)
|
|
46 {
|
|
47 return GlobalReAlloc(h, 0, GMEM_MOVEABLE);
|
|
48 }
|
|
49 HANDLE LocalDiscard(HANDLE h)
|
|
50 {
|
|
51 return LocalReAlloc(h, 0, LMEM_MOVEABLE);
|
|
52 }
|
|
53 BOOL SUCCEEDED(HRESULT Status)
|
|
54 {
|
|
55 return (cast(int)Status & 0x80000000) == 0;
|
|
56 }
|
|
57 BOOL FAILED(HRESULT Status)
|
|
58 {
|
|
59 return (cast(int)Status & 0x80000000) != 0;
|
|
60 }
|
|
61 BOOL IS_ERROR(HRESULT Status)
|
|
62 {
|
|
63 return (cast(int)Status >> 31) == SEVERITY_ERROR;
|
|
64 }
|
|
65 int HRESULT_CODE(HRESULT hr)
|
|
66 {
|
|
67 return cast(int)hr & 0xFFFF;
|
|
68 }
|
|
69 int HRESULT_FACILITY(HRESULT hr)
|
|
70 {
|
|
71 return (cast(int)hr >> 16) & 0x1FFF;
|
|
72 }
|
|
73 int HRESULT_SEVERITY(HRESULT hr)
|
|
74 {
|
|
75 return (cast(int)hr >> 31) & 0x1;
|
|
76 }
|
|
77 HRESULT MAKE_HRESULT(int sev, int fac, int code)
|
|
78 {
|
|
79 return cast(HRESULT)((sev << 31) | (fac << 16) | code);
|
|
80 }
|
|
81 HRESULT HRESULT_FROM_WIN32(int x)
|
|
82 {
|
|
83 return cast(HRESULT) (x ? (x & 0xFFFF) | (FACILITY_WIN32 << 16) | 0x80000000 : 0);
|
|
84 }
|
|
85 //HRESULT HRESULT_FROM_NT(int x)
|
|
86 //{
|
|
87 // return x | FACILITY_NT_BIT;
|
|
88 //}
|
|
89 DWORD MAKEROP4(DWORD fore, DWORD back)
|
|
90 {
|
|
91 return ((back << 8) & 0xFF000000) | fore;
|
|
92 }
|
|
93 ubyte GetKValue(COLORREF cmyk)
|
|
94 {
|
|
95 return cast(ubyte)(cmyk & 0xFF);
|
|
96 }
|
|
97 ubyte GetYValue(COLORREF cmyk)
|
|
98 {
|
|
99 return cast(ubyte)((cmyk >> 8) & 0xFF);
|
|
100 }
|
|
101 ubyte GetMValue(COLORREF cmyk)
|
|
102 {
|
|
103 return cast(ubyte)((cmyk >> 16) & 0xFF);
|
|
104 }
|
|
105 ubyte GetCValue(COLORREF cmyk)
|
|
106 {
|
|
107 return cast(ubyte)((cmyk >> 24) & 0xFF);
|
|
108 }
|
|
109 COLORREF CMYK(ubyte c, ubyte m, ubyte y, ubyte k)
|
|
110 {
|
|
111 return k | (y << 8) | (m << 16) | (c << 24);
|
|
112 }
|
|
113 COLORREF RGB(ubyte r, ubyte g, ubyte b)
|
|
114 {
|
|
115 return r | (g << 8) | (b << 16);
|
|
116 }
|
|
117 COLORREF PALETTERGB(ubyte r, ubyte g, ubyte b)
|
|
118 {
|
|
119 return 0x02000000 | RGB(r, g, b);
|
|
120 }
|
|
121 COLORREF PALETTEINDEX(ushort i)
|
|
122 {
|
|
123 return 0x01000000 | i;
|
|
124 }
|
|
125 ubyte GetRValue(COLORREF rgb)
|
|
126 {
|
|
127 return cast(ubyte)(rgb & 0xFF);
|
|
128 }
|
|
129 ubyte GetGValue(COLORREF rgb)
|
|
130 {
|
|
131 return cast(ubyte)((rgb >> 8) & 0xFF);
|
|
132 }
|
|
133 ubyte GetBValue(COLORREF rgb)
|
|
134 {
|
|
135 return cast(ubyte)((rgb >> 16) & 0xFF);
|
|
136 }
|
|
137 WPARAM MAKEWPARAM(ushort l, ushort h)
|
|
138 {
|
|
139 return MAKELONG(l, h);
|
|
140 }
|
|
141 LPARAM MAKELPARAM(ushort l, ushort h)
|
|
142 {
|
|
143 return MAKELONG(l, h);
|
|
144 }
|
|
145 LRESULT MAKELRESULT(ushort l, ushort h)
|
|
146 {
|
|
147 return MAKELONG(l, h);
|
|
148 }
|
|
149 BOOL ExitWindows(DWORD dwReserved, UINT uReserved)
|
|
150 {
|
|
151 return ExitWindowsEx(EWX_LOGOFF, 0);
|
|
152 }
|
|
153 HWND CreateWindowA(PCHAR b, PCHAR c, DWORD d, int e,
|
|
154 int f, int g, int h, HWND i, HMENU j, HINST k, POINTER l)
|
|
155 {
|
|
156 return CreateWindowExA(0, b, c, d, e, f, g, h, i, j, k, l);
|
|
157 }
|
|
158 HWND CreateWindowW(PWIDECHAR b, PWIDECHAR c, DWORD d, int e,
|
|
159 int f, int g, int h, HWND i, HMENU j, HINST k, POINTER l)
|
|
160 {
|
|
161 return CreateWindowExW(0, b, c, d, e, f, g, h, i, j, k, l);
|
|
162 }
|
|
163 HWND CreateDialogA(HINST a, PANSICHAR b, HWND c, DLGPROC d)
|
|
164 {
|
|
165 return CreateDialogParamA(a, b, c, d, 0);
|
|
166 }
|
|
167 HWND CreateDialogW(HINST a, PWIDECHAR b, HWND c, DLGPROC d)
|
|
168 {
|
|
169 return CreateDialogParamW(a, b, c, d, 0);
|
|
170 }
|
|
171 HWND CreateDialogIndirectA(HINST a, DLGTEMPLATE* b, HWND c, DLGPROC d)
|
|
172 {
|
|
173 return CreateDialogIndirectParamA(a, b, c, d, 0);
|
|
174 }
|
|
175 HWND CreateDialogIndirectW(HINST a, DLGTEMPLATE* b, HWND c, DLGPROC d)
|
|
176 {
|
|
177 return CreateDialogIndirectParamW(a, b, c, d, 0);
|
|
178 }
|
|
179 int DialogBoxA(HINST a, PANSICHAR b, HWND c, DLGPROC d)
|
|
180 {
|
|
181 return DialogBoxParamA(a, b, c, d, 0);
|
|
182 }
|
|
183 int DialogBoxW(HINST a, PWIDECHAR b, HWND c, DLGPROC d)
|
|
184 {
|
|
185 return DialogBoxParamW(a, b, c, d, 0);
|
|
186 }
|
|
187 int DialogBoxIndirectA(HINST a, DLGTEMPLATE* b, HWND c, DLGPROC d)
|
|
188 {
|
|
189 return DialogBoxIndirectParamA(a, b, c, d, 0);
|
|
190 }
|
|
191 int DialogBoxIndirectW(HINST a, DLGTEMPLATE* b, HWND c, DLGPROC d)
|
|
192 {
|
|
193 return DialogBoxIndirectParamW(a, b, c, d, 0);
|
|
194 }
|
|
195 void ZeroMemory(void* dest, uint len)
|
|
196 {
|
|
197 memset(dest, 0, len);
|
|
198 }
|
|
199 void FillMemory(void* dest, uint len, ubyte c)
|
|
200 {
|
|
201 memset(dest, c, len);
|
|
202 }
|
|
203 void MoveMemory(void* dest, void* src, uint len)
|
|
204 {
|
|
205 memmove(dest, src, len);
|
|
206 }
|
|
207 void CopyMemory(void* dest, void* src, uint len)
|
|
208 {
|
|
209 memcpy(dest, src, len);
|
|
210 }
|