VC 畫座標 方法2

2021-06-22 05:15:58 字數 2706 閱讀 9623

//

//*******畫座標圖*******

//crect rect(250,300,600,600);

//getclientrect(&rect);

int nxlength=rect.width();

int nylength=rect.height();

int nxdivisionnumber = 7;

int nydivisionnumber = 6;

int nmeshlength;

cstring str;

int i;

cdc* pdc = this->getdc();

//     pdc->rectangle(0,0,nxlength,nylength);

cpen* ppenred = new cpen;                                          //建立畫筆物件

ppenred->createpen(ps_solid, 1, rgb(255,0,0));  //紅色畫筆

cpen* ppengreen = new cpen;                                //建立畫筆物件

ppengreen->createpen(ps_solid, 1, rgb(0,255,0));//綠色畫筆

cpen* ppenblue = new cpen;                                  //建立畫筆物件

ppenblue->createpen(ps_dot, 1, rgb(0,0,255));     //藍色畫筆

cpen* ppenblack = new cpen;                                 //建立畫筆物件

ppenblack->createpen(ps_solid, 1, rgb(0,0,0)); //黑色畫筆

//選中黑色畫筆,並儲存當前畫筆

cgdiobject* poldpen = pdc->selectobject(ppenblack);

pdc->moveto(rect.left,rect.top);                              //繪製座標軸

pdc->lineto(rect.left,rect.bottom);                  //垂直軸

pdc->lineto(rect.right,rect.bottom);   //水平軸

//橫座標箭頭

pdc->moveto(rect.right,rect.bottom);

pdc->lineto(rect.right-10,rect.bottom-3);

pdc->lineto(rect.right-10,rect.bottom+3);

pdc->lineto(rect.right,rect.bottom);

//縱座標箭頭

pdc->moveto(rect.left ,rect.top);

pdc->lineto(rect.left-3,rect.top+10);

pdc->lineto(rect.left+3,rect.top+10);

pdc->lineto(rect.left ,rect.top);

pdc->setbkmode(transparent);  //設定背景透明

//橫座標數字

nmeshlength = (nxlength-40)/(nxdivisionnumber+1);

for (i=1; itextout(rect.left-5+i*nmeshlength, rect.bottom+5, str);

}//橫座標標識

str.format("資料序列");

pdc->textout(rect.left-5+i*nmeshlength,rect.bottom+5,str);

//縱座標數字

nmeshlength = (nylength-40)/(nydivisionnumber+1);

for (i=0; itextout(rect.left-30, rect.bottom-i*nmeshlength, str);

}//縱座標標識

str.format("電壓(v)");

pdc->textout(rect.left+10,rect.top-15,str);

//網格線

pdc->selectobject(ppenblue);

nmeshlength = (nxlength-40)/(nxdivisionnumber+1);

for (i=1; imoveto(rect.left+i*nmeshlength,rect.bottom);

pdc->lineto(rect.left+i*nmeshlength,rect.top);

}nmeshlength = (nylength-40)/(nydivisionnumber+1);

for (i=1; imoveto(rect.left , rect.bottom-i*nmeshlength);

pdc->lineto(rect.right, rect.bottom-i*nmeshlength);

}//恢復以前的畫筆

pdc->selectobject(poldpen);

delete ppenred;

delete ppengreen;

delete ppenblue;

delete ppenblack;

地理座標與螢幕座標轉換(VC )

在底層gis開發中,我們經常會碰到空間資料視覺化問題,當我們拿到地理資料之後,我們該怎麼把它展現在我們的計算機螢幕中呢,這或許是乙個比較簡單的問題。我們知道,地理座標系是我們使用者自定義的座標系,而顯示在計算機螢幕上的座標是基於螢幕座標來繪製的,那麼改如何轉化呢?首先,我們來熟悉幾個概念 地理座標系...

VC 畫刷和畫筆

建立畫筆 cpen pen ps solid,1,rgb 255,0,0 cpen poldpen dc.selectobject pen dc.selectobject poldpen 建立普通畫刷 cclientdc dc this cbrush brush rgb 255,0,0 dc.fil...

VC 獲取滑鼠點座標

onlbuttondown 傳入的point座標為客戶區座標,而輸出矩形為窗體座標,point縱座標需要加上 標題欄高度 26 和對話方塊高度 3 point橫座標需要加上 對話方塊寬度 3 int captionheight getsystemmetrics sm cycaption 標題欄高度 ...