GDI+绘制圆环,抗锯齿

COLORREF m_crOuterClr;
COLORREF m_crInnerClr;
CSize m_sizeInnerPos;

void CRoundWnd::OnPaint(Gdiplus::Graphics* dc)
{
    //抗锯齿 
	dc->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);

	//外圆
	Gdiplus::Pen pen(Gdiplus::Color(255, GetRValue(m_crOuterClr), GetGValue(m_crOuterClr), GetBValue(m_crOuterClr)));
	dc->DrawEllipse(&pen, m_rcWindow.left, m_rcWindow.top, m_rcWindow.Width(), m_rcWindow.Height());
 
 	Gdiplus::SolidBrush brush(Gdiplus::Color(255, GetRValue(m_crOuterClr), GetGValue(m_crOuterClr), GetBValue(m_crOuterClr)));
 	dc->FillEllipse(&brush, m_rcWindow.left, m_rcWindow.top, m_rcWindow.Width(), m_rcWindow.Height());
 
 	//内圆
 	Gdiplus::SolidBrush brush2(Gdiplus::Color(255, GetRValue(m_crInnerClr), GetGValue(m_crInnerClr), GetBValue(m_crInnerClr)));
 	dc->FillEllipse(&brush2, 
 		m_rcWindow.left+m_sizeInnerPos.cx, 
 		m_rcWindow.top+m_sizeInnerPos.cy, 
 		m_rcWindow.Width() - m_sizeInnerPos.cx*2, 
 		m_rcWindow.Height() - m_sizeInnerPos.cy*2);
 
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 GDI+ 在窗口中绘制滚动条,你可以使用 `Graphics` 类来绘制滚动条的背景和滑块。下面是一个示例代码,展示了如何在 C++ 中使用 GDI+ 绘制一个简单的垂直滚动条: ```cpp #include <iostream> #include <windows.h> #include <gdiplus.h> using namespace Gdiplus; LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // 创建窗口 HWND hWnd; WNDCLASSEX wc = {}; wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = L"ScrollBarExample"; RegisterClassEx(&wc); hWnd = CreateWindowEx(0, L"ScrollBarExample", L"ScrollBar Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // 初始化 GDI+ GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); // 消息循环 MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // 清理 GDI+ GdiplusShutdown(gdiplusToken); return static_cast<int>(msg.wParam); } LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); // 创建 Graphics 对象 Graphics graphics(hdc); // 获取窗口尺寸 RECT rect; GetClientRect(hWnd, &rect); int width = rect.right - rect.left; int height = rect.bottom - rect.top; // 绘制滚动条背景 SolidBrush backBrush(Color(220, 220, 220)); graphics.FillRectangle(&backBrush, width - 20, 0, 20, height); // 绘制滑块 int thumbHeight = 50; // 滑块的高度 int thumbTop = 0; // 滑块的顶部坐标,根据实际需要计算 SolidBrush thumbBrush(Color(100, 100, 100)); graphics.FillRectangle(&thumbBrush, width - 20, thumbTop, 20, thumbHeight); EndPaint(hWnd, &ps); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } ``` 上述代码创建了一个简单的窗口,并在窗口的右侧绘制了一个垂直滚动条。在 `WM_PAINT` 消息处理函数中,我们创建了一个 `Graphics` 对象,并使用 `FillRectangle` 函数绘制了滚动条的背景和滑块。滑块的位置和大小可以根据实际需求进行计算和调整。 请注意,上述代码中的 `ScrollBarExample` 需要根据你的实际情况进行替换。此外,你需要在项目中链接 GDI+ 库,并包含相应的头文件和命名空间。 希望这对你有帮助!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值