谁会vc++帮我解决一个问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:14:16
谁会vc++帮我解决一个问题
怎么样用画圆超出picture控件不显示?
那个圆是用中点画圆法画的
void CMYCIRCLEDlg::MidpointCircle(int r,COLORREF linecolor)
{
CRect rect;
CWnd *pWnd=(CWnd *)GetDlgItem(IDC_SHOW);//获得控件IDC_DRAW的窗口指针
CDC *pDC=pWnd->GetDC();//获得所需要的绘图设备环境
pWnd->GetClientRect(&rect);
int x,y;
double d;
x=0;
y=r;
d=1.25-r;
Draw(x, y,linecolor); //显示圆弧上的八个对称点
while(x<=y)
{
if(d<0)
d+=2*x+3;
else
{
d+=2*(x-y)+5;
y--;
}
x++;
if(y>rect.left && y<rect.right && x>rect.bottom && x<rect.top)
Draw(y,x,linecolor);
if(x>rect.left && x<rect.right && y>rect.bottom && y<rect.top)
Draw(x,y,linecolor);
if(-x>rect.left && -x<rect.right && y>rect.bottom && y<rect.top)
Draw(-x,y,linecolor);
if(-y>rect.left && -y<rect.right && x>rect.bottom && x<rect.top

我把你的Draw函数去掉了
基本原理就是
在内存中建一个 大小为 2r * 2r 的图片
如果2r 小于 picture控件 宽度或高度 ,则建立控件大小图片。
然后对其填充画圆
在内存中画完以后,将其拷贝到Picture控件上去。而且只拷贝Picture控件大小的区域。则超过部分就不会被显示了。

void CMYCIRCLEDlg::MidpointCircle(int r, COLORREF linecolor)
{
CRect rect;
CWnd *pWnd=(CWnd *)GetDlgItem(IDC_SHOW);
CDC *pDC=pWnd->GetDC();
pWnd->GetClientRect(&rect);

CDC dcMemory ;
dcMemory .CreateCompatibleDC ( NULL );

int nW = 2*r > rect.Width() ? 2*r : rect.Width();
int nH = 2*r > rect.Height() ? 2*r : rect.Height();

BYTE* pDrawingSurfaceBits;
HBITMAP hDrawingSurface;
BITMAPINFOHEADER BMIH;
BMIH.biSize = sizeof(BITMAPINFOHEADER);
BMIH.biBitCount = 24;
BMIH.biPlanes = 1;
BMIH.biCompression = BI_RGB;
BMIH.biWidth = nW;
BMIH.biHeight = nH;
BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount) + 31) & ~3