Windows: add basic parent window support
This commit is contained in:
parent
9d4d82f9f7
commit
756b182250
|
@ -16,9 +16,11 @@ use self::winapi::um::wingdi::{
|
||||||
use self::winapi::um::winuser::{
|
use self::winapi::um::winuser::{
|
||||||
CreateWindowExA, DefWindowProcA, DispatchMessageA, GetDC, PeekMessageA, PostQuitMessage,
|
CreateWindowExA, DefWindowProcA, DispatchMessageA, GetDC, PeekMessageA, PostQuitMessage,
|
||||||
RegisterClassA, TranslateMessage, CS_HREDRAW, CS_OWNDC, CS_VREDRAW, CW_USEDEFAULT, MSG,
|
RegisterClassA, TranslateMessage, CS_HREDRAW, CS_OWNDC, CS_VREDRAW, CW_USEDEFAULT, MSG,
|
||||||
PM_REMOVE, WM_DESTROY, WM_QUIT, WNDCLASSA, WS_OVERLAPPEDWINDOW, WS_VISIBLE,
|
PM_REMOVE, WM_DESTROY, WM_QUIT, WNDCLASSA, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS,
|
||||||
|
WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, WS_SIZEBOX, WS_VISIBLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::Parent::WithParent;
|
||||||
use crate::WindowOpenOptions;
|
use crate::WindowOpenOptions;
|
||||||
|
|
||||||
pub struct Window;
|
pub struct Window;
|
||||||
|
@ -60,18 +62,32 @@ impl Window {
|
||||||
};
|
};
|
||||||
RegisterClassA(&wnd_class);
|
RegisterClassA(&wnd_class);
|
||||||
|
|
||||||
|
let mut flags = WS_POPUPWINDOW
|
||||||
|
| WS_CAPTION
|
||||||
|
| WS_VISIBLE
|
||||||
|
| WS_SIZEBOX
|
||||||
|
| WS_MINIMIZEBOX
|
||||||
|
| WS_MAXIMIZEBOX
|
||||||
|
| WS_CLIPSIBLINGS;
|
||||||
|
|
||||||
|
let mut parent = null_mut();
|
||||||
|
if let WithParent(p) = options.parent {
|
||||||
|
parent = p;
|
||||||
|
flags = WS_CHILD | WS_VISIBLE;
|
||||||
|
}
|
||||||
|
|
||||||
let hwnd = CreateWindowExA(
|
let hwnd = CreateWindowExA(
|
||||||
0,
|
0,
|
||||||
class_name.as_ptr() as *const i8,
|
class_name.as_ptr() as *const i8,
|
||||||
(options.title.to_owned() + "\0").as_ptr() as *const i8,
|
(options.title.to_owned() + "\0").as_ptr() as *const i8,
|
||||||
// todo: fine for now, will have to change with a parent
|
// todo: fine for now, will have to change with a parent
|
||||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
flags,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
CW_USEDEFAULT,
|
CW_USEDEFAULT,
|
||||||
// todo: check if usize fits into i32
|
// todo: check if usize fits into i32
|
||||||
options.width as i32,
|
options.width as i32,
|
||||||
options.height as i32,
|
options.height as i32,
|
||||||
null_mut(),
|
parent as *mut _,
|
||||||
null_mut(),
|
null_mut(),
|
||||||
null_mut(),
|
null_mut(),
|
||||||
null_mut(),
|
null_mut(),
|
||||||
|
@ -116,6 +132,7 @@ impl Window {
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo: decide what to do with the message pump
|
// todo: decide what to do with the message pump
|
||||||
|
if parent.is_null() {
|
||||||
loop {
|
loop {
|
||||||
if !handle_msg(null_mut()) {
|
if !handle_msg(null_mut()) {
|
||||||
break;
|
break;
|
||||||
|
@ -127,6 +144,7 @@ impl Window {
|
||||||
SwapBuffers(hdc);
|
SwapBuffers(hdc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Window
|
Window
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue