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

📄 qsentfontdlg.cpp

📁 Led 发送晨曦
💻 CPP
字号:
// QSentFontDlg.cpp : implementation file
//

#include "stdafx.h"
#include "QSentFont.h"
#include "QSentFontDlg.h"
#include "membm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CString showText=("欢迎便用力麒科技LED屏");
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()

/////////////////////////////////////////////////////////////////////////////
// CQSentFontDlg dialog

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

void CQSentFontDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQSentFontDlg)
	DDX_Control(pDX, IDC_STATIC_pict, m_DrawArea);
	DDX_Control(pDX, IDC_SetBt, m_SetBt);
	DDX_Control(pDX, IDC_SelectCOM, m_SelectCom);
	DDX_Control(pDX, IDC_DISPLAYTEXT, m_ctIDisplayText);
	DDX_Control(pDX, IDC_LFONTS, m_ctlFontList);
	DDX_LBString(pDX, IDC_LFONTS, m_strFontName);
	DDX_Text(pDX, IDC_ESAMPTEXT, m_strSampText);
	DDX_Text(pDX, IDC_DISPLAYTEXT, m_strDisplayText);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CQSentFontDlg, CDialog)
	//{{AFX_MSG_MAP(CQSentFontDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_DFLTMSG, OnDfltmsg)
	ON_BN_CLICKED(IDC_CLRMSG, OnClrmsg)
	ON_LBN_SELCHANGE(IDC_LFONTS, OnSelchangeLfonts)
	ON_EN_CHANGE(IDC_ESAMPTEXT, OnChangeEsamptext)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQSentFontDlg message handlers

BOOL CQSentFontDlg::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
		// Fill the font list box
	FillFontList();
    
	// Initalize the text to be entered
	m_strSampText = "欢迎光临";
    // Copy the Text to the font sample area
	m_strDisplayText = m_strSampText;
	m_SelectCom.InsertString(0,"COM1");
	m_SelectCom.InsertString(1,"COM2");
	m_SelectCom.InsertString(2,"COM3");
	m_SelectCom.InsertString(3,"COM4");
	m_SelectCom.InsertString(4,"COM5");
	m_SelectCom.InsertString(5,"COM6");
	m_SelectCom.SelectString(-1,"COM1");
	m_SetBt.SelectString(-1,"9600");
	// Update the dialog
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CQSentFontDlg::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 CQSentFontDlg::OnPaint() 
{

		CPaintDC dc(this); // device context for painting

		//CMemBm
  
	CRect rect ;//占位符矩形

   //char *showText=("欢欣鼓舞go to the windows!");
	

	m_DrawArea.GetWindowRect( &rect );
	ScreenToClient( &rect );

	// 2 - Draw inside placeholder rectangle
	// Draw current shape
	CBrush brShape( RGB( 0, 0, 0 ) );
	CBrush* pOldBrush = dc.SelectObject( &brShape );

	dc.Rectangle( rect );

	CPen pen( PS_SOLID, 2, RGB( 255, 255, 255) );
	CPen* pOldPen = dc.SelectObject( &pen );

	SetBkColor(dc,(0,0,0));
	SetTextColor(dc,(255,255,255));
	TextOut(dc,25,310,showText,strlen(showText));

	dc.SelectObject( pOldPen );
	dc.SelectObject( pOldBrush );
//********************************************

/*
    CMemBm bmSnap( dc, NULL, 0, 0, 715,120 );
	HPEN hPen = CreatePen( PS_SOLID, 1, RGB(255,0,0) );
	HANDLE hOldPen = SelectObject(bmSnap, hPen);
	SetBkColor(bmSnap,(0,0,0));
	SetTextColor(bmSnap,(255,255,255));
	TextOut(bmSnap,0,0,showText,strlen(showText));

	SelectObject(bmSnap, hOldPen);
	DeleteObject(hPen);

bmSnap.Fill( dc,25, 310,715,120, true );
*/	
}

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

void CQSentFontDlg::OnDfltmsg() 
{
		
	m_strSampText = "欢迎光临";
    m_strDisplayText = m_strSampText;
showText="欢迎光临";
RedrawArea();
    UpdateData(FALSE);	
}

void CQSentFontDlg::OnClrmsg() 
{
	m_strSampText = "";
    m_strDisplayText = m_strSampText;
    showText="";
    RedrawArea();
	UpdateData(FALSE);	
}

void CQSentFontDlg::OnSelchangeLfonts() 
{	// MY CODE STARTS HERE

	// Update the variables with the dialog controls
	UpdateData(TRUE);
// Set the font for the sample
	SetMyFont();
	
}
void CQSentFontDlg::SetMyFont()
{
	CRect rRect;
	int iHeight;

	// Has a font been selected?
	if (m_strFontName != "")
	{
		// Get the dimensions of the font sample display area
		m_ctIDisplayText.GetWindowRect(&rRect);
		// Calculate the area height
		iHeight = rRect.top - rRect.bottom;
		// Make sure the height is positive
		if (iHeight < 0)
			iHeight = 0 - iHeight;
		// Release the current font
		m_fSampFont.Detach();
		// create the font to be used
		m_fSampFont.CreateFont((iHeight - 1),0,0,0, FW_NORMAL,
			0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,
			CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | 
			FF_DONTCARE, m_strFontName);

		// Set the font for the sample display area
		m_ctIDisplayText.SetFont(&m_fSampFont);
	}
}
int CALLBACK EnumFontFamProc(LPENUMLOGFONT lpelf,
							 LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam)
{
	// Create a pointer to the dialog window
	CQSentFontDlg* pWnd = (CQSentFontDlg*) lparam;

	// add the font name to the list box
	pWnd ->m_ctlFontList.AddString(lpelf ->elfLogFont.lfFaceName);
	// Return 1 to continue font enumeration
	return 1;
}
void CQSentFontDlg::FillFontList()
{
	int iCount;
	int iCurCount;
	CString strCurFont;
	CString strPrevFont = "";	
	LOGFONT lf;

	// Initialize the LOGFONT structure
	lf.lfCharSet = DEFAULT_CHARSET;
	strcpy(lf.lfFaceName,"");
	// clear the list box
	m_ctlFontList.ResetContent();
	// create a device context variable
	CClientDC dc (this);
	// Enumerate the font families
	::EnumFontFamiliesEx((HDC) dc,&lf,
		(FONTENUMPROC) EnumFontFamProc,(LPARAM) this,0);
	
	
	// Get the number of fonts in the list box
	iCount = m_ctlFontList.GetCount();
	// Loop from the last entry in the list box to the first,
	// searching for and deleting the duplicate entries
	for (iCurCount = iCount; iCurCount > 0; iCurCount--)
	{
		// Get the current font name
		m_ctlFontList.GetText((iCurCount - 1), strCurFont);
		// is it the same as the previous font name?
		if (strCurFont == strPrevFont)
		{
			// if yes,then delete it
			m_ctlFontList.DeleteString((iCurCount - 1));
		}
		// Set the previous font name to the current font name
		strPrevFont = strCurFont;
	}
}

void CQSentFontDlg::OnChangeEsamptext() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
		// Update the variables with the dialog controls
	UpdateData(TRUE);

	// copy the current text to the font sample
	m_strDisplayText = m_strSampText;
	showText=m_strSampText;
    RedrawArea();
	// Update the dialog with the variables
	UpdateData(FALSE);

	// TODO: Add your control notification handler code here
	
}
void CQSentFontDlg::RedrawArea()
{
	CRect rect;
	m_DrawArea.GetWindowRect(&rect);
	ScreenToClient(&rect);

	InvalidateRect(rect);
	UpdateWindow();

}

⌨️ 快捷键说明

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