Draging a Window by the Top Level Menu.

Orlando Gondar 61 Reputation points
2023-03-07T22:03:18.6333333+00:00

Hello I do not know is this is possible, but I create a Window that only have
a Client Area and a Menu Resource.
Is there a way that I can drag a the window by holding the Menu?

I know how to do this on a area of the Window's Client Area, but I wonder if
something similar could be done to a Menu.

Thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,427 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,656 Reputation points
    2023-03-08T11:54:57.22+00:00

    Try this -

        case WM_NCHITTEST:
        {
            auto result = DefWindowProc(hWnd, message, wParam, lParam);
            if (result == HTMENU)
            {
                HMENU hBar = GetMenu(hWnd);
                auto x = GET_X_LPARAM(lParam);
                auto y = GET_Y_LPARAM(lParam);
                auto item = MenuItemFromPoint(hWnd, hBar, POINT{ x, y });
                if (item == -1)
                    return HTCAPTION;
                else
                    return result;
            }
            else
                return result;
        }
        break;
    

    And these are the results -

    MenuDrag

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,181 Reputation points Microsoft Vendor
    2023-03-08T02:22:51.1366667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You could try to use WM_NCHITTEST message. If you want to drag the window by holding the Menu. You could refer to the code:

    case WM_NCHITTEST: {
        LRESULT hit = DefWindowProc(hWnd, message, wParam, lParam);
        if (hit == HTMENU) { 
             hit = HTCAPTION;
        }
        return hit;
        break;
    }
    

    However, this will make interaction with your application very difficult. You couldn't click the File/Help buttons. So, I couldn't advise you to do that.

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.