C# 区域填充

        protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WinUser.WM_CREATE:
break;
case WinUser.WM_PAINT:
break;
case WinUser.WM_LBUTTONDOWN:
POINT point;
point.x = WinUser.LOWORD((int)m.LParam);
point.y = WinUser.HIWORD((int)m.LParam);
ElliRgns(this.Handle, point);
break;
}
}

/// <summary>
/// 创建椭圆区域, 并进行填充
/// </summary>
/// <param name="hwnd"></param>
/// <param name="point"></param>
unsafe void ElliRgns(IntPtr hwnd, POINT point)
{
RECT rect, rectClient;
IntPtr hrgn;
IntPtr hBrush, hBrushOld;

//DC
IntPtr hdc = Win32Native.GetDC(hwnd);
Win32Native.GetClientRect(hwnd, &rectClient);

//点周围一块区域
rect.left = point.x - 40;
rect.right = point.x + 40;
rect.top = point.y - 30;
rect.bottom = point.y + 30;

//创建区域
hrgn = Win32Native.CreateEllipticRgnIndirect(&rect);

//创建画刷
hBrush = Win32Native.CreateSolidBrush(WinUser.RGB(0, 255, 0));
hBrushOld = Win32Native.SelectObject(hdc, hBrush);

//为 DC 选择画刷
Win32Native.SelectObject(hdc, hBrush);

//绘制区域
Win32Native.PaintRgn(hdc, hrgn);

//稀放资源
hBrush = Win32Native.SelectObject(hdc, hBrushOld);
Win32Native.DeleteObject(hBrush);
Win32Native.DeleteObject(hrgn);
Win32Native.DeleteDC(hdc);
}

posted @ 2011-10-08 23:12  一浩瀚星空一  阅读(2091)  评论(0编辑  收藏  举报