最近學習自繪,寫好了繪圖函式,已經放到OnPaint()函式中顯示到界面了,譬如想修改圖中的某個引數,我怎么才能實作再次重繪呢?怎么把需要畫的圖再進入OnPaint()函式繪制出來,就現在這種情況怎么實作再繪圖一次,求大神指點,不知道怎么觸發條件再自繪一次
void CROMDlg::Painthead() //圖頭繪制部分
{
CDC *pDc =GetDlgItem(IDC_STATIC_Pic) -> GetDC();//獲取該控制元件的畫布
Graphics gr(pDc->m_hDC);
CRect rect;
GetClientRect(&rect);
Pen mypen(Color(0,0, 0), 3);//邊框粗線
int Width=rect.Width();
int Height=rect.Height();
Pen mypen1(Color(0,0, 0), 2);//畫圖曲線,第一列上
mypen1.SetDashStyle(DashStyle::DashStyleDashDotDot); //線條樣式
Pen mypen2(Color(255,0, 0), 2);//畫圖曲線,第一列
Gdiplus::Font myFont(L"Arial", 10);
SolidBrush brushB(Color(255,0,0,0));
Bitmap bmp(Width,Height*20);
Graphics* graphics = Graphics::FromImage(&bmp);
HatchBrush newBrush( HatchStyleCross, Color(2555, 255, 255, 255), Color(255, 255, 255,255));//白色
graphics->FillRectangle(&newBrush, 0, 0, Width, Height*20);//給畫圖區域填充白色背景
for(int i=0;i<600;i++)
{
graphics->DrawLine(&mypen, Width*i*0.01,0,Width*i*0.01,Height*100); //豎線
graphics->DrawLine(&mypen, 0,Height*i*0.05,Width,Height*i*0.05); //橫線
WCHAR buf[160];
wsprintfW(buf, L"%d", i);
graphics->DrawString(buf, -1, &myFont, PointF(0,Height*i*0.05), &brushB); //輸入標號
}
gr.DrawImage(&bmp,0,0,0,Height*5,Width,Height,UnitPixel);
}
void CROMDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于繪制的設備背景關系
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使圖示在作業區矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 繪制圖示
dc.DrawIcon(x, y, m_hIcon);
}
else
{
Painthead();
CDialogEx::OnPaint();
}
uj5u.com熱心網友回復:
你可以使用時鐘來執行繪制的函式uj5u.com熱心網友回復:
如果需要實時繪制建議用時鐘,如果繪制不頻繁,可以通過向視窗發送WM_PAINT訊息,或者呼叫重繪函式。uj5u.com熱心網友回復:
如果需要實時繪制建議用時鐘,如果繪制不頻繁,可以通過向視窗發送WM_PAINT訊息,或者呼叫重繪函式。uj5u.com熱心網友回復:
Invalidate();UpdateWindow();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/15801.html
標籤:基礎類
上一篇:c語言
下一篇:函式題 順序表的由于插入操作
