工序打紮流程(箭頭實現、重新整理畫面)

來源:互聯網
上載者:User

三、箭頭實現。

/////////////////////
//畫箭頭封裝調用函數實現
void CButtonTestDlg::ArrowTo(
CDC *pDC,              //畫刷
CPoint point,          //終點座標
int nPenStyle,          //線樣式
int nPenWidth,          //線寬度
COLORREF color, //顏色
int nWidth,            //三角形底邊寬度
float fTheta,          //三角形頂角角度
bool bFill              //是否填充顏色
)
{
CPen* pOldPen;
CPen pen(nPenStyle,nPenWidth,color);
pOldPen = pDC->SelectObject(&pen);

CBrush br,*pbrOld;
br.CreateSolidBrush(color);
pbrOld = pDC->SelectObject(&br);

//開始繪圖
POINT pFrom;
POINT pBase;
POINT aptPoly[3];
float vecLine[2];
float vecLeft[2];
float fLength;
float th;
float ta;

// get from point
MoveToEx(*pDC, 0, 0, &pFrom);

// set to point
aptPoly[0].x = point.x;
aptPoly[0].y = point.y;

// build the line vector
vecLine[0] = (float) aptPoly[0].x - pFrom.x;
vecLine[1] = (float) aptPoly[0].y - pFrom.y;

// build the arrow base vector - normal to the line
vecLeft[0] = -vecLine[1];
vecLeft[1] = vecLine[0];

// setup length parameters
fLength = (float) sqrt(vecLine[0] * vecLine[0] + vecLine[1] * vecLine[1]);
if (fLength < 0.1)
{
fLength = 0.1f;
}
th = nWidth / (2.0f * fLength);
ta = nWidth / (2.0f * (tanf(fTheta) / 2.0f) * fLength);

// find the base of the arrow
pBase.x = (int) (aptPoly[0].x + -ta * vecLine[0]);
pBase.y = (int) (aptPoly[0].y + -ta * vecLine[1]);

// build the points on the sides of the arrow
aptPoly[1].x = (int) (pBase.x + th * vecLeft[0]);
aptPoly[1].y = (int) (pBase.y + th * vecLeft[1]);
aptPoly[2].x = (int) (pBase.x + -th * vecLeft[0]);
aptPoly[2].y = (int) (pBase.y + -th * vecLeft[1]);

MoveToEx(*pDC, pFrom.x, pFrom.y, NULL);

// draw we're fillin'...
if(bFill) {
LineTo(*pDC, aptPoly[0].x, aptPoly[0].y);
Polygon(*pDC, aptPoly, 3); //畫實體三角形
}
// ... or even jes chillin'...
else
{
LineTo(*pDC, pBase.x, pBase.y);
LineTo(*pDC, aptPoly[1].x, aptPoly[1].y);
LineTo(*pDC, aptPoly[0].x, aptPoly[0].y);
LineTo(*pDC, aptPoly[2].x, aptPoly[2].y);
LineTo(*pDC, pBase.x, pBase.y);
MoveToEx(*pDC, aptPoly[0].x, aptPoly[0].y, NULL);
}
//結束繪圖

pDC->SelectObject(pOldPen);
pDC->SelectObject(pbrOld);
}

////////////////////////調用:
dc.MoveTo(points[0].x,points[0].y);
ArrowTo(&dc,points[1],PS_SOLID,1,RGB(0,0,0),10,45,false);

二、重新整理畫面。

DIALOG 屬性:clip children 設定為true。意思是在繪製對話方塊時剪輯子視窗,
也就是在調用Invalidate();的時候,不會重繪子視窗。可以保證在Invalidate();的時候,介面不會閃。

void CButtonTestDlg::OnPaint()
{
if (IsIconic())
{
///....
}
else
{
Invalidate();//必須先Invalidate,後CPaintDC dc(this);
CPaintDC dc(this); // 用於繪製的裝置上下文

CPoint points[2];
GetLinePoints((RFMSStepButton*)GetDlgItem(124),(RFMSStepButton*)GetDlgItem(125),points);

dc.MoveTo(points[0].x,points[0].y);
ArrowTo(&dc,points[1],PS_SOLID,1,RGB(0,0,0),10,45,false);

GetLinePoints((RFMSStepButton*)GetDlgItem(123),(RFMSStepButton*)GetDlgItem(125),points);
dc.MoveTo(points[0].x,points[0].y);
ArrowTo(&dc,points[1],PS_SOLID,1,RGB(0,0,0),10,45,true);

CDialog::OnPaint();
}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.