烈性摔跤无删减在线看:谁会vc++帮我解决一个问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/09 04:53:28
谁会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(-y,x,linecolor);
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(y,-x,linecolor);
}
}

void CMYCIRCLEDlg::Draw(int x, int y,COLORREF linecolor)
{
CRect rect;
CWnd *pWnd=GetDlgItem(IDC_SHOW);//获得控件IDC_DRAW的窗口指针
pWnd->UpdateWindow();//避免系统自动重绘
CDC *pDC=pWnd->GetDC();//获得所需要的绘图设备环境
pWnd->GetClientRect(&rect);
int X,Y;
X=x+m_x;
Y=y+m_y;
CPen mypen;
mypen.CreatePen(PS_SOLID,1,linecolor);
CPen *pOldPen=pDC->SelectObject(&mypen);
pDC->Ellipse(X,Y,X+3,Y+3);
pDC->SelectObject(pOldPen);//恢复设备环境原来的画刷设置
Sleep(1);
}

我把你的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) & ~31) >> 3) * BMIH.biHeight;
hDrawingSurface = CreateDIBSection(dcMemory.GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&pDrawingSurfaceBits, NULL, 0);

dcMemory.SelectObject ( hDrawingSurface );

CPen mypen;
mypen.CreatePen(PS_SOLID,1,linecolor);

CPen *pOldPen=dcMemory.SelectObject(&mypen);
dcMemory.FillSolidRect ( &rect, RGB(0xff,0xff,0xff));

for ( int i = 0 ; i < r ; i ++ )
{
dcMemory.Ellipse ( i,i,2*r-i,2*r-i );
}

pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcMemory,0,0,SRCCOPY);

dcMemory.SelectObject(pOldPen);

}