Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/testwindow.zig
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn WindowProc(
}

{
const brush = win32.createSolidBrush(0xff00ffff);
const brush = win32.createSolidBrush(.yellow);
defer win32.deleteObject(brush);
win32.fillRect(hdc, ps.rcPaint, brush);
}
Expand Down
1 change: 1 addition & 0 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,7 @@ const redirects = std.StaticStringMap(Redirect).initComptime(.{
.{ "VARIANT_BOOL", Redirect{ .native = "i16" } },
.{ "BSTR", Redirect{ .native = "*u16" } },
.{ "HRESULT", Redirect{ .import = "zig" } },
.{ "COLORREF", Redirect{ .import = "zig" } },
});

const type_renames = std.StaticStringMap([]const u8).initComptime(.{
Expand Down
27 changes: 26 additions & 1 deletion src/static/win32/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@ pub const HRESULT = packed struct (u32) {
pub const S_OK: HRESULT = .fromInt(0);
};

pub const COLORREF = packed struct(u32) {
r: u8,
g: u8,
b: u8,
flags: u8,
pub fn fromInt(i: u32) COLORREF {
return @bitCast(i);
}
pub fn rgb(r: u8, g: u8, b: u8) COLORREF {
return .{ .r = r, .g = g, .b = b, .flags = 0 };
}
pub const invalid: COLORREF = .fromInt(0xFFFFFFFF);
pub const none: COLORREF = .fromInt(0xFFFFFFFF);
pub const default: COLORREF = .fromInt(0xFF000000);
pub const black: COLORREF = .rgb(0, 0, 0);
pub const white: COLORREF = .rgb(255, 255, 255);
pub const red: COLORREF = .rgb(255, 0, 0);
pub const green: COLORREF = .rgb(0, 255, 0);
pub const blue: COLORREF = .rgb(0, 0, 255);
pub const yellow: COLORREF = .rgb(255, 255, 0);
pub const cyan: COLORREF = .rgb(0, 255, 255);
pub const magenta: COLORREF = .rgb(255, 0, 255);
pub const gray: COLORREF = .rgb(128, 128, 128);
};

// These constants were removed from the metadata to allow each projection
// to define them however they like (see https://github.com/microsoft/win32metadata/issues/530)
pub const FALSE: win32.BOOL = 0;
Expand Down Expand Up @@ -572,7 +597,7 @@ pub fn endPaint(hwnd: win32.HWND, paintstruct: *const win32.PAINTSTRUCT) void {
}

/// calls CreateSolidBrush, panics on failure
pub fn createSolidBrush(color: u32) win32.HBRUSH {
pub fn createSolidBrush(color: COLORREF) win32.HBRUSH {
return win32.CreateSolidBrush(color) orelse panicWin32(
"CreateSolidBrush",
win32.GetLastError(),
Expand Down
Loading