use windows::{
core::*,
Win32::Foundation::*,
Win32::System::LibraryLoader::GetModuleHandleW,
Win32::UI::WindowsAndMessaging::*,
};
unsafe extern "system" fn wnd_proc(
hwnd: HWND,
msg: u32,
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
match msg {
WM_DESTROY => {
PostQuitMessage(0);
LRESULT(0)
}
_ => DefWindowProcW(hwnd, msg, wparam, lparam),
}
}
pub fn create_native_window() -> Result<()> {
unsafe {
let instance = GetModuleHandleW(None)?;
let class_name = w!("MyVulkanWindowClass");
let wnd_class = WNDCLASSW {
hInstance: instance.into(),
lpszClassName: class_name,
lpfnWndProc: Some(wnd_proc),
..Default::default()
};
RegisterClassW(&wnd_class);
let hwnd = CreateWindowExW(
WINDOW_EX_STYLE::default(),
class_name,
w!("Vulkan Direct Win32 Window"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
None,
None,
Some(instance.into()),
None,
)?;
println!("Win32生のHWND(ウィンドウハンドル)を作成しました: {:?}", hwnd);
let mut msg = MSG::default();
while GetMessageW(&mut msg, None, 0, 0).into() {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
Ok(())
}