@@ -172,16 +172,7 @@ unsafe extern "system" fn subclassed_window_proc(
172172
173173 // If the hit test is in the client area, check if it's in the draggable region
174174 if hit. 0 == HTCLIENT as isize {
175- let points = POINTS {
176- x : LOWORD ( lparam. 0 as u32 ) as i16 ,
177- y : HIWORD ( lparam. 0 as u32 ) as i16 ,
178- } ;
179- let mut point = POINT {
180- x : points. x as i32 ,
181- y : points. y as i32 ,
182- } ;
183-
184- let _ = ScreenToClient ( hwnd, & mut point) ;
175+ let point = lparam_to_client_point ( lparam, hwnd) ;
185176
186177 // If the point is inside the draggable region, return HTTRANSPARENT
187178 // so the root window can handle the dragging
@@ -222,16 +213,7 @@ unsafe extern "system" fn root_window_proc(
222213
223214 // If the hit test is in the client area, check if it's in the draggable region
224215 if hit. 0 == HTCLIENT as isize {
225- let points = POINTS {
226- x : LOWORD ( lparam. 0 as u32 ) as i16 ,
227- y : HIWORD ( lparam. 0 as u32 ) as i16 ,
228- } ;
229- let mut point = POINT {
230- x : points. x as i32 ,
231- y : points. y as i32 ,
232- } ;
233-
234- let _ = ScreenToClient ( hwnd, & mut point) ;
216+ let point = lparam_to_client_point ( lparam, hwnd) ;
235217
236218 // If the point is inside the draggable region, return HTCAPTION
237219 // to allow dragging the window
@@ -244,10 +226,14 @@ unsafe extern "system" fn root_window_proc(
244226 return hit;
245227 }
246228
247- // If the message is WM_NCLBUTTONDOWN, call DefWindowProc
248- // not the original wnd proc to ensure proper dragging behavior.
249229 if msg == WM_NCLBUTTONDOWN {
250- return unsafe { DefWindowProcW ( hwnd, msg, wparam, lparam) } ;
230+ let point = lparam_to_client_point ( lparam, hwnd) ;
231+
232+ // If the point is inside the draggable region, call DefWindowProc
233+ // not the original wnd proc to ensure proper dragging behavior.
234+ if PtInRegion ( draggable_region, point. x , point. y ) . as_bool ( ) {
235+ return unsafe { DefWindowProcW ( hwnd, msg, wparam, lparam) } ;
236+ }
251237 }
252238
253239 // For other messages, call the original window procedure
@@ -263,6 +249,23 @@ pub fn subclass_window_for_dragging(window: &mut cef::Window) {
263249 subclass_window ( hwnd, root_window_proc, HRGN :: default ( ) ) ;
264250}
265251
252+ /// Converts a LPARAM from a mouse event to a POINT in client coordinates.
253+ fn lparam_to_client_point ( lparam : LPARAM , hwnd : HWND ) -> POINT {
254+ let points = POINTS {
255+ x : LOWORD ( lparam. 0 as u32 ) as i16 ,
256+ y : HIWORD ( lparam. 0 as u32 ) as i16 ,
257+ } ;
258+
259+ let mut point = POINT {
260+ x : points. x as i32 ,
261+ y : points. y as i32 ,
262+ } ;
263+
264+ let _ = unsafe { ScreenToClient ( hwnd, & mut point) } ;
265+
266+ point
267+ }
268+
266269/// Extracts the low-order word from a 32-bit value.
267270#[ allow( non_snake_case) ]
268271pub fn LOWORD ( dword : u32 ) -> u16 {
0 commit comments