Skip to content

Commit

Permalink
implement GetWindowPlacement
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Oct 7, 2024
1 parent af32dd4 commit e4eda44
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion win32/src/winapi/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12425,7 +12425,7 @@ pub mod user32 {
pub unsafe fn GetWindowPlacement(machine: &mut Machine, stack_args: u32) -> u32 {
let mem = machine.mem().detach();
let hWnd = <HWND>::from_stack(mem, stack_args + 0u32);
let lpwndpl = <Option<&mut u32>>::from_stack(mem, stack_args + 4u32);
let lpwndpl = <Option<&mut WINDOWPLACEMENT>>::from_stack(mem, stack_args + 4u32);
let __trace_context = if crate::trace::enabled("user32/window") {
Some(crate::trace::trace_begin(
"user32/window",
Expand Down
2 changes: 1 addition & 1 deletion win32/src/winapi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct HWNDT;
pub type HWND = HANDLE<HWNDT>;

#[repr(C, packed)]
#[derive(Debug, Default, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct RECT {
pub left: i32,
pub top: i32,
Expand Down
45 changes: 42 additions & 3 deletions win32/src/winapi/user32/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct Window {
pub height: u32,
pub wndclass: Rc<WndClass>,
pub style: WindowStyle,
/// The current show state of the window.
pub show_cmd: SW,
}

pub enum WindowType {
Expand Down Expand Up @@ -485,6 +487,7 @@ pub async fn CreateWindowExW(
height,
wndclass,
style,
show_cmd: SW::HIDE,
};
machine.state.user32.windows.set(hwnd, window);

Expand Down Expand Up @@ -583,7 +586,7 @@ pub async fn UpdateWindow(machine: &mut Machine, hWnd: HWND) -> bool {
}

/// nCmdShow passed to ShowWindow().
#[derive(Debug, win32_derive::TryFromEnum)]
#[derive(Copy, Clone, Debug, win32_derive::TryFromEnum)]
pub enum SW {
HIDE = 0,
NORMAL = 1,
Expand All @@ -601,6 +604,9 @@ pub enum SW {

#[win32_derive::dllexport]
pub async fn ShowWindow(machine: &mut Machine, hWnd: HWND, nCmdShow: Result<SW, u32>) -> bool {
// Store the show command for returning from GetWindowPlacement.
machine.state.user32.windows.get_mut(hWnd).unwrap().show_cmd = nCmdShow.unwrap();

dispatch_message(
machine,
&MSG {
Expand Down Expand Up @@ -963,9 +969,42 @@ pub fn GetWindowRect(machine: &mut Machine, hWnd: HWND, lpRect: Option<&mut RECT
true
}

#[repr(C, packed)]
#[derive(Clone, Debug)]
pub struct WINDOWPLACEMENT {
length: u32,
flags: u32,
showCmd: u32,
ptMinPosition: POINT,
ptMaxPosition: POINT,
rcNormalPosition: RECT,
}
unsafe impl memory::Pod for WINDOWPLACEMENT {}

#[win32_derive::dllexport]
pub fn GetWindowPlacement(_machine: &mut Machine, hWnd: HWND, lpwndpl: Option<&mut u32>) -> bool {
false
pub fn GetWindowPlacement(
machine: &mut Machine,
hWnd: HWND,
lpwndpl: Option<&mut WINDOWPLACEMENT>,
) -> bool {
let window = machine.state.user32.windows.get(hWnd).unwrap();
let wndpl = lpwndpl.unwrap();

*wndpl = WINDOWPLACEMENT {
length: std::mem::size_of::<WINDOWPLACEMENT>() as u32,
flags: 0,
showCmd: window.show_cmd as u32,
ptMinPosition: POINT { x: 0, y: 0 },
ptMaxPosition: POINT { x: 0, y: 0 },
rcNormalPosition: RECT {
left: 0,
top: 0,
right: window.width as i32,
bottom: window.height as i32,
},
};

true
}

#[win32_derive::dllexport]
Expand Down

0 comments on commit e4eda44

Please sign in to comment.