GDI 输出文字、画点、线、三角形、矩形、圆、椭圆、多边形

效果图:

代码:

            hdc=BeginPaint(hwnd,&scPaint);
            if (hdc)
            {
                //输出文本
                SetTextColor(hdc,RGB(255,0,0));
                SetBkColor(hdc,RGB(0,255,0));
                SetBkMode(hdc,TRANSPARENT);
                TextOut(hdc,10,100,"Welcome!",8);
                //画点
                SetPixel(hdc,10,10,RGB(255,0,0));
                //画线,三角形
                HPEN gPen=CreatePen(PS_SOLID,1,RGB(0,255,0));
                HPEN oPen=(HPEN)SelectObject(hdc,gPen);
                MoveToEx(hdc,20,20,NULL);
                LineTo(hdc,100,100);
                LineTo(hdc,400,20);
                LineTo(hdc,20,20);
                //画矩形
                gPen=CreatePen(PS_SOLID,1,RGB(0,255,0));
                HBRUSH bBrush=CreateSolidBrush(RGB(0,0,255));
                oPen=(HPEN)SelectObject(hdc,gPen);
                SelectObject(hdc,bBrush);
                Rectangle(hdc,50,150,150,250);
                //FillRect
                RECT rect;
                rect.left=50;
                rect.top=270;
                rect.right=150;
                rect.bottom=370;
                FillRect(hdc,&rect,CreateSolidBrush(RGB(0,0,255)));
                //FrameRect
                rect.left=50;
                rect.top=380;
                rect.right=150;
                rect.bottom=480;
                FrameRect(hdc,&rect,CreateSolidBrush(RGB(255,0,0)));

                //画圆
                Ellipse(hdc,200,150,300,250);
                //画椭圆
                Ellipse(hdc,200,270,340,370);
                //画多边形
                POINT gPoint[5]={{420,10},{540,140},{600,100},{550,200},{420,10}};
                Polygon(hdc,gPoint,5);

                SelectObject(hdc,oPen);
                DeleteObject(gPen);
                DeleteObject(bBrush);

                EndPaint(hwnd,&scPaint);
                ReleaseDC(hwnd,hdc);
            }

 

 


 

 

posted @ 2012-08-14 14:58  冷夜 - 网游编程技术  阅读(17715)  评论(0编辑  收藏  举报