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

📄 shiboqidlg.cpp

📁 简单的演示示波器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// shiboqiDlg.cpp : implementation file
//

#include "stdafx.h"
#include "shiboqi.h"
#include "shiboqiDlg.h"
#include<math.h>
#define PI 3.1415

#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()

/////////////////////////////////////////////////////////////////////////////
// CShiboqiDlg dialog

CShiboqiDlg::CShiboqiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShiboqiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShiboqiDlg)
	m_nChannel = -1;
	m_nA = 10;
	m_nP = 10;
	m_nPos = 0;
	m_fSin = FALSE;
	m_fSquare = FALSE;
	m_fRandom = FALSE;
	m_fModulation = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_n=0;
	m_bStop=FALSE;
	m_bPlay=FALSE;
	m_nChannel=0;
	m_nWaveSum=0;
	m_nOriginPos=0;
	m_nEndPos=0;
	m_fPos=0;
}

void CShiboqiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShiboqiDlg)
	DDX_Control(pDX, IDC_OPEN, m_ctrlOpen);
	DDX_Control(pDX, IDC_SAVEAS, m_ctrlSaveas);
	DDX_Control(pDX, IDC_POSSPIN, m_ctrlSpinPos);
	DDX_Control(pDX, IDC_POS, m_ctrlPos);
	DDX_Control(pDX, IDC_PSPIN, m_ctrlSpinP);
	DDX_Control(pDX, IDC_P, m_ctrlP);
	DDX_Control(pDX, IDC_ASPIN, m_ctrlSpinA);
	DDX_Control(pDX, IDC_A, m_ctrlEditA);
	DDX_Control(pDX, IDOK, m_ctrlExit);
	DDX_Control(pDX, IDC_PLAY, m_ctrlPlay);
	DDX_Control(pDX, IDC_STOP, m_ctrlStop);
	DDX_Radio(pDX, IDC_CHANNEL, m_nChannel);
	DDX_Text(pDX, IDC_A, m_nA);
	DDV_MinMaxUInt(pDX, m_nA, 1, 100);
	DDX_Text(pDX, IDC_P, m_nP);
	DDV_MinMaxUInt(pDX, m_nP, 1, 100);
	DDX_Text(pDX, IDC_POS, m_nPos);
	DDV_MinMaxInt(pDX, m_nPos, -160, 160);
	DDX_Check(pDX, IDC_SIN, m_fSin);
	DDX_Check(pDX, IDC_SQUARE, m_fSquare);
	DDX_Check(pDX, IDC_RANDOM, m_fRandom);
	DDX_Check(pDX, IDC_MODULATION, m_fModulation);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShiboqiDlg, CDialog)
	//{{AFX_MSG_MAP(CShiboqiDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_PLAY, OnPlay)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_WM_SETCURSOR()
	ON_BN_CLICKED(IDC_SAVEAS, OnSaveas)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShiboqiDlg message handlers

BOOL CShiboqiDlg::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
//	CDC* pDC=GetDC();
//	pDC->TextOut(450,450,"演示示波器",8);
//	m_brush.CreateSolidBrush(RGB(74,125,181));
	m_brush.CreateSolidBrush(RGB(77,158,179));
	m_editBrush.CreateSolidBrush(RGB(0,128,128));
//	CenterWindow(GetDesktopWindow());
	m_hBtnCursor=AfxGetApp()->LoadCursor(IDC_BTNCURSOR);

//	m_ctrlExit.LoadBitmaps(IDB_EXIT);
//	m_ctrlExit.AutoLoad(IDOK,GetParent());
//	CBitmap bmp;
	m_exitBitmap.LoadBitmap(IDB_EXIT);
	m_ctrlExit.SetBitmap((HBITMAP)m_exitBitmap.m_hObject);
//  buttonBMP.LoadBitmap(IDB_BITMAP_PWRBN);
//	this->m_BmpButton.SetBitmap((HBITMAP)buttonBMP.m_hObject);

	//编辑框设置
	m_ctrlSpinA.SetBuddy(&m_ctrlEditA);
	m_ctrlSpinA.SetRange(1,100);
//	m_nA=30;
	m_ctrlSpinP.SetBuddy(&m_ctrlP);
	m_ctrlSpinP.SetRange(1,100);

	m_ctrlSpinPos.SetBuddy(&m_ctrlPos);
	m_ctrlSpinPos.SetRange(-160,160);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CShiboqiDlg::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 CShiboqiDlg::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
	{
		CDialog::OnPaint();
	}
	CDC *pDC=GetDC();
//文字输出
	CFont font;
	font.CreatePointFont(300,"华文彩云");
	pDC->SelectObject(&font);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextColor(RGB(128,128,0));
	pDC->TextOut(550,470,"演示示波器",10);
	pDC->SetTextColor(RGB(255,128,78));
	pDC->TextOut(547,470,"演示示波器",10);
	font.DeleteObject();
	CDC dc;
	CBitmap bmp;
	CBrush brush;
	brush.CreateSolidBrush(RGB(0,0,0));
	dc.CreateCompatibleDC(pDC);
	CWnd* pWnd=GetDlgItem(IDC_GRAPHIC);
	pWnd->GetWindowRect(m_rtGraphic);
	ScreenToClient(m_rtGraphic);
	bmp.CreateCompatibleBitmap(pDC,m_rtGraphic.Width(),m_rtGraphic.Height());
	dc.SelectObject(&bmp);
	dc.FillRect(m_rtGraphic,&brush);
//	dc.SelectObject(&brush);
	//绘制背景网格
	CPen pen(PS_SOLID,1,RGB(0,255,0));
	CPen* pOldPen=dc.SelectObject(&pen);
	m_ptOrigin.x=m_rtGraphic.left+54;
	m_ptOrigin.y=m_ptEnd.y=(m_rtGraphic.top+m_rtGraphic.bottom)/2-160;
	m_ptEnd.x=m_rtGraphic.right-53;
	int i=0;
	while(i<=320)
	{
		dc.MoveTo(m_ptOrigin.x,m_ptOrigin.y+i);
		dc.LineTo(m_ptEnd.x,m_ptEnd.y+i);
		i+=40;
	}
	i=0;
	while(i<=480)
	{
		dc.MoveTo(m_ptOrigin.x+i,m_ptOrigin.y);
		dc.LineTo(m_ptOrigin.x+i,m_ptOrigin.y+320);
		i+=40;
	}
	pDC->BitBlt(m_rtGraphic.left,m_rtGraphic.top,m_rtGraphic.Width(),m_rtGraphic.Height(),
					&dc,0,0,SRCCOPY);
/*	dc.MoveTo(m_ptOrigin);
	dc.LineTo(m_ptEnd);
	dc.LineTo(m_ptEnd.x,m_ptEnd.y-160);
	dc.LineTo(m_ptOrigin.x,m_ptOrigin.y-160);
	dc.LineTo(m_ptOrigin.x,m_ptOrigin.y+160);
	dc.LineTo(m_ptEnd.x,m_ptEnd.y+160);
//	dc.LineTo(m_ptEnd);*/
	dc.SelectObject(pOldPen);
	bmp.DeleteObject();
	this->ReleaseDC(pDC);
	dc.DeleteDC();
//	OnDrawWave();
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CShiboqiDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

HBRUSH CShiboqiDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	pDC->SetBkMode(TRANSPARENT);
	if(nCtlColor==CTLCOLOR_EDIT)
	{
		pDC->SetTextColor(RGB(0,255,12));
		return m_editBrush;
	}
	pDC->SetTextColor(RGB(255,128,0));
	if(m_rtGraphic)

⌨️ 快捷键说明

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