/
main.rs
52 lines (44 loc) · 1.67 KB
/
main.rs
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
use windows_sys::{Win32::Foundation::*, Win32::Graphics::Gdi::ValidateRect, Win32::System::LibraryLoader::GetModuleHandleA, Win32::UI::WindowsAndMessaging::*};
fn main() {
unsafe {
let instance = GetModuleHandleA(std::ptr::null_mut());
debug_assert!(instance != 0);
let window_class = b"window\0".as_ptr();
let wc = WNDCLASSA {
hCursor: LoadCursorW(0, IDC_ARROW),
hInstance: instance,
lpszClassName: window_class,
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc),
cbClsExtra: 0,
cbWndExtra: 0,
hIcon: 0,
hbrBackground: 0,
lpszMenuName: std::ptr::null_mut(),
};
let atom = RegisterClassA(&wc);
debug_assert!(atom != 0);
CreateWindowExA(0, window_class, b"This is a sample window\0".as_ptr(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, instance, std::ptr::null_mut());
let mut message = std::mem::zeroed();
while GetMessageA(&mut message, 0, 0, 0) != 0 {
DispatchMessageA(&message);
}
}
}
extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT {
unsafe {
match message as u32 {
WM_PAINT => {
println!("WM_PAINT");
ValidateRect(window, std::ptr::null());
0
}
WM_DESTROY => {
println!("WM_DESTROY");
PostQuitMessage(0);
0
}
_ => DefWindowProcA(window, message, wparam, lparam),
}
}
}