关键代码提示: 关键代码提示:
“画刷”的例子 画刷” case WM_PAINT: hDC= BeginPaint(hWnd, &; PtStr); hBrush1 = CreateHatchBrush(HS_CROSS,RGB(255,0,0)); hBrush2 =(HBRUSH)GetStockObject(BLACK_BRUSH); //创建红色的水平和垂直交叉组成的阴影图案的画刷 if(hBrush1){ hOldBrush = (HBRUSH)SelectObject(hDC, hBrush1 ); //将新创建的画刷 1 选进设备表中,以前的画刷保存在 hOldBrush, //以便画完后恢复 Rectangle(hDC,0,0,100,100); //这里进行绘图操作 } if(hBrush2){ SelectObject(hDC, hBrush2 ); //将新创建的画刷 2 选进设备表中 Ellipse (hDC,100,100,200,200); //这里进行绘图操作 } SelectObject(hDC, hOldBrush); //复原画刷 DeleteObject(hBrush1); //删除新创建的画刷,释放空间 DeleteObject(hBrush2); //删除新创建的画刷,释放空间 EndPaint(hWnd,&;PtStr); break; “文字”的例子 文字” case WM_PAINT: LOGFONT LogFont; HFONT hHelv,hTmsRmn; memset(&;LogFont,0,sizeof(LOGFONT)); LogFont.lfHeight=25; LogFont.lfWidth=15; LogFont.lfUnderline=1; LogFont.lfItalic=1; lstrcpy(LogFont.lfFaceName,"Helv"); hHelv=CreateFontIndirect(&;LogFont); memset(&;LogFont,0,sizeof(LOGFONT)); LogFont.lfHeight=25; LogFont.lfWidth=15; LogFont.lfUnderline=1; LogFont.lfItalic=1; lstrcpy(LogFont.lfFaceName,"TmsRmn"); hTmsRmn=CreateFontIndirect(&;LogFont); hdc = BeginPaint(hWnd, &;ps);
SelectObject(hdc,hHelv); TextOut(hdc,20,20,"例子",5); SelectObject(hdc,hTmsRmn); TextOut(hdc,5,100,"Times Roman_Underlined and Itatics",34); RECT rect; SetTextAlign(hdc,TA_CENTER); GetClientRect(hWnd,(LPRECT)&;rect); TextOut(hdc,rect.right/2,rect.bottom/2,sname,20); //---------------------------------------------------------//virtual BOOL TextOut( int x, int y, LPCTSTR lpszString, int nCount ); // x 为文本开始的 X 坐标,y 为文本开始的 Y 坐标 // lpszString 为需要显示的字符串, nCount 为显示字符串的长度 //---------------------------------------------------------TextOut(hdc,rect.right/3,rect.bottom/3,sname,strlen(sname)); EndPaint(hWnd, &;ps); break; “apipaint”例子 ” HDC hDC; HBRUSH hBrush; HPEN hPen ; PAINTSTRUCT PtStr; POINT points [6] = { { 100,212}, {70,227},{70,250},{130,250},{130,227},{100,212} }; switch ( iMessage) { case WM_PAINT: hDC = BeginPaint (hWnd , &; PtStr); hPen = (HPEN) GetStockObject(NULL_PEN); SelectObject (hDC,hPen); hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH); SelectObject (hDC,hBrush); LineTo (hDC, 50, 50); DeleteObject(hPen); hPen = CreatePen(PS_SOLID,2,RGB(255,0,0)); SelectObject(hDC,hPen); LineTo(hDC,150,50); LineTo(hDC,100,137); LineTo(hDC,50,50); Polyline(hDC,points,6); Arc(hDC,63,137,138,212,100,137,100,137); Pie(hDC,213,137,288,212,240,137,260,1370); Rectangle(hDC,213,212,287,250); RoundRect (hDC,213,100,287,137,20,20);
DeleteObject(hPen); “apipaint1”例子 ” case WM_PAINT: POINT m_ptOrigin,point; m_ptOrigin.x=0; m_ptOrigin.y=0; point.x=100; point.y=100; HDC hDC; hDC=GetDC(hWnd);;//获取 DC 句柄 MoveToEx(hDC,m_ptOrigin.
x,m_ptOrigin.y,NULL); LineTo(hDC,point.x,point.y); Rectangle(hDC,100,100,200,200); Arc(hDC,100,100,200,200,100,100,200,200); Rectangle(hDC,200,200,300,300); Pie(hDC,200,200,300,300,200,200,300,300); Ellipse(hDC,200,300,260,360); RECT rt; Get