这样可以吗?
如果是这样的话,建的是MFC单文档工程,随便在mainframe里面加个按钮事件,我这里是在主菜单中加了个“操作”,把下面代码丢进去即可
CClientDC dc(this);
CPen newPen(PS_SOLID,1,RGB(0,0,0));
CPen *oldPen=dc.SelectObject(&newPen);
dc.MoveTo(CPoint(200,600));
dc.LineTo(CPoint(600,100));
dc.LineTo(CPoint(800,400));
dc.LineTo(CPoint(200,600));
dc.Ellipse(0,400,400,0);
dc.SelectObject(oldPen);
#include "conio.h"
#include "Windows.h"
#define XPixel 30//该值你可以自己设定,以改变图形的显示大小和形状
#define YPixel 30//该值你可以自己设定,以改变图形的显示大小和形状
int main (void)
{
HWND hWnd;
HDC hDC;
HPEN hPen;
RECT rect;
hWnd = GetForegroundWindow ();
hDC = GetDC (hWnd);
hPen = CreatePen (PS_SOLID, 1, RGB (0, 0, 0));
SelectObject (hDC, hPen);
rect.left=0;
rect.top=0;
rect.right=8*XPixel;
rect.bottom=8*YPixel;
Rectangle(hDC,rect.left,rect.top,rect.right,rect.bottom);//画一个8X8 的矩形
//画三角形
MoveToEx (hDC,2*XPixel, 6*YPixel, NULL);//设置起点开始画三角形
LineTo (hDC, 6*XPixel, YPixel);
LineTo (hDC, 8*XPixel, 4*YPixel);
LineTo (hDC, 2*XPixel, 6*YPixel);
//画圆形
Ellipse(hDC,0,0,4*XPixel,4*YPixel);//若XPixel和YPixel值不相等,则会变成椭圆形
//输出字符
SetTextColor(hDC, RGB (0, 0, 0));
TextOut(hDC,5*XPixel,3*YPixel,"GOLLUM",sizeof("GOLLUM"));
getch ();
DeleteObject (hPen);
ReleaseDC (hWnd, hDC);
return 0;
}
纯手工,VS2010调试无误,可追问。