| ... | @@ -4,45 +4,79 @@ | ... | @@ -4,45 +4,79 @@ |
| 4 | // The MIT license requires this copyright notice to be included in all copies | 4 | // The MIT license requires this copyright notice to be included in all copies |
| 5 | // and substantial portions of the software. | 5 | // and substantial portions of the software. |
| 6 | usingnamespace @import("bits.zig"); | 6 | usingnamespace @import("bits.zig"); |
| | 7 | const std = @import("std"); |
| | 8 | const builtin = @import("builtin"); |
| | 9 | const assert = std.debug.assert; |
| | 10 | const windows = @import("../windows.zig"); |
| | 11 | const unexpectedError = windows.unexpectedError; |
| | 12 | const GetLastError = windows.kernel32.GetLastError; |
| | 13 | const SetLastError = windows.kernel32.SetLastError; |
| 7 | | 14 | |
| 8 | // PM | 15 | fn selectSymbol(comptime function_static: anytype, function_dynamic: anytype, comptime os: std.Target.Os.WindowsVersion) @TypeOf(function_static) { |
| 9 | pub const PM_REMOVE = 0x0001; | 16 | comptime { |
| 10 | pub const PM_NOREMOVE = 0x0000; | 17 | const sym_ok = builtin.Target.current.os.isAtLeast(.windows, os); |
| 11 | pub const PM_NOYIELD = 0x0002; | 18 | if (sym_ok == true) return function_static; |
| | 19 | if (sym_ok == null) return function_dynamic; |
| | 20 | if (sym_ok == false) @compileError("Target OS range does not support function, at least " ++ @tagName(os) ++ " is required"); |
| | 21 | } |
| | 22 | } |
| | 23 | |
| | 24 | // === Messages === |
| | 25 | |
| | 26 | pub const WNDPROC = fn (hwnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM) callconv(WINAPI) LRESULT; |
| | 27 | |
| | 28 | pub const MSG = extern struct { |
| | 29 | hWnd: ?HWND, |
| | 30 | message: UINT, |
| | 31 | wParam: WPARAM, |
| | 32 | lParam: LPARAM, |
| | 33 | time: DWORD, |
| | 34 | pt: POINT, |
| | 35 | lPrivate: DWORD, |
| | 36 | }; |
| 12 | | 37 | |
| 13 | // WM | | |
| 14 | pub const WM_NULL = 0x0000; | 38 | pub const WM_NULL = 0x0000; |
| 15 | pub const WM_CREATE = 0x0001; | 39 | pub const WM_CREATE = 0x0001; |
| 16 | pub const WM_DESTROY = 0x0002; | 40 | pub const WM_DESTROY = 0x0002; |
| | 41 | pub const WM_NCDESTROY = WM_DESTROY; |
| 17 | pub const WM_MOVE = 0x0003; | 42 | pub const WM_MOVE = 0x0003; |
| 18 | pub const WM_SIZE = 0x0005; | 43 | pub const WM_SIZE = 0x0005; |
| 19 | | | |
| 20 | pub const WM_ACTIVATE = 0x0006; | 44 | pub const WM_ACTIVATE = 0x0006; |
| 21 | pub const WM_PAINT = 0x000F; | | |
| 22 | pub const WM_CLOSE = 0x0010; | | |
| 23 | pub const WM_QUIT = 0x0012; | | |
| 24 | pub const WM_SETFOCUS = 0x0007; | 45 | pub const WM_SETFOCUS = 0x0007; |
| 25 | | | |
| 26 | pub const WM_KILLFOCUS = 0x0008; | 46 | pub const WM_KILLFOCUS = 0x0008; |
| 27 | pub const WM_ENABLE = 0x000A; | 47 | pub const WM_ENABLE = 0x000A; |
| 28 | pub const WM_SETREDRAW = 0x000B; | 48 | pub const WM_SETREDRAW = 0x000B; |
| 29 | | 49 | pub const WM_SETTEXT = 0x000C; |
| 30 | pub const WM_SYSCOLORCHANGE = 0x0015; | 50 | pub const WM_GETTEXT = 0x000D; |
| | 51 | pub const WM_GETTEXTLENGTH = 0x000E; |
| | 52 | pub const WM_PAINT = 0x000F; |
| | 53 | pub const WM_CLOSE = 0x0010; |
| | 54 | pub const WM_QUIT = 0x0012; |
| | 55 | pub const WM_ERASEBKGND = 0x0014; |
| 31 | pub const WM_SHOWWINDOW = 0x0018; | 56 | pub const WM_SHOWWINDOW = 0x0018; |
| 32 | | 57 | pub const WM_CTLCOLOR = 0x0019; |
| 33 | pub const WM_WINDOWPOSCHANGING = 0x0046; | 58 | pub const WM_NEXTDLGCTL = 0x0028; |
| | 59 | pub const WM_DRAWITEM = 0x002B; |
| | 60 | pub const WM_MEASUREITEM = 0x002C; |
| | 61 | pub const WM_DELETEITEM = 0x002D; |
| | 62 | pub const WM_VKEYTOITEM = 0x002E; |
| | 63 | pub const WM_CHARTOITEM = 0x002F; |
| | 64 | pub const WM_SETFONT = 0x0030; |
| | 65 | pub const WM_GETFONT = 0x0031; |
| | 66 | pub const WM_COMPAREITEM = 0x0039; |
| 34 | pub const WM_WINDOWPOSCHANGED = 0x0047; | 67 | pub const WM_WINDOWPOSCHANGED = 0x0047; |
| 35 | pub const WM_POWER = 0x0048; | 68 | pub const WM_NOTIFY = 0x004E; |
| 36 | | 69 | pub const WM_NCCALCSIZE = 0x0083; |
| 37 | pub const WM_CONTEXTMENU = 0x007B; | 70 | pub const WM_NCHITTEST = 0x0084; |
| 38 | pub const WM_STYLECHANGING = 0x007C; | 71 | pub const WM_NCPAINT = 0x0085; |
| 39 | pub const WM_STYLECHANGED = 0x007D; | 72 | pub const WM_GETDLGCODE = 0x0087; |
| 40 | pub const WM_DISPLAYCHANGE = 0x007E; | 73 | pub const WM_NCMOUSEMOVE = 0x00A0; |
| 41 | pub const WM_GETICON = 0x007F; | 74 | pub const WM_NCLBUTTONDOWN = 0x00A1; |
| 42 | pub const WM_SETICON = 0x0080; | 75 | pub const WM_NCLBUTTONUP = 0x00A2; |
| 43 | | 76 | pub const WM_NCLBUTTONDBLCLK = 0x00A3; |
| 44 | pub const WM_INPUT_DEVICE_CHANGE = 0x00fe; | 77 | pub const WM_NCRBUTTONDOWN = 0x00A4; |
| 45 | pub const WM_INPUT = 0x00FF; | 78 | pub const WM_NCRBUTTONUP = 0x00A5; |
| | 79 | pub const WM_NCRBUTTONDBLCLK = 0x00A6; |
| 46 | pub const WM_KEYFIRST = 0x0100; | 80 | pub const WM_KEYFIRST = 0x0100; |
| 47 | pub const WM_KEYDOWN = 0x0100; | 81 | pub const WM_KEYDOWN = 0x0100; |
| 48 | pub const WM_KEYUP = 0x0101; | 82 | pub const WM_KEYUP = 0x0101; |
| ... | @@ -52,13 +86,21 @@ pub const WM_SYSKEYDOWN = 0x0104; | ... | @@ -52,13 +86,21 @@ pub const WM_SYSKEYDOWN = 0x0104; |
| 52 | pub const WM_SYSKEYUP = 0x0105; | 86 | pub const WM_SYSKEYUP = 0x0105; |
| 53 | pub const WM_SYSCHAR = 0x0106; | 87 | pub const WM_SYSCHAR = 0x0106; |
| 54 | pub const WM_SYSDEADCHAR = 0x0107; | 88 | pub const WM_SYSDEADCHAR = 0x0107; |
| 55 | pub const WM_UNICHAR = 0x0109; | 89 | pub const WM_KEYLAST = 0x0108; |
| 56 | pub const WM_KEYLAST = 0x0109; | 90 | pub const WM_INITDIALOG = 0x0110; |
| 57 | | | |
| 58 | pub const WM_COMMAND = 0x0111; | 91 | pub const WM_COMMAND = 0x0111; |
| 59 | pub const WM_SYSCOMMAND = 0x0112; | 92 | pub const WM_SYSCOMMAND = 0x0112; |
| 60 | pub const WM_TIMER = 0x0113; | 93 | pub const WM_TIMER = 0x0113; |
| 61 | | 94 | pub const WM_HSCROLL = 0x0114; |
| | 95 | pub const WM_VSCROLL = 0x0115; |
| | 96 | pub const WM_ENTERIDLE = 0x0121; |
| | 97 | pub const WM_CTLCOLORMSGBOX = 0x0132; |
| | 98 | pub const WM_CTLCOLOREDIT = 0x0133; |
| | 99 | pub const WM_CTLCOLORLISTBOX = 0x0134; |
| | 100 | pub const WM_CTLCOLORBTN = 0x0135; |
| | 101 | pub const WM_CTLCOLORDLG = 0x0136; |
| | 102 | pub const WM_CTLCOLORSCROLLBAR = 0x0137; |
| | 103 | pub const WM_CTLCOLORSTATIC = 0x0138; |
| 62 | pub const WM_MOUSEFIRST = 0x0200; | 104 | pub const WM_MOUSEFIRST = 0x0200; |
| 63 | pub const WM_MOUSEMOVE = 0x0200; | 105 | pub const WM_MOUSEMOVE = 0x0200; |
| 64 | pub const WM_LBUTTONDOWN = 0x0201; | 106 | pub const WM_LBUTTONDOWN = 0x0201; |
| ... | @@ -71,105 +113,561 @@ pub const WM_MBUTTONDOWN = 0x0207; | ... | @@ -71,105 +113,561 @@ pub const WM_MBUTTONDOWN = 0x0207; |
| 71 | pub const WM_MBUTTONUP = 0x0208; | 113 | pub const WM_MBUTTONUP = 0x0208; |
| 72 | pub const WM_MBUTTONDBLCLK = 0x0209; | 114 | pub const WM_MBUTTONDBLCLK = 0x0209; |
| 73 | pub const WM_MOUSEWHEEL = 0x020A; | 115 | pub const WM_MOUSEWHEEL = 0x020A; |
| 74 | pub const WM_XBUTTONDOWN = 0x020B; | 116 | pub const WM_MOUSELAST = 0x020A; |
| 75 | pub const WM_XBUTTONUP = 0x020C; | 117 | pub const WM_HOTKEY = 0x0312; |
| 76 | pub const WM_XBUTTONDBLCLK = 0x020D; | 118 | pub const WM_CARET_CREATE = 0x03E0; |
| | 119 | pub const WM_CARET_DESTROY = 0x03E1; |
| | 120 | pub const WM_CARET_BLINK = 0x03E2; |
| | 121 | pub const WM_FDINPUT = 0x03F0; |
| | 122 | pub const WM_FDOUTPUT = 0x03F1; |
| | 123 | pub const WM_FDEXCEPT = 0x03F2; |
| | 124 | pub const WM_USER = 0x0400; |
| 77 | | 125 | |
| 78 | // WA | 126 | pub extern "user32" fn GetMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) callconv(WINAPI) BOOL; |
| 79 | pub const WA_INACTIVE = 0; | 127 | pub fn getMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax: u32) !void { |
| 80 | pub const WA_ACTIVE = 0x0006; | 128 | const r = GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); |
| | 129 | if (r == 0) return error.Quit; |
| | 130 | if (r != -1) return; |
| | 131 | return switch (GetLastError()) { |
| | 132 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 133 | .INVALID_PARAMETER => unreachable, |
| | 134 | else => |err| return windows.unexpectedError(err), |
| | 135 | }; |
| | 136 | } |
| 81 | | 137 | |
| 82 | // WS | 138 | pub extern "user32" fn GetMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) callconv(WINAPI) BOOL; |
| 83 | pub const WS_OVERLAPPED = 0x00000000; | 139 | pub var pfnGetMessageW: @TypeOf(GetMessageW) = undefined; |
| 84 | pub const WS_CAPTION = 0x00C00000; | 140 | pub fn getMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax: u32) !void { |
| 85 | pub const WS_SYSMENU = 0x00080000; | 141 | const function = selectSymbol(GetMessageW, pfnGetMessageW, .win2k); |
| 86 | pub const WS_THICKFRAME = 0x00040000; | | |
| 87 | pub const WS_MINIMIZEBOX = 0x00020000; | | |
| 88 | pub const WS_MAXIMIZEBOX = 0x00010000; | | |
| 89 | | 142 | |
| 90 | // PFD | 143 | const r = function(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); |
| 91 | pub const PFD_DRAW_TO_WINDOW = 0x00000004; | 144 | if (r == 0) return error.Quit; |
| 92 | pub const PFD_SUPPORT_OPENGL = 0x00000020; | 145 | if (r != -1) return; |
| 93 | pub const PFD_DOUBLEBUFFER = 0x00000001; | 146 | return switch (GetLastError()) { |
| 94 | pub const PFD_MAIN_PLANE = 0; | 147 | .INVALID_WINDOW_HANDLE => unreachable, |
| 95 | pub const PFD_TYPE_RGBA = 0; | 148 | .INVALID_PARAMETER => unreachable, |
| | 149 | else => |err| return windows.unexpectedError(err), |
| | 150 | }; |
| | 151 | } |
| 96 | | 152 | |
| 97 | // CS | 153 | pub const PM_NOREMOVE = 0x0000; |
| 98 | pub const CS_HREDRAW = 0x0002; | 154 | pub const PM_REMOVE = 0x0001; |
| 99 | pub const CS_VREDRAW = 0x0001; | 155 | pub const PM_NOYIELD = 0x0002; |
| 100 | pub const CS_OWNDC = 0x0020; | | |
| 101 | | 156 | |
| 102 | // SW | 157 | pub extern "user32" fn PeekMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) callconv(WINAPI) BOOL; |
| 103 | pub const SW_HIDE = 0; | 158 | pub fn peekMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax: u32, wRemoveMsg: u32) !bool { |
| 104 | pub const SW_SHOW = 5; | 159 | const r = PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); |
| | 160 | if (r == 0) return false; |
| | 161 | if (r != -1) return true; |
| | 162 | return switch (GetLastError()) { |
| | 163 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 164 | .INVALID_PARAMETER => unreachable, |
| | 165 | else => |err| return windows.unexpectedError(err), |
| | 166 | }; |
| | 167 | } |
| | 168 | |
| | 169 | pub extern "user32" fn PeekMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) callconv(WINAPI) BOOL; |
| | 170 | pub var pfnPeekMessageW: @TypeOf(PeekMessageW) = undefined; |
| | 171 | pub fn peekMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax: u32, wRemoveMsg: u32) !bool { |
| | 172 | const function = selectSymbol(PeekMessageW, pfnPeekMessageW, .win2k); |
| | 173 | |
| | 174 | const r = function(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg); |
| | 175 | if (r == 0) return false; |
| | 176 | if (r != -1) return true; |
| | 177 | return switch (GetLastError()) { |
| | 178 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 179 | .INVALID_PARAMETER => unreachable, |
| | 180 | else => |err| return windows.unexpectedError(err), |
| | 181 | }; |
| | 182 | } |
| | 183 | |
| | 184 | pub extern "user32" fn TranslateMessage(lpMsg: *const MSG) callconv(WINAPI) BOOL; |
| | 185 | pub fn translateMessage(lpMsg: *const MSG) bool { |
| | 186 | return if (TranslateMessage(lpMsg) == 0) false else true; |
| | 187 | } |
| | 188 | |
| | 189 | pub extern "user32" fn DispatchMessageA(lpMsg: *const MSG) callconv(WINAPI) LRESULT; |
| | 190 | pub fn dispatchMessageA(lpMsg: *const MSG) LRESULT { |
| | 191 | return DispatchMessageA(lpMsg); |
| | 192 | } |
| | 193 | |
| | 194 | pub extern "user32" fn DispatchMessageW(lpMsg: *const MSG) callconv(WINAPI) LRESULT; |
| | 195 | pub var pfnDispatchMessageW: @TypeOf(DispatchMessageW) = undefined; |
| | 196 | pub fn dispatchMessageW(lpMsg: *const MSG) LRESULT { |
| | 197 | const function = selectSymbol(DispatchMessageW, pfnDispatchMessageW, .win2k); |
| | 198 | return function(lpMsg); |
| | 199 | } |
| 105 | | 200 | |
| 106 | pub const WNDPROC = fn (HWND, UINT, WPARAM, LPARAM) callconv(WINAPI) LRESULT; | 201 | pub extern "user32" fn PostQuitMessage(nExitCode: i32) callconv(WINAPI) void; |
| | 202 | pub fn postQuitMessage(nExitCode: i32) void { |
| | 203 | PostQuitMessage(nExitCode); |
| | 204 | } |
| | 205 | |
| | 206 | pub extern "user32" fn DefWindowProcA(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) callconv(WINAPI) LRESULT; |
| | 207 | pub fn defWindowProcA(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) LRESULT { |
| | 208 | return DefWindowProcA(hWnd, Msg, wParam, lParam); |
| | 209 | } |
| | 210 | |
| | 211 | pub extern "user32" fn DefWindowProcW(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) callconv(WINAPI) LRESULT; |
| | 212 | pub var pfnDefWindowProcW: @TypeOf(DefWindowProcW) = undefined; |
| | 213 | pub fn defWindowProcW(hWnd: HWND, Msg: UINT, wParam: WPARAM, lParam: LPARAM) LRESULT { |
| | 214 | const function = selectSymbol(DefWindowProcW, pfnDefWindowProcW, .win2k); |
| | 215 | return function(hWnd, Msg, wParam, lParam); |
| | 216 | } |
| | 217 | |
| | 218 | // === Windows === |
| | 219 | |
| | 220 | pub const CS_VREDRAW = 0x0001; |
| | 221 | pub const CS_HREDRAW = 0x0002; |
| | 222 | pub const CS_DBLCLKS = 0x0008; |
| | 223 | pub const CS_OWNDC = 0x0020; |
| | 224 | pub const CS_CLASSDC = 0x0040; |
| | 225 | pub const CS_PARENTDC = 0x0080; |
| | 226 | pub const CS_NOCLOSE = 0x0200; |
| | 227 | pub const CS_SAVEBITS = 0x0800; |
| | 228 | pub const CS_BYTEALIGNCLIENT = 0x1000; |
| | 229 | pub const CS_BYTEALIGNWINDOW = 0x2000; |
| | 230 | pub const CS_GLOBALCLASS = 0x4000; |
| 107 | | 231 | |
| 108 | pub const WNDCLASSEXA = extern struct { | 232 | pub const WNDCLASSEXA = extern struct { |
| 109 | cbSize: UINT = @sizeOf(WNDCLASSEXA), | 233 | cbSize: UINT = @sizeOf(WNDCLASSEXA), |
| 110 | style: UINT, | 234 | style: UINT, |
| 111 | lpfnWndProc: WNDPROC, | 235 | lpfnWndProc: WNDPROC, |
| 112 | cbClsExtra: i32, | 236 | cbClsExtra: i32 = 0, |
| 113 | cbWndExtra: i32, | 237 | cbWndExtra: i32 = 0, |
| 114 | hInstance: HINSTANCE, | 238 | hInstance: HINSTANCE, |
| 115 | hIcon: ?HICON, | 239 | hIcon: ?HICON, |
| 116 | hCursor: ?HCURSOR, | 240 | hCursor: ?HCURSOR, |
| 117 | hbrBackground: ?HBRUSH, | 241 | hbrBackground: ?HBRUSH, |
| 118 | lpszMenuName: ?LPCSTR, | 242 | lpszMenuName: ?[*:0]const u8, |
| 119 | lpszClassName: LPCSTR, | 243 | lpszClassName: [*:0]const u8, |
| 120 | hIconSm: ?HICON, | 244 | hIconSm: ?HICON, |
| 121 | }; | 245 | }; |
| 122 | | 246 | |
| 123 | pub const POINT = extern struct { | 247 | pub const WNDCLASSEXW = extern struct { |
| 124 | x: c_long, y: c_long | 248 | cbSize: UINT = @sizeOf(WNDCLASSEXW), |
| | 249 | style: UINT, |
| | 250 | lpfnWndProc: WNDPROC, |
| | 251 | cbClsExtra: i32 = 0, |
| | 252 | cbWndExtra: i32 = 0, |
| | 253 | hInstance: HINSTANCE, |
| | 254 | hIcon: ?HICON, |
| | 255 | hCursor: ?HCURSOR, |
| | 256 | hbrBackground: ?HBRUSH, |
| | 257 | lpszMenuName: ?[*:0]const u16, |
| | 258 | lpszClassName: [*:0]const u16, |
| | 259 | hIconSm: ?HICON, |
| 125 | }; | 260 | }; |
| 126 | | 261 | |
| 127 | pub const MSG = extern struct { | 262 | pub extern "user32" fn RegisterClassExA(*const WNDCLASSEXA) callconv(WINAPI) ATOM; |
| 128 | hWnd: ?HWND, | 263 | pub fn registerClassExA(window_class: *const WNDCLASSEXA) !ATOM { |
| 129 | message: UINT, | 264 | const atom = RegisterClassExA(window_class); |
| 130 | wParam: WPARAM, | 265 | if (atom != 0) return atom; |
| 131 | lParam: LPARAM, | 266 | return switch (GetLastError()) { |
| 132 | time: DWORD, | 267 | .CLASS_ALREADY_EXISTS => error.AlreadyExists, |
| 133 | pt: POINT, | 268 | .INVALID_PARAMETER => unreachable, |
| 134 | lPrivate: DWORD, | 269 | else => |err| return windows.unexpectedError(err), |
| 135 | }; | 270 | }; |
| | 271 | } |
| 136 | | 272 | |
| 137 | pub extern "user32" fn CreateWindowExA( | 273 | pub extern "user32" fn RegisterClassExW(*const WNDCLASSEXW) callconv(WINAPI) ATOM; |
| 138 | dwExStyle: DWORD, | 274 | pub var pfnRegisterClassExW: @TypeOf(RegisterClassExW) = undefined; |
| 139 | lpClassName: LPCSTR, | 275 | pub fn registerClassExW(window_class: *const WNDCLASSEXA) !ATOM { |
| 140 | lpWindowName: LPCSTR, | 276 | const function = selectSymbol(RegisterClassExW, pfnRegisterClassExW, .win2k); |
| 141 | dwStyle: DWORD, | 277 | const atom = function(window_class); |
| 142 | X: i32, | 278 | if (atom != 0) return atom; |
| 143 | Y: i32, | 279 | return switch (GetLastError()) { |
| 144 | nWidth: i32, | 280 | .CLASS_ALREADY_EXISTS => error.AlreadyExists, |
| 145 | nHeight: i32, | 281 | .CALL_NOT_IMPLEMENTED => unreachable, |
| 146 | hWindParent: ?HWND, | 282 | .INVALID_PARAMETER => unreachable, |
| 147 | hMenu: ?HMENU, | 283 | else => |err| return windows.unexpectedError(err), |
| 148 | hInstance: HINSTANCE, | 284 | }; |
| 149 | lpParam: ?LPVOID, | 285 | } |
| 150 | ) callconv(WINAPI) ?HWND; | 286 | |
| | 287 | pub extern "user32" fn UnregisterClassA(lpClassName: LPCSTR, hInstance: HINSTANCE) callconv(.Stdcall) BOOL; |
| | 288 | pub fn unregisterClassA(lpClassName: [*:0]const u8, hInstance: HINSTANCE) !void { |
| | 289 | if (UnregisterClassA(lpClassName, hInstance) == 0) { |
| | 290 | return switch (GetLastError()) { |
| | 291 | .CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist, |
| | 292 | else => |err| return windows.unexpectedError(err), |
| | 293 | }; |
| | 294 | } |
| | 295 | } |
| | 296 | |
| | 297 | pub extern "user32" fn UnregisterClassW(lpClassName: LPCWSTR, hInstance: HINSTANCE) callconv(.Stdcall) BOOL; |
| | 298 | pub var pfnUnregisterClassW: @TypeOf(UnregisterClassW) = undefined; |
| | 299 | pub fn unregisterClassW(lpClassName: [*:0]const u16, hInstance: HINSTANCE) !void { |
| | 300 | const function = selectSymbol(UnregisterClassW, pfnUnregisterClassW, .win2k); |
| | 301 | if (function(lpClassName, hInstance) == 0) { |
| | 302 | return switch (GetLastError()) { |
| | 303 | .CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist, |
| | 304 | else => |err| return windows.unexpectedError(err), |
| | 305 | }; |
| | 306 | } |
| | 307 | } |
| | 308 | |
| | 309 | pub const WS_OVERLAPPED = 0x00000000; |
| | 310 | pub const WS_POPUP = 0x80000000; |
| | 311 | pub const WS_CHILD = 0x40000000; |
| | 312 | pub const WS_MINIMIZE = 0x20000000; |
| | 313 | pub const WS_VISIBLE = 0x10000000; |
| | 314 | pub const WS_DISABLED = 0x08000000; |
| | 315 | pub const WS_CLIPSIBLINGS = 0x04000000; |
| | 316 | pub const WS_CLIPCHILDREN = 0x02000000; |
| | 317 | pub const WS_MAXIMIZE = 0x01000000; |
| | 318 | pub const WS_CAPTION = WS_BORDER | WS_DLGFRAME; |
| | 319 | pub const WS_BORDER = 0x00800000; |
| | 320 | pub const WS_DLGFRAME = 0x00400000; |
| | 321 | pub const WS_VSCROLL = 0x00200000; |
| | 322 | pub const WS_HSCROLL = 0x00100000; |
| | 323 | pub const WS_SYSMENU = 0x00080000; |
| | 324 | pub const WS_THICKFRAME = 0x00040000; |
| | 325 | pub const WS_GROUP = 0x00020000; |
| | 326 | pub const WS_TABSTOP = 0x00010000; |
| | 327 | pub const WS_MINIMIZEBOX = 0x00020000; |
| | 328 | pub const WS_MAXIMIZEBOX = 0x00010000; |
| | 329 | pub const WS_TILED = WS_OVERLAPPED; |
| | 330 | pub const WS_ICONIC = WS_MINIMIZE; |
| | 331 | pub const WS_SIZEBOX = WS_THICKFRAME; |
| | 332 | pub const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW; |
| | 333 | pub const WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX; |
| | 334 | pub const WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU; |
| | 335 | pub const WS_CHILDWINDOW = WS_CHILD; |
| | 336 | |
| | 337 | pub const WS_EX_DLGMODALFRAME = 0x00000001; |
| | 338 | pub const WS_EX_NOPARENTNOTIFY = 0x00000004; |
| | 339 | pub const WS_EX_TOPMOST = 0x00000008; |
| | 340 | pub const WS_EX_ACCEPTFILES = 0x00000010; |
| | 341 | pub const WS_EX_TRANSPARENT = 0x00000020; |
| | 342 | pub const WS_EX_MDICHILD = 0x00000040; |
| | 343 | pub const WS_EX_TOOLWINDOW = 0x00000080; |
| | 344 | pub const WS_EX_WINDOWEDGE = 0x00000100; |
| | 345 | pub const WS_EX_CLIENTEDGE = 0x00000200; |
| | 346 | pub const WS_EX_CONTEXTHELP = 0x00000400; |
| | 347 | pub const WS_EX_RIGHT = 0x00001000; |
| | 348 | pub const WS_EX_LEFT = 0x00000000; |
| | 349 | pub const WS_EX_RTLREADING = 0x00002000; |
| | 350 | pub const WS_EX_LTRREADING = 0x00000000; |
| | 351 | pub const WS_EX_LEFTSCROLLBAR = 0x00004000; |
| | 352 | pub const WS_EX_RIGHTSCROLLBAR = 0x00000000; |
| | 353 | pub const WS_EX_CONTROLPARENT = 0x00010000; |
| | 354 | pub const WS_EX_STATICEDGE = 0x00020000; |
| | 355 | pub const WS_EX_APPWINDOW = 0x00040000; |
| | 356 | pub const WS_EX_LAYERED = 0x00080000; |
| | 357 | pub const WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE); |
| | 358 | pub const WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST); |
| | 359 | |
| | 360 | pub const CW_USEDEFAULT = @bitCast(i32, @as(u32, 0x80000000)); |
| | 361 | |
| | 362 | pub extern "user32" fn CreateWindowExA(dwExStyle: DWORD, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND; |
| | 363 | pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName: [*:0]const u8, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*c_void) !HWND { |
| | 364 | const window = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWindParent, hMenu, hInstance, lpParam); |
| | 365 | if (window) |win| return win; |
| | 366 | |
| | 367 | return switch (GetLastError()) { |
| | 368 | .CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist, |
| | 369 | .INVALID_PARAMETER => unreachable, |
| | 370 | else => |err| return windows.unexpectedError(err), |
| | 371 | }; |
| | 372 | } |
| | 373 | |
| | 374 | pub extern "user32" fn CreateWindowExW(dwExStyle: DWORD, lpClassName: [*:0]const u16, lpWindowName: [*:0]const u16, dwStyle: DWORD, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?LPVOID) callconv(WINAPI) ?HWND; |
| | 375 | pub var pfnCreateWindowExW: @TypeOf(RegisterClassExW) = undefined; |
| | 376 | pub fn createWindowExW(dwExStyle: u32, lpClassName: [*:0]const u16, lpWindowName: [*:0]const u16, dwStyle: u32, X: i32, Y: i32, nWidth: i32, nHeight: i32, hWindParent: ?HWND, hMenu: ?HMENU, hInstance: HINSTANCE, lpParam: ?*c_void) !HWND { |
| | 377 | const function = selectSymbol(CreateWindowExW, pfnCreateWindowExW, .win2k); |
| | 378 | const window = function(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWindParent, hMenu, hInstance, lpParam); |
| | 379 | if (window) |win| return win; |
| | 380 | |
| | 381 | return switch (GetLastError()) { |
| | 382 | .CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist, |
| | 383 | .INVALID_PARAMETER => unreachable, |
| | 384 | else => |err| return windows.unexpectedError(err), |
| | 385 | }; |
| | 386 | } |
| | 387 | |
| | 388 | pub extern "user32" fn DestroyWindow(hWnd: HWND) callconv(WINAPI) BOOL; |
| | 389 | pub fn destroyWindow(hWnd: HWND) !void { |
| | 390 | if (DestroyWindow(hWnd) == 0) { |
| | 391 | return switch (GetLastError()) { |
| | 392 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 393 | .INVALID_PARAMETER => unreachable, |
| | 394 | else => |err| return windows.unexpectedError(err), |
| | 395 | }; |
| | 396 | } |
| | 397 | } |
| | 398 | |
| | 399 | pub const SW_HIDE = 0; |
| | 400 | pub const SW_SHOWNORMAL = 1; |
| | 401 | pub const SW_NORMAL = 1; |
| | 402 | pub const SW_SHOWMINIMIZED = 2; |
| | 403 | pub const SW_SHOWMAXIMIZED = 3; |
| | 404 | pub const SW_MAXIMIZE = 3; |
| | 405 | pub const SW_SHOWNOACTIVATE = 4; |
| | 406 | pub const SW_SHOW = 5; |
| | 407 | pub const SW_MINIMIZE = 6; |
| | 408 | pub const SW_SHOWMINNOACTIVE = 7; |
| | 409 | pub const SW_SHOWNA = 8; |
| | 410 | pub const SW_RESTORE = 9; |
| | 411 | pub const SW_SHOWDEFAULT = 10; |
| | 412 | pub const SW_FORCEMINIMIZE = 11; |
| | 413 | pub const SW_MAX = 11; |
| | 414 | |
| | 415 | pub extern "user32" fn ShowWindow(hWnd: HWND, nCmdShow: i32) callconv(WINAPI) BOOL; |
| | 416 | pub fn showWindow(hWnd: HWND, nCmdShow: i32) bool { |
| | 417 | return (ShowWindow(hWnd, nCmdShow) == TRUE); |
| | 418 | } |
| | 419 | |
| | 420 | pub extern "user32" fn UpdateWindow(hWnd: HWND) callconv(WINAPI) BOOL; |
| | 421 | pub fn updateWindow(hWnd: HWND) !void { |
| | 422 | if (ShowWindow(hWnd, nCmdShow) == 0) { |
| | 423 | return switch (GetLastError()) { |
| | 424 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 425 | .INVALID_PARAMETER => unreachable, |
| | 426 | else => |err| return windows.unexpectedError(err), |
| | 427 | }; |
| | 428 | } |
| | 429 | } |
| | 430 | |
| | 431 | pub extern "user32" fn AdjustWindowRectEx(lpRect: *RECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD) callconv(WINAPI) BOOL; |
| | 432 | pub fn adjustWindowRectEx(lpRect: *RECT, dwStyle: u32, bMenu: bool, dwExStyle: u32) !void { |
| | 433 | assert(dwStyle & WS_OVERLAPPED == 0); |
| | 434 | |
| | 435 | if (AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle) == 0) { |
| | 436 | return switch (GetLastError()) { |
| | 437 | .INVALID_PARAMETER => unreachable, |
| | 438 | else => |err| return windows.unexpectedError(err), |
| | 439 | }; |
| | 440 | } |
| | 441 | } |
| | 442 | |
| | 443 | pub const GWL_WNDPROC = -4; |
| | 444 | pub const GWL_HINSTANCE = -6; |
| | 445 | pub const GWL_HWNDPARENT = -8; |
| | 446 | pub const GWL_STYLE = -16; |
| | 447 | pub const GWL_EXSTYLE = -20; |
| | 448 | pub const GWL_USERDATA = -21; |
| | 449 | pub const GWL_ID = -12; |
| | 450 | |
| | 451 | pub extern "user32" fn GetWindowLongA(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG; |
| | 452 | pub fn getWindowLongA(hWnd: HWND, nIndex: i32) !i32 { |
| | 453 | const value = GetWindowLongA(hWnd, nIndex); |
| | 454 | if (value != 0) return value; |
| | 455 | |
| | 456 | return switch (GetLastError()) { |
| | 457 | .SUCCESS => 0, |
| | 458 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 459 | .INVALID_PARAMETER => unreachable, |
| | 460 | else => |err| return windows.unexpectedError(err), |
| | 461 | }; |
| | 462 | } |
| | 463 | |
| | 464 | pub extern "user32" fn GetWindowLongW(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG; |
| | 465 | pub var pfnGetWindowLongW: @TypeOf(GetWindowLongW) = undefined; |
| | 466 | pub fn getWindowLongW(hWnd: HWND, nIndex: i32) !i32 { |
| | 467 | const function = selectSymbol(GetWindowLongW, pfnGetWindowLongW, .win2k); |
| | 468 | |
| | 469 | const value = function(hWnd, nIndex); |
| | 470 | if (value != 0) return value; |
| | 471 | |
| | 472 | return switch (GetLastError()) { |
| | 473 | .SUCCESS => 0, |
| | 474 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 475 | .INVALID_PARAMETER => unreachable, |
| | 476 | else => |err| return windows.unexpectedError(err), |
| | 477 | }; |
| | 478 | } |
| | 479 | |
| | 480 | pub extern "user32" fn GetWindowLongPtrA(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG_PTR; |
| | 481 | pub fn getWindowLongPtrA(hWnd: HWND, nIndex: i32) !isize { |
| | 482 | // "When compiling for 32-bit Windows, GetWindowLongPtr is defined as a call to the GetWindowLong function." |
| | 483 | // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw |
| | 484 | if (@sizeOf(LONG_PTR) == 4) return getWindowLongA(hWnd, nIndex); |
| | 485 | |
| | 486 | const value = GetWindowLongPtrA(hWnd, nIndex); |
| | 487 | if (value != 0) return value; |
| | 488 | |
| | 489 | return switch (GetLastError()) { |
| | 490 | .SUCCESS => 0, |
| | 491 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 492 | .INVALID_PARAMETER => unreachable, |
| | 493 | else => |err| return windows.unexpectedError(err), |
| | 494 | }; |
| | 495 | } |
| | 496 | |
| | 497 | pub extern "user32" fn GetWindowLongPtrW(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG_PTR; |
| | 498 | pub var pfnGetWindowLongPtrW: @TypeOf(GetWindowLongPtrW) = undefined; |
| | 499 | pub fn getWindowLongPtrW(hWnd: HWND, nIndex: i32) !isize { |
| | 500 | if (@sizeOf(LONG_PTR) == 4) return getWindowLongW(hWnd, nIndex); |
| | 501 | const function = selectSymbol(GetWindowLongPtrW, pfnGetWindowLongPtrW, .win2k); |
| | 502 | |
| | 503 | const value = function(hWnd, nIndex); |
| | 504 | if (value != 0) return value; |
| | 505 | |
| | 506 | return switch (GetLastError()) { |
| | 507 | .SUCCESS => 0, |
| | 508 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 509 | .INVALID_PARAMETER => unreachable, |
| | 510 | else => |err| return windows.unexpectedError(err), |
| | 511 | }; |
| | 512 | } |
| | 513 | |
| | 514 | pub extern "user32" fn SetWindowLongA(hWnd: HWND, nIndex: i32, dwNewLong: LONG) callconv(WINAPI) LONG; |
| | 515 | pub fn setWindowLongA(hWnd: HWND, nIndex: i32, dwNewLong: i32) !i32 { |
| | 516 | // [...] you should clear the last error information by calling SetLastError with 0 before calling SetWindowLong. |
| | 517 | // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowlonga |
| | 518 | SetLastError(.SUCCESS); |
| | 519 | |
| | 520 | const value = SetWindowLongA(hWnd, nIndex, dwNewLong); |
| | 521 | if (value != 0) return value; |
| | 522 | |
| | 523 | return switch (GetLastError()) { |
| | 524 | .SUCCESS => 0, |
| | 525 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 526 | .INVALID_PARAMETER => unreachable, |
| | 527 | else => |err| return windows.unexpectedError(err), |
| | 528 | }; |
| | 529 | } |
| | 530 | |
| | 531 | pub extern "user32" fn SetWindowLongW(hWnd: HWND, nIndex: i32, dwNewLong: LONG) callconv(WINAPI) LONG; |
| | 532 | pub var pfnSetWindowLongW: @TypeOf(SetWindowLongW) = undefined; |
| | 533 | pub fn setWindowLongW(hWnd: HWND, nIndex: i32, dwNewLong: i32) !i32 { |
| | 534 | const function = selectSymbol(SetWindowLongW, pfnSetWindowLongW, .win2k); |
| | 535 | |
| | 536 | SetLastError(.SUCCESS); |
| | 537 | const value = function(hWnd, nIndex, dwNewLong); |
| | 538 | if (value != 0) return value; |
| | 539 | |
| | 540 | return switch (GetLastError()) { |
| | 541 | .SUCCESS => 0, |
| | 542 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 543 | .INVALID_PARAMETER => unreachable, |
| | 544 | else => |err| return windows.unexpectedError(err), |
| | 545 | }; |
| | 546 | } |
| | 547 | |
| | 548 | pub extern "user32" fn SetWindowLongPtrA(hWnd: HWND, nIndex: i32, dwNewLong: LONG_PTR) callconv(WINAPI) LONG_PTR; |
| | 549 | pub fn setWindowLongPtrA(hWnd: HWND, nIndex: i32, dwNewLong: isize) !isize { |
| | 550 | // "When compiling for 32-bit Windows, GetWindowLongPtr is defined as a call to the GetWindowLong function." |
| | 551 | // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptrw |
| | 552 | if (@sizeOf(LONG_PTR) == 4) return setWindowLongA(hWnd, nIndex, dwNewLong); |
| | 553 | |
| | 554 | SetLastError(.SUCCESS); |
| | 555 | const value = SetWindowLongPtrA(hWnd, nIndex, dwNewLong); |
| | 556 | if (value != 0) return value; |
| | 557 | |
| | 558 | return switch (GetLastError()) { |
| | 559 | .SUCCESS => 0, |
| | 560 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 561 | .INVALID_PARAMETER => unreachable, |
| | 562 | else => |err| return windows.unexpectedError(err), |
| | 563 | }; |
| | 564 | } |
| | 565 | |
| | 566 | pub extern "user32" fn SetWindowLongPtrW(hWnd: HWND, nIndex: i32, dwNewLong: LONG_PTR) callconv(WINAPI) LONG_PTR; |
| | 567 | pub var pfnSetWindowLongPtrW: @TypeOf(SetWindowLongPtrW) = undefined; |
| | 568 | pub fn setWindowLongPtrW(hWnd: HWND, nIndex: i32, dwNewLong: isize) !isize { |
| | 569 | if (@sizeOf(LONG_PTR) == 4) return setWindowLongW(hWnd, nIndex, dwNewLong); |
| | 570 | const function = selectSymbol(SetWindowLongPtrW, pfnSetWindowLongPtrW, .win2k); |
| | 571 | |
| | 572 | SetLastError(.SUCCESS); |
| | 573 | const value = function(hWnd, nIndex, dwNewLong); |
| | 574 | if (value != 0) return value; |
| | 575 | |
| | 576 | return switch (GetLastError()) { |
| | 577 | .SUCCESS => 0, |
| | 578 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 579 | .INVALID_PARAMETER => unreachable, |
| | 580 | else => |err| return windows.unexpectedError(err), |
| | 581 | }; |
| | 582 | } |
| 151 | | 583 | |
| 152 | pub extern "user32" fn RegisterClassExA(*const WNDCLASSEXA) callconv(WINAPI) c_ushort; | | |
| 153 | pub extern "user32" fn DefWindowProcA(HWND, Msg: UINT, WPARAM, LPARAM) callconv(WINAPI) LRESULT; | | |
| 154 | pub extern "user32" fn ShowWindow(hWnd: ?HWND, nCmdShow: i32) callconv(WINAPI) bool; | | |
| 155 | pub extern "user32" fn UpdateWindow(hWnd: ?HWND) callconv(WINAPI) bool; | | |
| 156 | pub extern "user32" fn GetDC(hWnd: ?HWND) callconv(WINAPI) ?HDC; | 584 | pub extern "user32" fn GetDC(hWnd: ?HWND) callconv(WINAPI) ?HDC; |
| | 585 | pub fn getDC(hWnd: ?HWND) !HDC { |
| | 586 | const hdc = GetDC(hWnd); |
| | 587 | if (hdc) |h| return h; |
| 157 | | 588 | |
| 158 | pub extern "user32" fn PeekMessageA( | 589 | return switch (GetLastError()) { |
| 159 | lpMsg: ?*MSG, | 590 | .INVALID_WINDOW_HANDLE => unreachable, |
| 160 | hWnd: ?HWND, | 591 | .INVALID_PARAMETER => unreachable, |
| 161 | wMsgFilterMin: UINT, | 592 | else => |err| return windows.unexpectedError(err), |
| 162 | wMsgFilterMax: UINT, | 593 | }; |
| 163 | wRemoveMsg: UINT, | 594 | } |
| 164 | ) callconv(WINAPI) bool; | | |
| 165 | | 595 | |
| 166 | pub extern "user32" fn GetMessageA( | 596 | pub extern "user32" fn ReleaseDC(hWnd: ?HWND, hDC: HDC) callconv(WINAPI) i32; |
| 167 | lpMsg: ?*MSG, | 597 | pub fn releaseDC(hWnd: ?HWND, hDC: HDC) bool { |
| 168 | hWnd: ?HWND, | 598 | return if (ReleaseDC(hWnd, hDC) == 1) true else false; |
| 169 | wMsgFilterMin: UINT, | 599 | } |
| 170 | wMsgFilterMax: UINT, | | |
| 171 | ) callconv(WINAPI) bool; | | |
| 172 | | 600 | |
| 173 | pub extern "user32" fn TranslateMessage(lpMsg: *const MSG) callconv(WINAPI) bool; | 601 | // === Modal dialogue boxes === |
| 174 | pub extern "user32" fn DispatchMessageA(lpMsg: *const MSG) callconv(WINAPI) LRESULT; | 602 | |
| 175 | pub extern "user32" fn PostQuitMessage(nExitCode: i32) callconv(WINAPI) void; | 603 | pub const MB_OK = 0x00000000; |
| | 604 | pub const MB_OKCANCEL = 0x00000001; |
| | 605 | pub const MB_ABORTRETRYIGNORE = 0x00000002; |
| | 606 | pub const MB_YESNOCANCEL = 0x00000003; |
| | 607 | pub const MB_YESNO = 0x00000004; |
| | 608 | pub const MB_RETRYCANCEL = 0x00000005; |
| | 609 | pub const MB_CANCELTRYCONTINUE = 0x00000006; |
| | 610 | pub const MB_ICONHAND = 0x00000010; |
| | 611 | pub const MB_ICONQUESTION = 0x00000020; |
| | 612 | pub const MB_ICONEXCLAMATION = 0x00000030; |
| | 613 | pub const MB_ICONASTERISK = 0x00000040; |
| | 614 | pub const MB_USERICON = 0x00000080; |
| | 615 | pub const MB_ICONWARNING = MB_ICONEXCLAMATION; |
| | 616 | pub const MB_ICONERROR = MB_ICONHAND; |
| | 617 | pub const MB_ICONINFORMATION = MB_ICONASTERISK; |
| | 618 | pub const MB_ICONSTOP = MB_ICONHAND; |
| | 619 | pub const MB_DEFBUTTON1 = 0x00000000; |
| | 620 | pub const MB_DEFBUTTON2 = 0x00000100; |
| | 621 | pub const MB_DEFBUTTON3 = 0x00000200; |
| | 622 | pub const MB_DEFBUTTON4 = 0x00000300; |
| | 623 | pub const MB_APPLMODAL = 0x00000000; |
| | 624 | pub const MB_SYSTEMMODAL = 0x00001000; |
| | 625 | pub const MB_TASKMODAL = 0x00002000; |
| | 626 | pub const MB_HELP = 0x00004000; |
| | 627 | pub const MB_NOFOCUS = 0x00008000; |
| | 628 | pub const MB_SETFOREGROUND = 0x00010000; |
| | 629 | pub const MB_DEFAULT_DESKTOP_ONLY = 0x00020000; |
| | 630 | pub const MB_TOPMOST = 0x00040000; |
| | 631 | pub const MB_RIGHT = 0x00080000; |
| | 632 | pub const MB_RTLREADING = 0x00100000; |
| | 633 | pub const MB_TYPEMASK = 0x0000000F; |
| | 634 | pub const MB_ICONMASK = 0x000000F0; |
| | 635 | pub const MB_DEFMASK = 0x00000F00; |
| | 636 | pub const MB_MODEMASK = 0x00003000; |
| | 637 | pub const MB_MISCMASK = 0x0000C000; |
| | 638 | |
| | 639 | pub const IDOK = 1; |
| | 640 | pub const IDCANCEL = 2; |
| | 641 | pub const IDABORT = 3; |
| | 642 | pub const IDRETRY = 4; |
| | 643 | pub const IDIGNORE = 5; |
| | 644 | pub const IDYES = 6; |
| | 645 | pub const IDNO = 7; |
| | 646 | pub const IDCLOSE = 8; |
| | 647 | pub const IDHELP = 9; |
| | 648 | pub const IDTRYAGAIN = 10; |
| | 649 | pub const IDCONTINUE = 11; |
| | 650 | |
| | 651 | pub extern "user32" fn MessageBoxA(hWnd: ?HWND, lpText: [*:0]const u8, lpCaption: [*:0]const u8, uType: UINT) callconv(WINAPI) i32; |
| | 652 | pub fn messageBoxA(hWnd: ?HWND, lpText: [*:0]const u8, lpCaption: [*:0]const u8, uType: u32) !i32 { |
| | 653 | const value = MessageBoxA(hWnd, lpText, lpCaption, uType); |
| | 654 | if (value != 0) return value; |
| | 655 | return switch (GetLastError()) { |
| | 656 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 657 | .INVALID_PARAMETER => unreachable, |
| | 658 | else => |err| return windows.unexpectedError(err), |
| | 659 | }; |
| | 660 | } |
| | 661 | |
| | 662 | pub extern "user32" fn MessageBoxW(hWnd: ?HWND, lpText: [*:0]const u16, lpCaption: ?[*:0]const u16, uType: UINT) callconv(WINAPI) i32; |
| | 663 | pub var pfnMessageBoxW: @TypeOf(MessageBoxW) = undefined; |
| | 664 | pub fn messageBoxW(hWnd: ?HWND, lpText: [*:0]const u16, lpCaption: [*:0]const u16, uType: u32) !i32 { |
| | 665 | const function = selectSymbol(pfnMessageBoxW, MessageBoxW, .win2k); |
| | 666 | const value = function(hWnd, lpText, lpCaption, uType); |
| | 667 | if (value != 0) return value; |
| | 668 | return switch (GetLastError()) { |
| | 669 | .INVALID_WINDOW_HANDLE => unreachable, |
| | 670 | .INVALID_PARAMETER => unreachable, |
| | 671 | else => |err| return windows.unexpectedError(err), |
| | 672 | }; |
| | 673 | } |