65,210
社区成员
发帖
与我相关
我的任务
分享
//class CMFCApplication1View : public CView
void CMFCApplication1View::OnDraw(CDC* pDC)
{
CMFCApplication1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
pDC->MoveTo(50, 50);
pDC->LineTo(100, 100);
CRect rc(CPoint(100, 100), CSize(100, 100));
pDC->Ellipse(rc);
}
上面代码正常, 在按照步骤F9设置断点,或者添加打印TRACE(_T("\r\n "));跟踪!#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
HFONT hfont,ohfont;
RECT r;
COLORREF oc;
switch(message) {
case WM_CLOSE://按Alt+F4退出
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
hdc = ps.hdc; // the device context to draw in
GetClientRect(hWnd, &r); // Obtain the window's client rectangle
hfont = CreateFont(240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
ohfont=(HFONT)SelectObject(hdc,hfont);
oc=SetTextColor(hdc,0x00C080FF);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc,r.left+r.right/2-720, r.top+r.bottom/2-120,"最短画图程序",12);
SelectObject(hdc,ohfont);
SetTextColor(hdc,oc);
DeleteObject(hfont);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASS wc = {0};
HBRUSH hbrh;
hbrh=CreateSolidBrush(0x00000000);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = hbrh;
wc.lpszClassName = "minwindowsapp";
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
if( FAILED(RegisterClass(&wc)) ) return 1;
if(FAILED(CreateWindow(wc.lpszClassName,
"Minimal Windows Application",
WS_POPUP|WS_VISIBLE,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInstance,
NULL)))
return 2;
while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
DispatchMessage( &msg );
}
DeleteObject(hbrh);
return 0;
}

void DrawCircle(HDC&hdc, int R,COLORREF color=RGB(255,0,255))
{
HPEN hPen = CreatePen(PS_COSMETIC, 1, color);
SelectObject(hdc, hPen);
HBRUSH hBrush = CreateSolidBrush(color);
SelectObject(hdc, hBrush);
Ellipse(hdc,0,0,2*R,2*R);
DeleteObject(hBrush);
DeleteObject(hPen);
}