我有起始鼠标坐标 – x1和y1以及结束坐标x2和y2.如你所见,我强迫y2(temp_shape.bottom)为= y1(x2-x1).这不符合预期.我知道计算是完全错误的,但任何关于什么是正确的想法?
代码如下.
case WM_PAINT: { hdc = BeginPaint(hWnd,&ps); // Todo: Add any drawing code here... RECT rect; GetClIEntRect(hWnd,&rect); HDC backbuffDC = CreateCompatibleDC(hdc); HBITMAP backbuffer = CreateCompatibleBitmap( hdc,rect.right,rect.bottom); int savedDC = SaveDC(backbuffDC); SelectObject( backbuffDC,backbuffer ); HBrush hBrush = CreateSolIDBrush(RGB(255,255,255)); FillRect(backbuffDC,&rect,hBrush); DeleteObject(hBrush); //Brush and Pen colours SelectObject(backbuffDC,GetStockObject(DC_Brush)); SetDCBrushcolor(backbuffDC,RGB(255,0)); SelectObject(backbuffDC,GetStockObject(DC_PEN)); SetDCPencolor(backbuffDC,RGB(0,0)); //Shape Coordinates temp_shape.left=x1; temp_shape.top=y1; temp_shape.right=x2; temp_shape.bottom=y2; //Draw old Shapes //Rectangles for ( int i = 0; i < current_rect_count; i++ ) { Rectangle(backbuffDC,rect_List[i].left,rect_List[i].top,rect_List[i].right,rect_List[i].bottom); } //Ellipses for ( int i = 0; i < current_ellipse_count; i++ ) { Ellipse(backbuffDC,ellipse_List[i].left,ellipse_List[i].top,ellipse_List[i].right,ellipse_List[i].bottom); } if(mouse_down) { if(drawCircle) { temp_shape.right=y1+(x2-x1); Ellipse(backbuffDC,temp_shape.left,temp_shape.top,temp_shape.right,temp_shape.bottom); } if(drawRect) { Rectangle(backbuffDC,temp_shape.bottom); } if(drawEllipse) { Ellipse(backbuffDC,temp_shape.bottom); } } BitBlt(hdc,rect.bottom,backbuffDC,SRCcopY); RestoreDC(backbuffDC,savedDC); DeleteObject(backbuffer); DeleteDC(backbuffDC); EndPaint(hWnd,&ps); } break;解决方法 如果你想让椭圆()绘制一个完美的圆形圆,你需要给它一个完美的方形形状的坐标,而不是矩形.
假设x1,y1是拖动和x2的起始坐标,y2是当前鼠标坐标,那么试试这个:
//Shape Coordinatestemp_shape.left = min(x1,x2);temp_shape.top = min(y1,y2);temp_shape.right = max(x1,x2);temp_shape.bottom = max(y1,y2);...if (drawCircle){ int length = min(abs(x2-x1),abs(y2-y1)); if (x2 < x1) temp_shape.left = temp_shape.right - length; else temp_shape.right = temp_shape.left + length; if (y2 < y1) temp_shape.top = temp_shape.bottom - length; else temp_shape.bottom = temp_shape.top + length; Ellipse(backbuffDC,temp_shape.bottom);}总结
以上是内存溢出为你收集整理的c – Win32 GDI画一个圆圈?全部内容,希望文章能够帮你解决c – Win32 GDI画一个圆圈?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)