idanshmu
idanshmu

Reputation: 5271

Create resizable window with fixed top coordinate

I'd like to implemented a window that its top coordinate is always X (for simplicity let's say 0). Meaning, the window's top side is fixed on 0 which is the top of the screen.

I've already implemented the window, set its position using SetWindowPos but I'm struggling maintaining its top coordinate value.

Upvotes: 1

Views: 237

Answers (1)

Barmak Shemirani
Barmak Shemirani

Reputation: 31659

You can create a window with no caption bar, for example

CreateWindow(className, title, WS_THICKFRAME | WS_POPUP, ...)

Then override WM_NCHITTEST to change the requests for moving the window up and down.

If window has caption bar, for example:

CreateWindow(className, title, WS_OVERLAPPEDWINDOW, ...)

Then add override for WM_WINDOWPOSCHANGING as well:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {

    case WM_NCHITTEST:
    {
        LRESULT lresult = DefWindowProc(hwnd, msg, wParam, lParam);
        switch (lresult)
        {
        case HTTOP:      lresult = HTCLIENT; break;
        case HTTOPLEFT:  lresult = HTLEFT;   break;
        case HTTOPRIGHT: lresult = HTRIGHT;  break;
        }
        return lresult;
    }

    case WM_WINDOWPOSCHANGING:
    {
        WINDOWPOS* wndpos = (WINDOWPOS*)lParam;
        wndpos->y = 100;//choose a fixed position
        break;
    }

    ...
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

Upvotes: 1

Related Questions