我想实现一个窗口,它的顶部坐标总是 X (为简单起见,假设为0)。意思是,窗口的顶部固定在0,这是屏幕的顶部。
我已经实现了窗口,使用SetWindowPos设置其位置,但我正在努力维持其顶部坐标值。
答案 0 :(得分:1)
您可以创建一个没有标题栏的窗口,例如
CreateWindow(className, title, WS_THICKFRAME | WS_POPUP, ...)
然后覆盖WM_NCHITTEST
以更改上下移动窗口的请求。
如果窗口有标题栏,例如:
CreateWindow(className, title, WS_OVERLAPPEDWINDOW, ...)
然后为WM_WINDOWPOSCHANGING
添加覆盖:
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);
}