Draging a Window by the Top Level Menu.

Orlando Gondar 61 Reputation points

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.


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,488 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 42,181 Reputation points

    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;
                    return result;
                return result;

    And these are the results -


    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,351 Reputation points Microsoft Vendor


    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;

    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.


    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.