⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1dlg.cpp

📁 绘制柱状图的资源
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "1.h"
#include "1Dlg.h"
//#include "windows.h"
#include <iostream>
using namespace std;


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy1Dlg dialog

CMy1Dlg::CMy1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy1Dlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy1Dlg)
	DDX_Control(pDX, IDC_COMBO2, m_banji11);
	DDX_Control(pDX, IDC_COMBO1, m_kemu);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy1Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy1Dlg message handlers

BOOL CMy1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	OnButton1();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy1Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDC* pDC = GetDC();  //利用MFC的CDC类实现画线
	    CPoint pt1,pt2,pt3,pt4,pt6,pt8,pt10,pt12;  //定义起点、终点
     	pt1.x = 30;
		pt1.y = 0;
		pt2.x = 30;
		pt2.y = 200;
		pt3.x = 30;
		pt3.y = 200;
		pt4.x = 390;
		pt4.y = 200;
		pt6.x = 35;
		pt6.y = 15;
		pt8.x = 25;
		pt8.y = 15;
		pt10.x = 370;
		pt10.y = 195;
		pt12.x = 370;             
		pt12.y = 205;
		pDC->MoveTo(pt1);  //线的起点 //画竖轴
		pDC->LineTo(pt2);  //线的终点
		pDC->DrawText("20",-1,CRect(30,0,10,10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在纵轴写数字
		pDC->DrawText("15",-1,CRect(30,5,10,100),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在纵轴写数字
		pDC->DrawText("10",-1,CRect(30,5,10,200),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在纵轴写数字
		pDC->DrawText("5",-1,CRect(30,5,10,300),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在纵轴写数字

		pDC->DrawText("60-70",-1,CRect(60,200+5,100,200+15),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在横轴写数字
		pDC->DrawText("71-80",-1,CRect(120,200+5,160,200+15),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在横轴写数字
		pDC->DrawText("81-90",-1,CRect(180,200+5,220,200+15),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在横轴写数字
		pDC->DrawText("91-100",-1,CRect(240,200+5,285,200+15),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在横轴写数字
		pDC->DrawText("0-59",-1,CRect(308,200+5,338,200+15),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在横轴写数字


		pDC->DrawText("人数",-1,CRect(30,20,80,0),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//在纵轴写文字
		pDC->DrawText("分数",-1,CRect(350,210,380,230),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("成",-1,CRect(400,40,450,60),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("绩",-1,CRect(400,60,450,80),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("柱",-1,CRect(400,80,450,100),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("状",-1,CRect(400,100,450,120),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("图",-1,CRect(400,120,450,140),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		pDC->DrawText("072-13组",-1,CRect(450,215,510,235),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
		
		pDC->DrawText("参加",-1,CRect(100,5,130,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		pDC->DrawText("人数为:",-1,CRect(190,5,250,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		char str6[20]="d";
		int f=n1+n2+n3+n4+n5;
		sprintf(str6,"%d",f);
		pDC->DrawText(str6,-1,CRect(250,5,280,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		
		CString str; 
		if(m_kemu.GetCurSel()>=0)
			{
				m_kemu.GetLBText(m_kemu.GetCurSel(),str);
			}
		if(str=="离散")
		{
			pDC->DrawText("离",-1,CRect(395,60,410,80),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("散",-1,CRect(395,100,410,120),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("离散考试",-1,CRect(130,5,190,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}

					
		if(str=="物理")
		{
			pDC->DrawText("物",-1,CRect(395,60,410,80),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("理",-1,CRect(395,100,410,120),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("物理考试",-1,CRect(130,5,190,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}

					
		if(str=="概率")
		{
			pDC->DrawText("概",-1,CRect(395,60,410,80),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("率",-1,CRect(395,100,410,120),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("概率考试",-1,CRect(130,5,190,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}

		if(str=="英语")
		{
			pDC->DrawText("英",-1,CRect(395,60,410,80),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("语",-1,CRect(395,100,410,120),DT_CENTER|DT_VCENTER|DT_SINGLELINE);//写文字
			pDC->DrawText("英语考试",-1,CRect(130,5,190,20),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		}


	//	m_dcMem.DrawText(2,-1,1,DT_CENTER|DT_VCENTER|DT_SINGLELINE);

		HBRUSH hb=::CreateSolidBrush(RGB(100,100,0));//选择颜色
		pDC->SelectObject(hb);//填充颜色
		pDC->Rectangle(60,200-n1*10,100,200);//画柱子
	//	pDC->MoveTo(60,200-n1*10);
	//	pDC->LineTo(30,200-n1*10);
		char str1[20]="d";
		int a=n1;
		sprintf(str1,"%d",a);
		pDC->DrawText(str1,-1,CRect(60,190-n1*10,100,200-n1*10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);



        
		hb=::CreateSolidBrush(RGB(0,255,255));//选择颜色
		pDC->SelectObject(hb);//填充颜色
		pDC->Rectangle(120,200-n2*10,160,200);//画柱子
	/*	CPen *oldPen ;
        CPen pen(PS_DASH, 1, RGB(255,255,0));
        oldPen = pDC->SelectObject(&pen) ; 
		pDC->MoveTo(60,200-n1*10);
		pDC->LineTo(30,200-n1*10);
        pDC->SelectObject (oldPen) ;*/
		char str2[20]="d";
		int b=n2;
		sprintf(str2,"%d",b);
		pDC->DrawText(str2,-1,CRect(120,190-n2*10,160,200-n2*10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);


		
		hb=::CreateSolidBrush(RGB(0,255,0));//选择颜色
		pDC->SelectObject(hb);//填充颜色
        pDC->Rectangle(180,200-n3*10,220,200);//画柱子
		char str3[20]="d";
		int c=n3;
		sprintf(str3,"%d",c);
		pDC->DrawText(str3,-1,CRect(180,190-n3*10,220,200-n3*10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);


		hb=::CreateSolidBrush(RGB(300,100,50));//选择颜色
		pDC->SelectObject(hb);//填充颜色
		pDC->Rectangle(240,200-n4*10,280,200);//画柱子
		char str4[20]="d";
		int d=n4;
		sprintf(str4,"%d",d);
		pDC->DrawText(str4,-1,CRect(240,190-n4*10,280,200-n4*10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);


		hb=::CreateSolidBrush(RGB(200,100,100));//选择颜色
		pDC->SelectObject(hb);//填充颜色
		pDC->Rectangle(305,200-n5*10,340,200);//画柱子
		char str5[20]="d";
		int e=n5;
		sprintf(str5,"%d",e);
		pDC->DrawText(str5,-1,CRect(305,190-n5*10,340,200-n5*10),DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		

		CPen *oldPen ;//定义画笔时定义成虚线的画笔
        CPen pen(PS_DASH, 0.5, RGB(255,0,0));//第一个参数是线的格式;第二个是线宽;第三个是颜色
        oldPen = pDC->SelectObject(&pen) ; 
		pDC->MoveTo(60,200-n1*10);
		pDC->LineTo(30,200-n1*10);
		pDC->MoveTo(120,200-n2*10);
		pDC->LineTo(30,200-n2*10);
		pDC->MoveTo(180,200-n3*10);
		pDC->LineTo(30,200-n3*10);
		pDC->MoveTo(240,200-n4*10);
		pDC->LineTo(30,200-n4*10);
		pDC->MoveTo(305,200-n5*10);
		pDC->LineTo(30,200-n5*10);
        pDC->SelectObject (oldPen) ;
		
		pDC->MoveTo(pt3);  //线的起点  //画横轴
		pDC->LineTo(pt4);  //线的终点

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -