美文网首页
MFC画尺子

MFC画尺子

作者: Fa1se003 | 来源:发表于2017-06-10 20:03 被阅读34次
image.png

hellomfc.h

#ifndef __HELLO_H__
#define __HELLO_H__

class CMyApp:public CWinApp
{
public:
    virtual BOOL InitInstance();
};

class CMainWindow:public CFrameWnd
{
    DECLARE_MESSAGE_MAP()
    afx_msg void OnPaint();
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
public:
    CMainWindow();
};

#endif

hellomfc.cpp

#include <afxwin.h>
#include "HelloMFC.h"

CMyApp theApp;

BOOL CMyApp::InitInstance()
{
    m_pMainWnd = new CMainWindow;
    m_pMainWnd->ShowWindow(m_nCmdShow);
    m_pMainWnd->UpdateWindow();
    return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
    ON_WM_LBUTTONDOWN()
    ON_WM_PAINT()
END_MESSAGE_MAP()

CMainWindow::CMainWindow()
{
    Create(NULL,"HelloMFC");    
}


void CMainWindow::OnPaint()
{
    CPaintDC dc(this);
    TCHAR Num[20];

    CBrush brush(RGB(255,180,0)); 
    dc.SelectObject(&brush); 

    dc.SetMapMode(MM_LOMETRIC);
    
    dc.Rectangle(200,-100,3200,-400);
    

    CBrush brush2(RGB(255,255,255)); 
    dc.SelectObject(&brush2); 

    int dwStep=10;
    for (int i=0,j=0;i<300;i++)
    {
        if (i%5==0)
        {
            dc.MoveTo(200+i*dwStep,-350);
            dc.LineTo(200+i*dwStep,-400); 
        }
        if (i%10==0&&i!=0)
        {
            j++;
            sprintf(Num,"%d",j);
        //  dc.SetBkColor(RGB(255,180,0));
            dc.DrawText(Num,CRect(190+i*dwStep,-280,3300,-400),DT_SINGLELINE);
            dc.MoveTo(200+i*dwStep,-330);
            dc.LineTo(200+i*dwStep,-400); 
        }
        dc.MoveTo(200+i*dwStep,-370);
        dc.LineTo(200+i*dwStep,-400); 
    }
} 
void CMainWindow::OnLButtonDown(UINT nFlags, CPoint point)
{
    
}

相关文章

网友评论

      本文标题:MFC画尺子

      本文链接:https://www.haomeiwen.com/subject/ppjcqxtx.html