是否可以创建仅带有边框的winapi窗口 [英] Is it possible to create a winapi window with only borders
问题描述
因此,我试图创建一个仅显示其边框并使其余部分透明的窗口.我创建了一个脑海中的样机:
我尝试在具有透明像素的缓冲区中发条,但效果不理想.
有什么想法吗?
可以通过传递
有关内部结构以及常见用例的更多信息,请参见Kenny Kerr于2014年6月发表的出色的MSDN杂志文章带有C ++的Windows:使用Windows合成引擎的高性能窗口分层.
1 这需要启用桌面合成.桌面合成在所有受支持的Windows版本中都可用,但是在Windows 8之前,可由用户/系统管理员禁用. So I'm trying to create a window that only shows its borders and have the rest of the body be see through.
I've created a mockup of what that would look like in my head: I tried blitting in a buffer with transparent pixels but that did not have the desired effect. Any ideas ? This is possible by passing the WS_EX_NOREDIRECTIONBITMAP1 extended window style to a call to CreateWindowEx. This prevents the system from allocating a render surface for the window's client area, leaving the client area completely transparent. Note, that this does not make the window transparent to mouse clicks. Hit testing is still governed by the window, even if it doesn't have a visible client area. The following code provides a minimal code sample that showcases the use: This produces output similar to the following screenshot: More information on the internals, as well as a common use case can be found in Kenny Kerr's excellent June 2014 MSDN Magazine article Windows with C++ : High-Performance Window Layering Using the Windows Composition Engine. 1 This requires desktop composition to be enabled. Desktop composition is available in all supported versions of Windows, but can be disabled by the user/system administrator prior to Windows 8. 这篇关于是否可以创建仅带有边框的winapi窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!#define UNICODE
#include <Windows.h>
#pragma comment(lib, "user32.lib")
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int) {
WNDCLASSW wc{};
wc.hCursor = ::LoadCursorW(nullptr, IDC_ARROW);
wc.hInstance = hInstance;
wc.lpszClassName = L"TransparentWindow";
wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -> LRESULT
{
switch (message) {
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
default:
return ::DefWindowProcW(hWnd, message, wParam, lParam);
}
};
::RegisterClassW(&wc);
::CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP, wc.lpszClassName, L"Transparent window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
nullptr, nullptr, hInstance, nullptr);
MSG msg{};
while (::GetMessageW(&msg, nullptr, 0, 0) > 0) {
::DispatchMessageW(&msg);
}
return msg.wParam;
}