Win32 鼠标绘图代码研究
生活随笔
收集整理的這篇文章主要介紹了
Win32 鼠标绘图代码研究
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
http://download.csdn.net/detail/u012313945/9534690
下面摘錄繪圖部分代碼以供研究;winmain和相關窗口過程函數(shù)參閱相關資料;
void DrawMyRect(HDC hdc, PMYPIC pRect) // 繪制一個矩形 {HPEN hPen = CreatePenIndirect(&(pRect->logpen));HPEN hPenOld = (HPEN)SelectObject(hdc, hPen);HBRUSH hNewBrush = CreateBrushIndirect (&(pRect->logbrush));HBRUSH hOldBrush = (HBRUSH)SelectObject (hdc, hNewBrush);Rectangle(hdc,pRect->ptS.x,pRect->ptS.y,pRect->ptE.x,pRect->ptE.y);SelectObject(hdc, hPenOld);DeleteObject(hPen);SelectObject(hdc,hOldBrush);DeleteObject(hNewBrush); }
void DrawMyEll(HDC hdc, PMYPIC pRect) // 繪制一個橢圓 {HPEN hPen = CreatePenIndirect(&(pRect->logpen));HPEN hPenOld = (HPEN)SelectObject(hdc, hPen);HBRUSH hNewBrush = CreateBrushIndirect (&(pRect->logbrush));HBRUSH hOldBrush = (HBRUSH)SelectObject (hdc, hNewBrush);Ellipse(hdc,pRect->ptS.x,pRect->ptS.y,pRect->ptE.x,pRect->ptE.y);SelectObject(hdc, hPenOld);DeleteObject(hPen);SelectObject(hdc,hOldBrush);DeleteObject(hNewBrush); }
void DrawMyText(HDC hdc,PMYPIC pText) //畫文字 {HFONT hFont=CreateFontIndirect(&(pText->logfont));HFONT hFontOld = (HFONT)SelectObject (hdc, hFont);SetTextColor(hdc,pText->textColor);TextOut(hdc,(pText->ptS.x+pText->ptE.x)/2,(pText->ptS.y+pText->ptE.y)/2,pText->szText,lstrlen(pText->szText));GetTextExtentPoint32 (hdc,pText->szText, lstrlen (pText->szText), &pText->size);SelectObject(hdc,hFontOld);DeleteObject (hFont); }
int Sum_Pics(PMYPIC pPic,int len)//返回現(xiàn)有圖片總數(shù) {for (int i=0;i<len;i++){if (pPic[i].order==0)return i;}return 0;//保留 }
/*********************************** *判斷選中哪個圖形的函數(shù),返回選中圖形 *的次序,未選中返回0 ************************************/ int SelectedPic(POINT p, PMYPIC pPic,int len) {for (int i=Sum_Pics(pPic,len)-1;i>=0;i--){switch (pPic[i].DrawObj){case ID_PIC_LINE:/*if(abs((pPic[i].ptE.y-pPic[i].ptS.y)*p.x-(pPic[i].ptE.x-pPic[i].ptS.x)*p.y-pPic[i].ptS.x*(pPic[i].ptE.y-pPic[i].ptS.y)+pPic[i].ptS.y*(pPic[i].ptE.x-pPic[i].ptS.x))/sqrt(pow((pPic[i].ptE.y-pPic[i].ptS.y)*1.0,2)+pow((pPic[i].ptE.x-pPic[i].ptS.x)*1.0,2))<2)return pPic[i].order;*/ //點到直線的距離是錯誤的if((Dis_p2line(pPic[i].ptS,pPic[i].ptE,p))<=pPic[i].logpen.lopnWidth.x)return pPic[i].order;break;case ID_PIC_RECT:if(abs(pPic[i].ptS.x-p.x)+abs(pPic[i].ptE.x-p.x)<=abs(pPic[i].ptS.x-pPic[i].ptE.x) && abs(pPic[i].ptS.y-p.y)+abs(pPic[i].ptE.y-p.y)<=abs(pPic[i].ptS.y-pPic[i].ptE.y))return pPic[i].order;break;case ID_PIC_ELL:if((p.x-(pPic[i].ptS.x+pPic[i].ptE.x)/2.0)*(p.x-(pPic[i].ptS.x+pPic[i].ptE.x)/2.0)/(((pPic[i].ptS.x-pPic[i].ptE.x)/2.0)*((pPic[i].ptS.x-pPic[i].ptE.x)/2.0))+(p.y-(pPic[i].ptS.y+pPic[i].ptE.y)/2.0)*(p.y-(pPic[i].ptS.y+pPic[i].ptE.y)/2.0)/(((pPic[i].ptS.y-pPic[i].ptE.y)/2.0)*((pPic[i].ptS.y-pPic[i].ptE.y)/2.0))<=1)return pPic[i].order;break;case ID_PIC_TEXT:if(abs(p.x-(pPic[i].ptS.x+pPic[i].ptE.x)/2)+abs(p.x-((pPic[i].ptS.x+pPic[i].ptE.x)/2+pPic[i].size.cx))<=pPic[i].size.cx && abs(p.y-(pPic[i].ptS.y+pPic[i].ptE.y)/2)+abs(p.y-((pPic[i].ptS.y+pPic[i].ptE.y)/2+pPic[i].size.cy))<=pPic[i].size.cy)return pPic[i].order;break; default:break;}}return FALSE; }
void DeletePic(PMYPIC pPic,int order,int len)//刪除一個圖像 {for(int i=0;i<Sum_Pics(pPic,len)-order+1;i++){pPic[order-1+i]=pPic[order+i];pPic[order-1+i].order=order+i;//這句很關鍵} }//最后一個圖形的清零如何?
總結
以上是生活随笔為你收集整理的Win32 鼠标绘图代码研究的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VS 断点无法调试学习总结
- 下一篇: C# rdlc 报表学习总结