Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implement GetWindowPlacement
Browse files Browse the repository at this point in the history
LinusU committed Sep 22, 2024
1 parent faba6df commit f25ce54
Showing 3 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion win32/src/winapi/builtin.rs
Original file line number Diff line number Diff line change
@@ -4866,7 +4866,7 @@ pub mod user32 {
pub unsafe fn GetWindowPlacement(machine: &mut Machine, esp: u32) -> u32 {
let mem = machine.mem().detach();
let hWnd = <HWND>::from_stack(mem, esp + 4u32);
let lpwndpl = <Option<&mut u32>>::from_stack(mem, esp + 8u32);
let lpwndpl = <Option<&mut WINDOWPLACEMENT>>::from_stack(mem, esp + 8u32);
winapi::user32::GetWindowPlacement(machine, hWnd, lpwndpl).to_raw()
}
pub unsafe fn GetWindowRect(machine: &mut Machine, esp: u32) -> u32 {
4 changes: 2 additions & 2 deletions win32/src/winapi/types.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ pub struct HWNDT;
pub type HWND = HANDLE<HWNDT>;

#[repr(C, packed)]
#[derive(Debug, Default)]
#[derive(Debug, Default, Copy, Clone)]
pub struct RECT {
pub left: i32,
pub top: i32,
@@ -38,7 +38,7 @@ pub struct RECT {
unsafe impl memory::Pod for RECT {}

#[repr(C, packed)]
#[derive(Debug)]
#[derive(Debug, Copy, Clone)]
pub struct POINT {
pub x: DWORD,
pub y: DWORD,
45 changes: 42 additions & 3 deletions win32/src/winapi/user32/window.rs
Original file line number Diff line number Diff line change
@@ -81,6 +81,8 @@ pub struct Window {
pub height: u32,
pub wndclass: Rc<WndClass>,
pub style: WindowStyle,
/// The current show state of the window.
pub show_cmd: Result<SW, u32>,
}

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

@@ -604,7 +607,7 @@ pub async fn UpdateWindow(machine: &mut Machine, hWnd: HWND) -> bool {
}

/// nCmdShow passed to ShowWindow().
#[derive(Debug, win32_derive::TryFromEnum)]
#[derive(Debug, Clone, Copy, win32_derive::TryFromEnum)]
pub enum SW {
HIDE = 0,
NORMAL = 1,
@@ -622,6 +625,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.clone();

let windowpos_addr = machine.state.scratch.alloc(
machine.emu.memory.mem(),
std::mem::size_of::<WINDOWPOS>() as u32,
@@ -976,9 +982,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,
rcDevice: 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.flags = 0;
wndpl.showCmd = window.show_cmd.map_or_else(|v| v, |v| v as u32);
wndpl.ptMinPosition = POINT { x: 0, y: 0 };
wndpl.ptMaxPosition = POINT { x: 0, y: 0 };
wndpl.rcNormalPosition = RECT {
left: 0,
top: 0,
right: window.width as i32,
bottom: window.height as i32,
};

// FIXME: Fille rcDevice depending on wndpl.length

true
}

#[win32_derive::dllexport]

0 comments on commit f25ce54

Please sign in to comment.