Win32 C++ 将窗口位置设置为右下角

win32 c++ set window location to the right-down corner

本文关键字:设置 右下角 位置 窗口 C++ Win32      更新时间:2023-10-16

如何将窗口设置为屏幕的右下角(不包括任务栏(?我可以使用CreateWindowEx完成它吗?但我只看到了CW_USEDEFAULT,没有CW_把它放在角落里。

HWND hwnd = CreateWindowEx(
NULL,
DUCKPROC_CLASS_NAME,
DUCKPROC_WINDOW_TIP_NAME,
WS_BORDER| WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT, 
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
GetModuleHandle(NULL),
NULL
);

这是将窗口放置在右下角的示例。(这里我设置窗口的宽度和高度都是200。

RECT desktopRect;
if (!GetWindowRect(GetDesktopWindow(), &desktopRect))
return FALSE;
int windowWidth = 200;
int windowHeight = 200;
int posX = desktopRect.right - windowWidth;
int posY = desktopRect.bottom - windowHeight;
HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
posX, posY, windowWidth, windowHeight, nullptr, nullptr, hInstance, nullptr);

您可以使用 CreateWindowEx,但您不必这样做,因为:

创建具有扩展窗口的重叠窗口、弹出窗口或子窗口 风格;否则,此函数与创建窗口相同 功能。