这段代码作用是什么HWND hWnd = (HWND)this->winId(); DWORD style = GetWindowLong(hWnd, GWL_STYLE); SetWindowLongPtr(hWnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION | WS_BORDER | WS_MAXIMIZEBOX); bool enabledComposition = QtWin::isCompositionEnabled(); if (true == enabledComposition) { SetWindowLong(hWnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION | WS_BORDER); QtWin::extendFrameIntoClientArea(this, 1, 1, 1, 1); }
时间: 2023-05-27 22:06:11 浏览: 276
这段代码的作用是将当前窗口的样式设置为具有标题、边框和最大化按钮的可调整大小的窗口(WS_THICKFRAME | WS_CAPTION | WS_BORDER | WS_MAXIMIZEBOX)。如果操作系统启用了Aero效果,则还会将窗口边框扩展到客户区域(extendFrameIntoClientArea),以使窗口与桌面背景融为一体。
相关问题
void Form::on_pushButton_clicked() { std::vector<HWND> windows; EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL { auto& windows = *reinterpret_cast<std::vector<HWND>*>(lParam); if (IsWindowVisible(hwnd)) { windows.push_back(hwnd); } return TRUE; }, reinterpret_cast<LPARAM>(&windows)); for (auto hwnd : windows) { const int max_title_size = 1024; TCHAR title[max_title_size]; GetWindowText(hwnd, title, max_title_size); std::wcout << title << std::endl; } }精简代码
这段代码已经很精简了,但是我们可以进一步简化它。
由于我们只需要获取窗口标题,因此我们可以使用 Qt 提供的 `QWindow::windowTitle()` 函数,而不是调用 Windows API 的 `GetWindowText` 函数。这样可以使代码更加简洁且可移植。
下面是修改后的代码:
```cpp
void Form::on_pushButton_clicked()
{
auto windows = qApp->allWindows();
for (auto window : windows)
{
auto qwindow = dynamic_cast<QWindow*>(window);
if (qwindow && qwindow->winId())
{
qDebug() << "Window Title: " << qwindow->windowTitle();
}
}
}
```
在这个示例中,我们使用 `qApp->allWindows()` 函数获取所有窗口,并将它们存储在 `windows` 变量中。然后遍历所有的窗口,并将它们转换为 `QWindow` 类型。如果转换成功并且 `winId()` 属性值不为零,则输出窗口的标题。注意,这个代码依赖于 Qt 框架,因此可以在不同的操作系统上运行。
windll.user32.GetWindowLongPtrW(hwnd, self.GWL_EXSTYLE) 这段代码在我的系统上报错。我在使用win10
这个问题可能是因为在 Windows 10 中,GetWindowLongPtrW 函数已被标记为弃用。您可以使用 GetWindowLongPtrA 或 GetWindowLongW 函数来代替。
您可以尝试以下代码,它将使用 GetWindowLongW 函数:
```
import ctypes
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
# 定义常量
GWL_EXSTYLE = -20
WS_EX_LAYERED = 0x00080000
# 获取窗口句柄
hwnd = user32.GetDesktopWindow()
# 获取窗口扩展样式
style = user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
# 检查窗口是否启用了 WS_EX_LAYERED 扩展样式
if style & WS_EX_LAYERED:
print("Enabled")
else:
print("Not enabled")
```
如果您需要使用 GetWindowLongPtrW 函数,您可以使用 ctypes.wintypes 模块中的 LONG_PTR 数据类型来指定函数返回值的类型。例如:
```
import ctypes
from ctypes import wintypes
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
# 定义常量
GWL_EXSTYLE = -20
WS_EX_LAYERED = 0x00080000
# 获取窗口句柄
hwnd = user32.GetDesktopWindow()
# 获取窗口扩展样式
style = user32.GetWindowLongPtrW(hwnd, GWL_EXSTYLE)
# 检查窗口是否启用了 WS_EX_LAYERED 扩展样式
if style & WS_EX_LAYERED:
print("Enabled")
else:
print("Not enabled")
```
我希望这可以帮助您解决问题。
阅读全文
相关推荐
















