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

📄 addtextdlg.cpp

📁 thinking in java 3rd 英文版的
💻 CPP
字号:
// AddTextDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Test.h"
#include "AddTextDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddTextDlg dialog

CAddTextDlg::CAddTextDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddTextDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddTextDlg)
	m_strText = _T("");
	//}}AFX_DATA_INIT
	m_strBmpFilePath = "";
	ZeroMemory(&m_bmpIfHi, sizeof(BITMAPINFOHEADER));
	m_dwSize = 0;
	m_lpDIBits = NULL;
}

void CAddTextDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddTextDlg)
	DDX_Control(pDX, IDC_EDIT_TEXT, m_edtText);
	DDX_Control(pDX, IDC_STATIC_SHOW, m_BmpShow);
	DDX_Text(pDX, IDC_EDIT_TEXT, m_strText);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAddTextDlg, CDialog)
	//{{AFX_MSG_MAP(CAddTextDlg)
	ON_EN_CHANGE(IDC_EDIT_TEXT, OnChangeEditText)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddTextDlg message handlers

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


	// TODO: Add extra initialization here
	m_edtText.EnableWindow(FALSE);
	int nCharLimit = 0;	
	if (m_strBmpFilePath.GetLength() > 0)
	{//传文件路径
		if (m_BmpShow.SetReadBmpPath(m_strBmpFilePath, &nCharLimit))
		{
			m_edtText.EnableWindow();
			m_edtText.SetLimitText(nCharLimit);
		}
		else 
		{
			PostMessage(WM_CLOSE, 0, 0);
		}
	}
	else
	{//传位图信息和数据
		if (NULL == m_lpDIBits)
		{
			PostMessage(WM_CLOSE, 0, 0);
		}
		if (m_BmpShow.SetBmpInfo(&m_bmpIfHi, m_lpDIBits, &nCharLimit))
		{
			m_edtText.EnableWindow();
			m_edtText.SetLimitText(nCharLimit);
		}
		else
		{
			PostMessage(WM_CLOSE, 0, 0);
		}
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CAddTextDlg::OnChangeEditText() 
{
	// 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.
	UpdateData();
	m_BmpShow.SetBmpText(m_strText);
	// TODO: Add your control notification handler code here
	
}

BOOL CAddTextDlg::SetBmpFilePath(LPCTSTR pszPath)
{
	if (0 == _mbstrlen(pszPath))
	{
		return FALSE;
	}
	m_strBmpFilePath = pszPath;
	return TRUE;
}



void CAddTextDlg::OnOK() 
{
	// TODO: Add extra validation here
	if (m_strBmpFilePath.GetLength() > 0)
	{
		m_BmpShow.SetSaveBmpPath(m_strBmpFilePath);			
	}
	if (m_lpDIBits != NULL)
	{
		delete[] m_lpDIBits;
		m_lpDIBits = NULL;
	}
	m_lpDIBits = new BYTE[m_dwSize];		
	m_BmpShow.SaveModify(&m_bmpIfHi, m_lpDIBits);		
	CDialog::OnOK();
}

void CAddTextDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CAddTextDlg::SetBmpInfo(const LPBITMAPINFOHEADER lpbmih,  const LPVOID lpvBits)
{
	ASSERT((lpbmih != NULL) && (lpvBits != NULL));
	m_strBmpFilePath = "";
	if (m_lpDIBits != NULL)
	{
		delete[] m_lpDIBits;
		m_lpDIBits = NULL;
	}
	if ((lpbmih->biBitCount < 16) || (lpbmih->biBitCount > 32))
	{
		return FALSE;
	}

	memcpy(&m_bmpIfHi, lpbmih, sizeof(BITMAPINFOHEADER));
	m_BmpShow.ComputeImageSize(&m_bmpIfHi, &m_dwSize);
/*	if (m_dwSize != lpbmih->biSizeImage)
	{
		return FALSE;
	}*/
	
	m_lpDIBits = new BYTE[m_dwSize];
	memcpy(m_lpDIBits, lpvBits, lpbmih->biSizeImage);
//	memcpy(m_lpDIBits, lpvBits, m_dwSize);
	return TRUE;
}

CAddTextDlg::~CAddTextDlg()
{
	if (m_lpDIBits != NULL)
	{
		delete[] m_lpDIBits;
		m_lpDIBits = NULL;
	}
}

BOOL CAddTextDlg::GetBmpInfo(LPBITMAPINFOHEADER lpbmih, LPVOID lpvBits, LPDWORD pdwSize)
{
	memcpy(lpbmih, &m_bmpIfHi, sizeof(BITMAPINFOHEADER));
	*pdwSize = m_dwSize;
	memcpy(lpvBits, m_lpDIBits, m_dwSize);
	return TRUE;

}


⌨️ 快捷键说明

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