-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.zig
58 lines (49 loc) · 1.45 KB
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//!zig-autodoc-section: BaseEx\\main.zig
//! main.zig :
//! Template for a console program that hide the console window.
// Build using Zig 0.12.0
const std = @import("std");
const win = struct {
usingnamespace std.os.windows;
usingnamespace std.os.windows.kernel32;
};
pub fn main() void {
HideConsoleWindow();
_ = MessageBoxA(null, "Console window is hide.", "BaseEx", MB_OK);
}
fn HideConsoleWindow() void {
const BUF_TITLE = 1024;
var hwndFound: win.HWND = undefined;
var pszWindowTitle: [BUF_TITLE:0]win.CHAR = std.mem.zeroes([BUF_TITLE:0]win.CHAR);
_ = GetConsoleTitleA(&pszWindowTitle, BUF_TITLE);
hwndFound=FindWindowA(null, &pszWindowTitle);
_ = ShowWindow(hwndFound, SW_HIDE);
}
// ============================================================================
// Helpers
//
pub extern "kernel32" fn GetConsoleTitleA(
lpConsoleTitle: win.LPSTR,
nSize: win.DWORD,
) callconv(win.WINAPI) win.DWORD;
pub extern "kernel32" fn FindWindowA(
lpClassName: ?win.LPSTR,
lpWindowName: ?win.LPSTR,
) callconv(win.WINAPI) win.HWND;
pub const SW_HIDE = 0;
pub extern "user32" fn ShowWindow(
hWnd: win.HWND,
nCmdShow: i32
) callconv(win.WINAPI) win.BOOL;
pub const MB_OK = 0x00000000;
pub extern "user32" fn MessageBoxA(
hWnd: ?win.HWND,
lpText: [*:0]const u8,
lpCaption: [*:0]const u8,
uType: win.UINT
) callconv(win.WINAPI) win.INT;
// ============================================================================
// Tests
//
test " " {
}