WinAPI C++: Reprogramming Window Resize

后端 未结 5 1848
無奈伤痛
無奈伤痛 2020-12-30 16:15

I have a window, and I want to implement the borders as resizing borders, like any other window. Taking in suggestions from comments and answers, I have rewritten my code. F

5条回答
  •  温柔的废话
    2020-12-30 16:55

    Alas, this is not the answer you are waiting for. On Windows Seven, moving and sizing at the same time a Top-Level Window with WS_POPUP style is indeed broken. visually, the window is first moved, and afterward sized. When sizing by the left or top, the move operation briefly reveals backgroud pixels, resulting in very bad user experience.

    As far as I understand what's happening, it has nothing to do with WM_GETMINMAXINFO or WM_NCCALCSIZE.

    It's very simple to see the effect: create a WS_POPUP | WS_VISIBLE window with an almost empty window procedure, set a timer and in the WM_TIMER use SetWindowPos, moving the window a little to the left while sizing it larger, in order to let the right edge at the same place. You will see backgroud pixels, which is silly. No such breakage on Windows XP.

    I tried lots of tricks, some of them very twisted, but the end result is always the same: at the moment the window is finally rendered in its new state, there is first a move operation, then a size one...

    You are left with 2 options (if you target Seven+):

    1) Use standard sizing border and take advantage of the new APIs (eg: DwmExtendFrameIntoClientArea) for customizing the frame to fit your needs. See Custom Window Frame Using DWM at http://msdn.microsoft.com/en-us/library/windows/desktop/bb688195.aspx

    2) Do not use WS_POPUP, but WS_BORDER and use tricks that will fool Windows to NEVER renders the borders. It seems that's what VS2012 is doing.

    Don't forget: flickering INSIDE the window is another story, I am just talking about the right/bottom edge "stability" here.

提交回复
热议问题