[英]How to get window transparency?
我正在嘗試使用此 function 來檢索 window alpha 值, GetLastError
有時會說'Access is denied'
,有時The parameter is incorrect
,在這兩種情況下 alpha 都是204
。
正在檢查其透明度的 window not
以管理員身份運行,我還嘗試以管理員身份運行calling
function 的進程,但我仍然遇到相同的錯誤。
會發生什么?
std::string GetLastErrorAsString(DWORD err) {
if (err == 0)
return std::string(); //No error message has been recorded
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
std::string message(messageBuffer, size);
LocalFree(messageBuffer);
return message;
}
DWORD GetWindowAlpha(HWND hWnd)
{
COLORREF color;
BYTE alpha;
DWORD flags;
GetLayeredWindowAttributes(hWnd, &color, &alpha, &flags);
GetLastErrorAsString(GetLastError());
return DWORD(alpha);
}
function 位於 dll內部,它檢查不同進程的 window alpha。
SetLayeredWindowAttributes
並不是使 windows 透明的唯一方法。 MSDN 在GetLayeredWindowAttributes
文檔的底部有一個注釋:
僅當應用程序先前已在 window 上調用過
GetLayeredWindowAttributes
時,才能調用SetLayeredWindowAttributes
。 如果使用UpdateLayeredWindow
設置分層 window ,則 function 將失敗。
在沒有WS_EX_LAYERED
的 window 上調用它可能是未定義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.