Skip to content

Commit 6fd536a

Browse files
committed
Fixed bugs, style suggestions
1 parent bbc2c7c commit 6fd536a

File tree

1 file changed

+69
-68
lines changed

1 file changed

+69
-68
lines changed

lib/std/os/windows/user32.zig

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ pub const WM_SYSKEYDOWN = 0x0104;
8686
pub const WM_SYSKEYUP = 0x0105;
8787
pub const WM_SYSCHAR = 0x0106;
8888
pub const WM_SYSDEADCHAR = 0x0107;
89-
pub const WM_KEYLAST = 0x0108;
89+
pub const WM_UNICHAR = 0x0109;
90+
pub const WM_KEYLAST = 0x0109;
9091
pub const WM_INITDIALOG = 0x0110;
9192
pub const WM_COMMAND = 0x0111;
9293
pub const WM_SYSCOMMAND = 0x0112;
@@ -128,11 +129,11 @@ pub fn getMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax:
128129
const r = GetMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
129130
if (r == 0) return error.Quit;
130131
if (r != -1) return;
131-
return switch (GetLastError()) {
132+
switch (GetLastError()) {
132133
.INVALID_WINDOW_HANDLE => unreachable,
133134
.INVALID_PARAMETER => unreachable,
134135
else => |err| return windows.unexpectedError(err),
135-
};
136+
}
136137
}
137138

138139
pub extern "user32" fn GetMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) callconv(WINAPI) BOOL;
@@ -143,11 +144,11 @@ pub fn getMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax:
143144
const r = function(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
144145
if (r == 0) return error.Quit;
145146
if (r != -1) return;
146-
return switch (GetLastError()) {
147+
switch (GetLastError()) {
147148
.INVALID_WINDOW_HANDLE => unreachable,
148149
.INVALID_PARAMETER => unreachable,
149150
else => |err| return windows.unexpectedError(err),
150-
};
151+
}
151152
}
152153

153154
pub const PM_NOREMOVE = 0x0000;
@@ -159,11 +160,11 @@ pub fn peekMessageA(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax:
159160
const r = PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
160161
if (r == 0) return false;
161162
if (r != -1) return true;
162-
return switch (GetLastError()) {
163+
switch (GetLastError()) {
163164
.INVALID_WINDOW_HANDLE => unreachable,
164165
.INVALID_PARAMETER => unreachable,
165166
else => |err| return windows.unexpectedError(err),
166-
};
167+
}
167168
}
168169

169170
pub extern "user32" fn PeekMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) callconv(WINAPI) BOOL;
@@ -174,11 +175,11 @@ pub fn peekMessageW(lpMsg: *MSG, hWnd: ?HWND, wMsgFilterMin: u32, wMsgFilterMax:
174175
const r = function(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
175176
if (r == 0) return false;
176177
if (r != -1) return true;
177-
return switch (GetLastError()) {
178+
switch (GetLastError()) {
178179
.INVALID_WINDOW_HANDLE => unreachable,
179180
.INVALID_PARAMETER => unreachable,
180181
else => |err| return windows.unexpectedError(err),
181-
};
182+
}
182183
}
183184

184185
pub extern "user32" fn TranslateMessage(lpMsg: *const MSG) callconv(WINAPI) BOOL;
@@ -263,46 +264,46 @@ pub extern "user32" fn RegisterClassExA(*const WNDCLASSEXA) callconv(WINAPI) ATO
263264
pub fn registerClassExA(window_class: *const WNDCLASSEXA) !ATOM {
264265
const atom = RegisterClassExA(window_class);
265266
if (atom != 0) return atom;
266-
return switch (GetLastError()) {
267-
.CLASS_ALREADY_EXISTS => error.AlreadyExists,
267+
switch (GetLastError()) {
268+
.CLASS_ALREADY_EXISTS => return error.AlreadyExists,
268269
.INVALID_PARAMETER => unreachable,
269270
else => |err| return windows.unexpectedError(err),
270-
};
271+
}
271272
}
272273

273274
pub extern "user32" fn RegisterClassExW(*const WNDCLASSEXW) callconv(WINAPI) ATOM;
274275
pub var pfnRegisterClassExW: @TypeOf(RegisterClassExW) = undefined;
275-
pub fn registerClassExW(window_class: *const WNDCLASSEXA) !ATOM {
276+
pub fn registerClassExW(window_class: *const WNDCLASSEXW) !ATOM {
276277
const function = selectSymbol(RegisterClassExW, pfnRegisterClassExW, .win2k);
277278
const atom = function(window_class);
278279
if (atom != 0) return atom;
279-
return switch (GetLastError()) {
280-
.CLASS_ALREADY_EXISTS => error.AlreadyExists,
280+
switch (GetLastError()) {
281+
.CLASS_ALREADY_EXISTS => return error.AlreadyExists,
281282
.CALL_NOT_IMPLEMENTED => unreachable,
282283
.INVALID_PARAMETER => unreachable,
283284
else => |err| return windows.unexpectedError(err),
284-
};
285+
}
285286
}
286287

287-
pub extern "user32" fn UnregisterClassA(lpClassName: LPCSTR, hInstance: HINSTANCE) callconv(.Stdcall) BOOL;
288+
pub extern "user32" fn UnregisterClassA(lpClassName: [*:0]const u8, hInstance: HINSTANCE) callconv(WINAPI) BOOL;
288289
pub fn unregisterClassA(lpClassName: [*:0]const u8, hInstance: HINSTANCE) !void {
289290
if (UnregisterClassA(lpClassName, hInstance) == 0) {
290-
return switch (GetLastError()) {
291-
.CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist,
291+
switch (GetLastError()) {
292+
.CLASS_DOES_NOT_EXIST => return error.ClassDoesNotExist,
292293
else => |err| return windows.unexpectedError(err),
293-
};
294+
}
294295
}
295296
}
296297

297-
pub extern "user32" fn UnregisterClassW(lpClassName: LPCWSTR, hInstance: HINSTANCE) callconv(.Stdcall) BOOL;
298+
pub extern "user32" fn UnregisterClassW(lpClassName: [*:0]const u16, hInstance: HINSTANCE) callconv(.Stdcall) BOOL;
298299
pub var pfnUnregisterClassW: @TypeOf(UnregisterClassW) = undefined;
299300
pub fn unregisterClassW(lpClassName: [*:0]const u16, hInstance: HINSTANCE) !void {
300301
const function = selectSymbol(UnregisterClassW, pfnUnregisterClassW, .win2k);
301302
if (function(lpClassName, hInstance) == 0) {
302-
return switch (GetLastError()) {
303-
.CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist,
303+
switch (GetLastError()) {
304+
.CLASS_DOES_NOT_EXIST => return error.ClassDoesNotExist,
304305
else => |err| return windows.unexpectedError(err),
305-
};
306+
}
306307
}
307308
}
308309

@@ -354,8 +355,8 @@ pub const WS_EX_CONTROLPARENT = 0x00010000;
354355
pub const WS_EX_STATICEDGE = 0x00020000;
355356
pub const WS_EX_APPWINDOW = 0x00040000;
356357
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);
358+
pub const WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
359+
pub const WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
359360

360361
pub const CW_USEDEFAULT = @bitCast(i32, @as(u32, 0x80000000));
361362

@@ -364,11 +365,11 @@ pub fn createWindowExA(dwExStyle: u32, lpClassName: [*:0]const u8, lpWindowName:
364365
const window = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWindParent, hMenu, hInstance, lpParam);
365366
if (window) |win| return win;
366367

367-
return switch (GetLastError()) {
368-
.CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist,
368+
switch (GetLastError()) {
369+
.CLASS_DOES_NOT_EXIST => return error.ClassDoesNotExist,
369370
.INVALID_PARAMETER => unreachable,
370371
else => |err| return windows.unexpectedError(err),
371-
};
372+
}
372373
}
373374

374375
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;
@@ -378,21 +379,21 @@ pub fn createWindowExW(dwExStyle: u32, lpClassName: [*:0]const u16, lpWindowName
378379
const window = function(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWindParent, hMenu, hInstance, lpParam);
379380
if (window) |win| return win;
380381

381-
return switch (GetLastError()) {
382-
.CLASS_DOES_NOT_EXIST => error.ClassDoesNotExist,
382+
switch (GetLastError()) {
383+
.CLASS_DOES_NOT_EXIST => return error.ClassDoesNotExist,
383384
.INVALID_PARAMETER => unreachable,
384385
else => |err| return windows.unexpectedError(err),
385-
};
386+
}
386387
}
387388

388389
pub extern "user32" fn DestroyWindow(hWnd: HWND) callconv(WINAPI) BOOL;
389390
pub fn destroyWindow(hWnd: HWND) !void {
390391
if (DestroyWindow(hWnd) == 0) {
391-
return switch (GetLastError()) {
392+
switch (GetLastError()) {
392393
.INVALID_WINDOW_HANDLE => unreachable,
393394
.INVALID_PARAMETER => unreachable,
394395
else => |err| return windows.unexpectedError(err),
395-
};
396+
}
396397
}
397398
}
398399

@@ -420,11 +421,11 @@ pub fn showWindow(hWnd: HWND, nCmdShow: i32) bool {
420421
pub extern "user32" fn UpdateWindow(hWnd: HWND) callconv(WINAPI) BOOL;
421422
pub fn updateWindow(hWnd: HWND) !void {
422423
if (ShowWindow(hWnd, nCmdShow) == 0) {
423-
return switch (GetLastError()) {
424+
switch (GetLastError()) {
424425
.INVALID_WINDOW_HANDLE => unreachable,
425426
.INVALID_PARAMETER => unreachable,
426427
else => |err| return windows.unexpectedError(err),
427-
};
428+
}
428429
}
429430
}
430431

@@ -433,10 +434,10 @@ pub fn adjustWindowRectEx(lpRect: *RECT, dwStyle: u32, bMenu: bool, dwExStyle: u
433434
assert(dwStyle & WS_OVERLAPPED == 0);
434435

435436
if (AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle) == 0) {
436-
return switch (GetLastError()) {
437+
switch (GetLastError()) {
437438
.INVALID_PARAMETER => unreachable,
438439
else => |err| return windows.unexpectedError(err),
439-
};
440+
}
440441
}
441442
}
442443

@@ -453,12 +454,12 @@ pub fn getWindowLongA(hWnd: HWND, nIndex: i32) !i32 {
453454
const value = GetWindowLongA(hWnd, nIndex);
454455
if (value != 0) return value;
455456

456-
return switch (GetLastError()) {
457-
.SUCCESS => 0,
457+
switch (GetLastError()) {
458+
.SUCCESS => return 0,
458459
.INVALID_WINDOW_HANDLE => unreachable,
459460
.INVALID_PARAMETER => unreachable,
460461
else => |err| return windows.unexpectedError(err),
461-
};
462+
}
462463
}
463464

464465
pub extern "user32" fn GetWindowLongW(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG;
@@ -469,12 +470,12 @@ pub fn getWindowLongW(hWnd: HWND, nIndex: i32) !i32 {
469470
const value = function(hWnd, nIndex);
470471
if (value != 0) return value;
471472

472-
return switch (GetLastError()) {
473-
.SUCCESS => 0,
473+
switch (GetLastError()) {
474+
.SUCCESS => return 0,
474475
.INVALID_WINDOW_HANDLE => unreachable,
475476
.INVALID_PARAMETER => unreachable,
476477
else => |err| return windows.unexpectedError(err),
477-
};
478+
}
478479
}
479480

480481
pub extern "user32" fn GetWindowLongPtrA(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG_PTR;
@@ -486,12 +487,12 @@ pub fn getWindowLongPtrA(hWnd: HWND, nIndex: i32) !isize {
486487
const value = GetWindowLongPtrA(hWnd, nIndex);
487488
if (value != 0) return value;
488489

489-
return switch (GetLastError()) {
490-
.SUCCESS => 0,
490+
switch (GetLastError()) {
491+
.SUCCESS => return 0,
491492
.INVALID_WINDOW_HANDLE => unreachable,
492493
.INVALID_PARAMETER => unreachable,
493494
else => |err| return windows.unexpectedError(err),
494-
};
495+
}
495496
}
496497

497498
pub extern "user32" fn GetWindowLongPtrW(hWnd: HWND, nIndex: i32) callconv(WINAPI) LONG_PTR;
@@ -503,12 +504,12 @@ pub fn getWindowLongPtrW(hWnd: HWND, nIndex: i32) !isize {
503504
const value = function(hWnd, nIndex);
504505
if (value != 0) return value;
505506

506-
return switch (GetLastError()) {
507-
.SUCCESS => 0,
507+
switch (GetLastError()) {
508+
.SUCCESS => return 0,
508509
.INVALID_WINDOW_HANDLE => unreachable,
509510
.INVALID_PARAMETER => unreachable,
510511
else => |err| return windows.unexpectedError(err),
511-
};
512+
}
512513
}
513514

514515
pub extern "user32" fn SetWindowLongA(hWnd: HWND, nIndex: i32, dwNewLong: LONG) callconv(WINAPI) LONG;
@@ -520,12 +521,12 @@ pub fn setWindowLongA(hWnd: HWND, nIndex: i32, dwNewLong: i32) !i32 {
520521
const value = SetWindowLongA(hWnd, nIndex, dwNewLong);
521522
if (value != 0) return value;
522523

523-
return switch (GetLastError()) {
524-
.SUCCESS => 0,
524+
switch (GetLastError()) {
525+
.SUCCESS => return 0,
525526
.INVALID_WINDOW_HANDLE => unreachable,
526527
.INVALID_PARAMETER => unreachable,
527528
else => |err| return windows.unexpectedError(err),
528-
};
529+
}
529530
}
530531

531532
pub extern "user32" fn SetWindowLongW(hWnd: HWND, nIndex: i32, dwNewLong: LONG) callconv(WINAPI) LONG;
@@ -537,12 +538,12 @@ pub fn setWindowLongW(hWnd: HWND, nIndex: i32, dwNewLong: i32) !i32 {
537538
const value = function(hWnd, nIndex, dwNewLong);
538539
if (value != 0) return value;
539540

540-
return switch (GetLastError()) {
541-
.SUCCESS => 0,
541+
switch (GetLastError()) {
542+
.SUCCESS => return 0,
542543
.INVALID_WINDOW_HANDLE => unreachable,
543544
.INVALID_PARAMETER => unreachable,
544545
else => |err| return windows.unexpectedError(err),
545-
};
546+
}
546547
}
547548

548549
pub extern "user32" fn SetWindowLongPtrA(hWnd: HWND, nIndex: i32, dwNewLong: LONG_PTR) callconv(WINAPI) LONG_PTR;
@@ -555,12 +556,12 @@ pub fn setWindowLongPtrA(hWnd: HWND, nIndex: i32, dwNewLong: isize) !isize {
555556
const value = SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
556557
if (value != 0) return value;
557558

558-
return switch (GetLastError()) {
559-
.SUCCESS => 0,
559+
switch (GetLastError()) {
560+
.SUCCESS => return 0,
560561
.INVALID_WINDOW_HANDLE => unreachable,
561562
.INVALID_PARAMETER => unreachable,
562563
else => |err| return windows.unexpectedError(err),
563-
};
564+
}
564565
}
565566

566567
pub extern "user32" fn SetWindowLongPtrW(hWnd: HWND, nIndex: i32, dwNewLong: LONG_PTR) callconv(WINAPI) LONG_PTR;
@@ -573,24 +574,24 @@ pub fn setWindowLongPtrW(hWnd: HWND, nIndex: i32, dwNewLong: isize) !isize {
573574
const value = function(hWnd, nIndex, dwNewLong);
574575
if (value != 0) return value;
575576

576-
return switch (GetLastError()) {
577-
.SUCCESS => 0,
577+
switch (GetLastError()) {
578+
.SUCCESS => return 0,
578579
.INVALID_WINDOW_HANDLE => unreachable,
579580
.INVALID_PARAMETER => unreachable,
580581
else => |err| return windows.unexpectedError(err),
581-
};
582+
}
582583
}
583584

584585
pub extern "user32" fn GetDC(hWnd: ?HWND) callconv(WINAPI) ?HDC;
585586
pub fn getDC(hWnd: ?HWND) !HDC {
586587
const hdc = GetDC(hWnd);
587588
if (hdc) |h| return h;
588589

589-
return switch (GetLastError()) {
590+
switch (GetLastError()) {
590591
.INVALID_WINDOW_HANDLE => unreachable,
591592
.INVALID_PARAMETER => unreachable,
592593
else => |err| return windows.unexpectedError(err),
593-
};
594+
}
594595
}
595596

596597
pub extern "user32" fn ReleaseDC(hWnd: ?HWND, hDC: HDC) callconv(WINAPI) i32;
@@ -652,11 +653,11 @@ pub extern "user32" fn MessageBoxA(hWnd: ?HWND, lpText: [*:0]const u8, lpCaption
652653
pub fn messageBoxA(hWnd: ?HWND, lpText: [*:0]const u8, lpCaption: [*:0]const u8, uType: u32) !i32 {
653654
const value = MessageBoxA(hWnd, lpText, lpCaption, uType);
654655
if (value != 0) return value;
655-
return switch (GetLastError()) {
656+
switch (GetLastError()) {
656657
.INVALID_WINDOW_HANDLE => unreachable,
657658
.INVALID_PARAMETER => unreachable,
658659
else => |err| return windows.unexpectedError(err),
659-
};
660+
}
660661
}
661662

662663
pub extern "user32" fn MessageBoxW(hWnd: ?HWND, lpText: [*:0]const u16, lpCaption: ?[*:0]const u16, uType: UINT) callconv(WINAPI) i32;
@@ -665,9 +666,9 @@ pub fn messageBoxW(hWnd: ?HWND, lpText: [*:0]const u16, lpCaption: [*:0]const u1
665666
const function = selectSymbol(pfnMessageBoxW, MessageBoxW, .win2k);
666667
const value = function(hWnd, lpText, lpCaption, uType);
667668
if (value != 0) return value;
668-
return switch (GetLastError()) {
669+
switch (GetLastError()) {
669670
.INVALID_WINDOW_HANDLE => unreachable,
670671
.INVALID_PARAMETER => unreachable,
671672
else => |err| return windows.unexpectedError(err),
672-
};
673+
}
673674
}

0 commit comments

Comments
 (0)