自绘用于调整大小的“粒状”(grippie)

VS2008在非最大化时的状态栏上会有一个用于调整大小的“粒状”(grippie),我们自己的自绘窗口经常也需要这么一个东西,本文说的就是这个东西的实现。

 

图1:vs2008的grippie

自绘用于调整大小的“粒状”(grippie)_第1张图片


图2:vs2008的grippie放大后的样子

自绘用于调整大小的“粒状”(grippie)_第2张图片


图3:我的实现效果

自绘用于调整大小的“粒状”(grippie)_第3张图片

 

实现其实很简单,截个图,放大,原来就是画些点,具体还是贴代码吧:)

gdi和gdi+的代码其实没有本质的区别,我刚好都试了下,就顺便都贴出来和大家分享。

先看gdi的

<textarea cols="50" rows="15" name="code" class="cpp">/* @ Function : _DrawSizeGrip @ brief : 自绘用于调整大小的&ldquo;粒状&rdquo;(grippie) @ parameter : hDC @ parameter : rcClient,会在rcClient的右5下脚画,可以是窗口的GetClientRect @ return : @ remark : @ Date : 2009/9/7 22:01:57 debehe @*/ void _DrawSizeGrip(HDC hDC, CRect rcClient) { // 一个大点由四个小点组成 // 小的宽 const int SMALL_POINT_WIDTH = 1; // 大点的宽 const int LARGE_POINT_WIDTH = 2; const int LARGE_POINT_OFFSET= 3; CRect rcLargePoint = rcClient; rcLargePoint.right -= LARGE_POINT_WIDTH; rcLargePoint.bottom -= LARGE_POINT_WIDTH; rcLargePoint.top = rcLargePoint.bottom - LARGE_POINT_WIDTH; rcLargePoint.left = rcLargePoint.right - LARGE_POINT_WIDTH; __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, -LARGE_POINT_OFFSET); __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, -LARGE_POINT_OFFSET); __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(-LARGE_POINT_OFFSET, LARGE_POINT_OFFSET); __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, LARGE_POINT_OFFSET); __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(-LARGE_POINT_OFFSET, 0); __DrawGrip4Point(hDC, rcLargePoint, SMALL_POINT_WIDTH); } void __DrawGrip4Point(HDC hDC, CRect rcPoint, int nPointWidth) { // 4个点,每个点的大小为nPointWidth CRect rcItem = rcPoint; rcItem.left = rcItem.right - nPointWidth; rcItem.top = rcItem.bottom - nPointWidth; HBRUSH hBrush = (HBRUSH)GetStockObject(DKGRAY_BRUSH); FillRect(hDC, &amp;rcItem, hBrush); rcItem.OffsetRect(0, -nPointWidth); hBrush = (HBRUSH)GetStockObject(GRAY_BRUSH); FillRect(hDC, &amp;rcItem, hBrush); rcItem.OffsetRect(-nPointWidth, 0); hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH); FillRect(hDC, &amp;rcItem, hBrush); rcItem.OffsetRect(0, nPointWidth); hBrush = (HBRUSH)GetStockObject(GRAY_BRUSH); FillRect(hDC, &amp;rcItem, hBrush); }</textarea>

 

再看gdi+的

<textarea cols="50" rows="15" name="code" class="cpp">/* @ Function : _DrawSizeGrip @ brief : 自绘用于调整大小的&ldquo;粒状&rdquo;(grippie) @ parameter : hDC @ parameter : rcClient,会在rcClient的右5下脚画,可以是窗口的GetClientRect @ return : @ remark : @ Date : 2009/9/7 22:01:57 debehe @*/ void _DrawSizeGrip(Graphics* pGraphisc, CRect rcClient) { // 一个大点由四个小点组成 // 小的宽 const int SMALL_POINT_WIDTH = 1; // 大点的宽 const int LARGE_POINT_WIDTH = 2; const int LARGE_POINT_OFFSET= 3; CRect rcLargePoint = rcClient; rcLargePoint.right -= LARGE_POINT_WIDTH; rcLargePoint.bottom -= LARGE_POINT_WIDTH; rcLargePoint.top = rcLargePoint.bottom - LARGE_POINT_WIDTH; rcLargePoint.left = rcLargePoint.right - LARGE_POINT_WIDTH; __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, -LARGE_POINT_OFFSET); __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, -LARGE_POINT_OFFSET); __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(-LARGE_POINT_OFFSET, LARGE_POINT_OFFSET); __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(0, LARGE_POINT_OFFSET); __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); rcLargePoint.OffsetRect(-LARGE_POINT_OFFSET, 0); __DrawGrip4Point(pGraphisc, rcLargePoint, SMALL_POINT_WIDTH); } void __DrawGrip4Point(Graphics* pGraphisc, CRect rcPoint, int nPointWidth) { // 4个点,每个点的大小为nPointWidth SolidBrush penDkGray(Color(0xFE, 0xA9, 0xA9, 0xA9)); SolidBrush penGray(Color(0xFE, 0x80, 0x80, 0x80)); SolidBrush penWhite(Color(0xFE, 0xFF, 0xFF, 0xFF)); CRect rcItem = rcPoint; rcItem.left = rcItem.right - nPointWidth; rcItem.top = rcItem.bottom - nPointWidth; pGraphisc-&gt;FillRectangle(&amp;penDkGray, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height()); rcItem.OffsetRect(0, -nPointWidth); pGraphisc-&gt;FillRectangle(&amp;penGray, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height()); rcItem.OffsetRect(-nPointWidth, 0); pGraphisc-&gt;FillRectangle(&amp;penWhite, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height()); rcItem.OffsetRect(0, nPointWidth); pGraphisc-&gt;FillRectangle(&amp;penGray, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height()); }</textarea>

 

-- theEnd --

你可能感兴趣的:(自绘用于调整大小的“粒状”(grippie))