melak47 / BorderlessWindow

basic win32 example of a borderless window (with aero shadows)
Creative Commons Zero v1.0 Universal
480 stars 76 forks source link

The titlebar will appear again sometimes. #10

Closed lygstate closed 8 years ago

lygstate commented 9 years ago

When I click/focus other window such as Chrome Brower, and then MouseDown on the BorderlessWindow, and don't release, [This must be at the dragging state] Then we will see the titlebar again. Along with the border, and the maximize,minimize icons doesn't appear. This is at the Aero state, At the win7 basic theme, when I maximize/restore the window by double clicking the window The titlebar will appear in the procedure of maximize/restore.

melak47 commented 8 years ago

I can only reproduce this while the windows 7 basic theme is active. What appears to happen is this: If borderless_move is true, the entire window's client area is treated as the title bar. So clicking and dragging enters the modal size/move message loop, during which my own message loop will not run, and hence cannot call InvalidateRect which would cause the window to be repainted.

I tried listening to WM_ENTERSIZEMOVE and WM_SIZE, WM_MOVE, and WM_MOUSEMOVE to also repaint the window then, but this doesn't seem to help.

I'm not sure how to solve this, I guess you'll have to live with it on Windows 7. Since Windows 8, DWM composition cannot be disabled anymore, so this phenomenon should not occur there.

lygstate commented 8 years ago

After all the days lives with win32, I am about know what's happening to the win32 api to getting the style without titlebar totally. The key part is listening to the event

case WM.WM_STYLECHANGING: {
  let ret = this.OldWindowProc(hwnd, uMsg, wParam, lParam)
  let windowStylePtr = cast(PVOID(lParam), STYLESTRUCT.ptr)
  let windowStyle = windowStylePtr.contents.styleNew
  // http://stackoverflow.com/questions/2398746/removing-window-border
  windowStyle = WS.WS_THICKFRAME | windowStyle
  windowStyle = excludeBits(windowStyle, [WS.WS_POPUP, WS.WS_CAPTION])
  windowStylePtr.contents.styleNew = windowStyle
  return ret
}

And when the once event WM_STYLECHANGING appeared, we should always make sure the windowStyle do not have the WS_CAPTION

Even though my code are written in Javascript, it's should be understandable.:)

lygstate commented 8 years ago

Besides

    case WM.WM_NCCALCSIZE:
      return LRESULT(0)
    case WM.WM_NCACTIVATE:
      return LRESULT(1)
melak47 commented 8 years ago

Handling WM_NCACTIVATE seems to get rid of this behavior, thanks for that!

I also removed WS_CAPTION, but for a different reason: it's what caused the upper corners to appear round with the Win7 basic theme.

Listening to the WM_STYLECHANGED event and forcefully removing any style bits does not seem to be necessary.