win32-window-custom-titlebar icon indicating copy to clipboard operation
win32-window-custom-titlebar copied to clipboard

Some issues along with their fixes

Open RCECoder opened this issue 2 years ago • 2 comments

Hey, nice coding there!

There are some issues I ran into when I tested this code: When the window is maximized, double clicking the far top caption doesn't un maximize the window (it does only if you double click slightly below the far top)

Fix is simple by handling WM_NCLBUTTONDBLCLK message like so

case WM_NCLBUTTONDBLCLK: {
        POINT cursor_point;
        CURSORINFO curInfo;
        curInfo.cbSize = sizeof(CURSORINFO);
        if (w_param == HTTOP)
        {
            GetCursorInfo(&curInfo);
            HCURSOR curHandle = LoadCursor(NULL, IDC_ARROW);
            if (curHandle == curInfo.hCursor) {
                //Fixes double click on far top to un maximize when the window is maximized...
                w_param = HTCAPTION;
                return DefWindowProc(handle, message, w_param, l_param);
            }
        }

    }

Another issue is when you hover your mouse over the top of the Min/Max/Close buttons, the buttons will be hovered which is not the correct behavior on default caption bar under Windows 10. This happens even though the mouse cursor type is actually an IDC_SIZENS which when clicked, it should not click the button but does the resize.

I fixed it by making a compare to hover the buttons only if mouse cursor is IDC_ARROW.

POINT cursor_point;
        CURSORINFO curInfo;
        curInfo.cbSize = sizeof(CURSORINFO);


if (PtInRect(&button_rects.close, cursor_point)) {
            GetCursorInfo(&curInfo);
            HCURSOR curHandle = LoadCursor(NULL, IDC_ARROW);
            if (curHandle == curInfo.hCursor) {
                new_hovered_button = CustomTitleBarHoveredButton_Close;

            }
            
        }
        else if (PtInRect(&button_rects.minimize, cursor_point)) {
            
            GetCursorInfo(&curInfo);
            HCURSOR curHandle = LoadCursor(NULL, IDC_ARROW);

            if (curHandle == curInfo.hCursor) {
                new_hovered_button = CustomTitleBarHoveredButton_Minimize;

            }
        }
        else if (PtInRect(&button_rects.maximize, cursor_point)) {
            GetCursorInfo(&curInfo);
            HCURSOR curHandle = LoadCursor(NULL, IDC_ARROW);
            if (curHandle == curInfo.hCursor) {
                new_hovered_button = CustomTitleBarHoveredButton_Maximize;

            }
            
        }
 

Just a question, this code seems to require minimum Windows 10, version 1703 due to the DPI Awareness APIs used. Am I right?

RCECoder avatar Aug 03 '23 02:08 RCECoder

Another issue: Menu don't draw properly. If we add menu to our app, it will not be visible until we click away to make app lose focus. Very weird issue...

Same happened here: https://microsoft.public.win32.programmer.ui.narkive.com/ljlMM4jg/my-menu-bar-is-disappeared

By commenting out handling of WM_NCCALCSIZE message, the issue disappears so it seems that this is the offending code...

RCECoder avatar Aug 03 '23 17:08 RCECoder

@RCECoder sorry for the long wait and thanks for the fixes.

Could you please make a PR with them? That way it would be a lot easier for me to review / accept them and you would also get the appropriate attribution in the repo Contributor's list. Thanks again.

Regarding the menu bar - I am drawing everything manually in my app, so it is not an issue, but if we find a solution that would be great as well.

grassator avatar Aug 12 '23 18:08 grassator