Skip to content

Commit

Permalink
- Error handling for WindowHandle::resizable on windows
Browse files Browse the repository at this point in the history
- Use WindowLongPtr instead of LONG_PTR for 32 bit windows support
  • Loading branch information
teddemunnik committed Mar 20, 2020
1 parent 46d9341 commit 1b3971d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::sync::{Arc, Mutex};

use log::{debug, error, warn};
use winapi::ctypes::{c_int, c_void};
use winapi::shared::basetsd::LONG_PTR;
use winapi::shared::dxgi::*;
use winapi::shared::dxgi1_2::*;
use winapi::shared::dxgiformat::*;
Expand All @@ -34,6 +33,7 @@ use winapi::shared::minwindef::*;
use winapi::shared::windef::*;
use winapi::shared::winerror::*;
use winapi::um::d2d1::*;
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::unknwnbase::*;
use winapi::um::winnt::*;
use winapi::um::winuser::*;
Expand Down Expand Up @@ -1084,12 +1084,26 @@ impl WindowHandle {
let hwnd = w.hwnd.get();
unsafe {
let mut style = GetWindowLongPtrW(hwnd, GWL_STYLE);
if style == 0 {
warn!(
"failed to get window style: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
return;
}

if resizable {
style |= (WS_THICKFRAME | WS_MAXIMIZEBOX) as LONG_PTR;
style |= (WS_THICKFRAME | WS_MAXIMIZEBOX) as WindowLongPtr;
} else {
style &= !(WS_THICKFRAME | WS_MAXIMIZEBOX) as LONG_PTR;
style &= !(WS_THICKFRAME | WS_MAXIMIZEBOX) as WindowLongPtr;
}

if SetWindowLongPtrW(hwnd, GWL_STYLE, style) == 0 {
warn!(
"failed to set the window style: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
}
SetWindowLongPtrW(hwnd, GWL_STYLE, style);
}
}
}
Expand Down

0 comments on commit 1b3971d

Please sign in to comment.