我在Win32 C++中创建了一个透明复选框.我已经做到了,因为据我所知你在本机win32中没有透明复选框,我需要在NSIS安装程序中使用此复选框.
我的问题:当重新粉刷时,我不知道如何擦除我的透明背景,所以我可以在"清晰的画布上"画画.当用户更改复选框内的文本时,这很重要,我需要重新绘制它.我想我遇到了透明窗户必须得到的问题.
我可以清除透明窗口的方式是什么,注意我熟悉WinAPI,你不能真正清除窗口AFAIK,因为你只是在窗口重新绘制.所以我正在寻找关于我可以用来重绘窗口的技术的建议,例如:
我的代码:
case WM_SET_TEXT:
{
// set checkbox text
// Technique 1: update parent window to clear this window
RECT thisRect = {thisX, thisY, thisW, thisH};
InvalidateRect(parentHwnd, &thisRect, TRUE);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// Technique 2:
SetBkMode(hdc, TRANSPARENT);
Rectangle(hdc, thisX, thisY, thisW, thisH); // doesn't work just makes the window a big black rectangle?
EndPaint(hwnd, &ps);
}
break;
Run Code Online (Sandbox Code Playgroud)
您需要处理该WM_ERASEBBKGND消息。像下面这样的东西应该可以工作!
case WM_ERASEBKGND:
{
RECT rcWin;
RECT rcWnd;
HWND parWnd = GetParent( hwnd ); // Get the parent window.
HDC parDc = GetDC( parWnd ); // Get its DC.
GetWindowRect( hwnd, &rcWnd );
ScreenToClient( parWnd, &rcWnd ); // Convert to the parent's co-ordinates
GetClipBox(hdc, &rcWin );
// Copy from parent DC.
BitBlt( hdc, rcWin.left, rcWin.top, rcWin.right - rcWin.left,
rcWin.bottom - rcWin.top, parDC, rcWnd.left, rcWnd.top, SRC_COPY );
ReleaseDC( parWnd, parDC );
}
break;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4198 次 |
| 最近记录: |