1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.util.wintypes;
29 
30 private
31 {
32     import derelict.util.compat;
33 }
34 
35 /*
36 This module is used internally to avoid any dependence upon external Win32 modules.
37 Considering that there are modules in Phobos, Tango, and the Bindings project at
38 DSource, we want to avoid any conflicts with whichever implementation Derelict users choose.
39 */
40 version(Windows)
41 {
42     alias uint DWORD;
43     alias ushort WORD;
44     alias ushort USHORT;
45     alias uint UINT;
46     alias int INT;
47     alias int LONG;
48     alias ubyte BYTE;
49     alias float FLOAT;
50     alias int BOOL;
51     alias DWORD COLORREF;
52 
53     alias CCPTR LPCSTR;
54     alias void* LPVOID;
55 
56     alias void* HANDLE;
57     alias HANDLE HDC;
58     alias HANDLE HGLRC;
59     alias HANDLE HINSTANCE;
60     alias HANDLE HMODULE;
61     alias HANDLE HWND;
62     alias HANDLE HLOCAL;
63     alias HANDLE HPALETTE;
64     alias HANDLE HBITMAP;
65 
66     alias UINT WPARAM;
67     alias LONG LPARAM;
68 
69     alias int function() FARPROC;
70 
71     struct LAYERPLANEDESCRIPTOR
72     {
73         WORD nSize;
74         WORD nVersion;
75         DWORD dwFlags;
76         BYTE iPixelType;
77         BYTE cColorBits;
78         BYTE cRedBits;
79         BYTE cRedShift;
80         BYTE cGreenBits;
81         BYTE cGreenShift;
82         BYTE cBlueBits;
83         BYTE cBlueShift;
84         BYTE cAlphaBits;
85         BYTE cAlphaShift;
86         BYTE cAccumBits;
87         BYTE cAccumRedBits;
88         BYTE cAccumGreenBits;
89         BYTE cAccumBlueBits;
90         BYTE cAccumAlphaBits;
91         BYTE cDepthBits;
92         BYTE cStencilBits;
93         BYTE cAuxBuffers;
94         BYTE iLayerPlane;
95         BYTE bReserved;
96         COLORREF crTransparent;
97     }
98 
99     struct POINTFLOAT
100     {
101         FLOAT x;
102         FLOAT y;
103     }
104 
105     struct GLYPHMETRICSFLOAT
106     {
107         FLOAT gmfBlackBoxX;
108         FLOAT gmfBlackBoxY;
109         POINTFLOAT gmfptGlyphOrigin;
110         FLOAT gmfCellIncX;
111         FLOAT gmfCellIncY;
112     }
113 
114     struct PIXELFORMATDESCRIPTOR
115     {
116         WORD  nSize;
117         WORD  nVersion;
118         DWORD dwFlags;
119         BYTE  iPixelType;
120         BYTE  cColorBits;
121         BYTE  cRedBits;
122         BYTE  cRedShift;
123         BYTE  cGreenBits;
124         BYTE  cGreenShift;
125         BYTE  cBlueBits;
126         BYTE  cBlueShift;
127         BYTE  cAlphaBits;
128         BYTE  cAlphaShift;
129         BYTE  cAccumBits;
130         BYTE  cAccumRedBits;
131         BYTE  cAccumGreenBits;
132         BYTE  cAccumBlueBits;
133         BYTE  cAccumAlphaBits;
134         BYTE  cDepthBits;
135         BYTE  cStencilBits;
136         BYTE  cAuxBuffers;
137         BYTE  iLayerType;
138         BYTE  bReserved;
139         DWORD dwLayerMask;
140         DWORD dwVisibleMask;
141         DWORD dwDamageMask;
142     }
143 
144     struct VA_LIST {}
145 
146     enum : BYTE
147     {
148         PFD_TYPE_RGBA                   = 0,
149         PFD_TYPE_COLORINDEX             = 1
150     }
151 
152     enum
153     {
154         PFD_MAIN_PLANE                  = 0,
155         PFD_OVERLAY_PLANE               = 1,
156         PFD_UNDERLAY_PLANE              = -1
157     }
158 
159     enum
160     {
161         PFD_DOUBLEBUFFER                = 0x00000001,
162         PFD_STEREO                      = 0x00000002,
163         PFD_DRAW_TO_WINDOW              = 0x00000004,
164         PFD_DRAW_TO_BITMAP              = 0x00000008,
165         PFD_SUPPORT_GDI                 = 0x00000010,
166         PFD_SUPPORT_OPENGL              = 0x00000020,
167         PFD_GENERIC_FORMAT              = 0x00000040,
168         PFD_NEED_PALETTE                = 0x00000080,
169         PFD_NEED_SYSTEM_PALETTE         = 0x00000100,
170         PFD_SWAP_EXCHANGE               = 0x00000200,
171         PFD_SWAP_COPY                   = 0x00000400,
172         PFD_SWAP_LAYER_BUFFERS          = 0x00000800,
173         PFD_GENERIC_ACCELERATED         = 0x00001000,
174         PFD_SUPPORT_DIRECTDRAW          = 0x00002000,
175         PFD_DEPTH_DONTCARE              = 0x20000000,
176         PFD_DOUBLBUFFER_DONTCARE        = 0x40000000,
177         PFD_STEREO_DONTCARE             = 0x80000000,
178     }
179 
180     enum
181     {
182         LANG_NEUTRAL                    = 0,
183         SUBLANG_DEFAULT                 = 1,
184         FORMAT_MESSAGE_ALLOCATE_BUFFER  = 256,
185         FORMAT_MESSAGE_IGNORE_INSERTS   = 512,
186         FORMAT_MESSAGE_FROM_SYSTEM      = 4096
187     }
188 
189     struct RGBQUAD {
190         BYTE    rgbBlue;
191         BYTE    rgbGreen;
192         BYTE    rgbRed;
193         BYTE    rgbReserved;
194     }
195 
196     struct BITMAPINFOHEADER
197     {
198         DWORD      biSize;
199         LONG       biWidth;
200         LONG       biHeight;
201         WORD       biPlanes;
202         WORD       biBitCount;
203         DWORD      biCompression;
204         DWORD      biSizeImage;
205         LONG       biXPelsPerMeter;
206         LONG       biYPelsPerMeter;
207         DWORD      biClrUsed;
208         DWORD      biClrImportant;
209     }
210 
211     struct BITMAPINFO {
212         BITMAPINFOHEADER    bmiHeader;
213         RGBQUAD[1]          bmiColors;
214     }
215 
216     struct RECT
217     {
218         LONG    left;
219         LONG    top;
220         LONG    right;
221         LONG    bottom;
222     }
223 
224     extern(Windows)
225     {
226         int ChoosePixelFormat(HDC,PIXELFORMATDESCRIPTOR*);
227         int GetPixelFormat(HDC);
228         int DescribePixelFormat(HDC,int,UINT,PIXELFORMATDESCRIPTOR*);
229         BOOL SwapBuffers(HDC);
230 
231         HMODULE LoadLibraryA(LPCSTR);
232         FARPROC GetProcAddress(HMODULE, LPCSTR);
233         void FreeLibrary(HMODULE);
234         DWORD GetLastError();
235         DWORD FormatMessageA(DWORD, in void*, DWORD, DWORD, LPCSTR, DWORD, VA_LIST*);
236         HLOCAL LocalFree(HLOCAL);
237     }
238 
239     DWORD MAKELANGID(WORD p, WORD s)
240     {
241          return (((cast(WORD)s) << 10) | cast(WORD)p);
242     }
243 }