【文件属性】:
文件名称:文字与图片合成图片代码
文件大小:40KB
文件格式:RAR
更新时间:2012-06-16 08:09:24
图片合成
// AddTextDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test.h"
#include "AddTextDlg.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
ON_BN_CLICKED(IDOK, OnBnClickedOk)
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;
}
void CAddTextDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
OnOK();
}
【文件预览】:
bmptext
----RectTrackerEx.cpp(3KB)
----StdAfx.cpp(206B)
----Test.vcproj(7KB)
----RectTrackerEx.h(2KB)
----Test.dsw(533B)
----TestDlg.h(1KB)
----Test.opt(48KB)
----Test.cpp(2KB)
----Test.aps(22KB)
----BmpShow.h(3KB)
----TestDlg.cpp(4KB)
----Test.ncb(43KB)
----Test.sln(897B)
----AddTextDlg.cpp(4KB)
----StdAfx.h(1KB)
----Resource.h(911B)
----Test.suo(9KB)
----res()
--------Test.ico(1KB)
--------Test.rc2(396B)
----Test.clw(2KB)
----AddTextDlg.h(2KB)
----Test.rc(6KB)
----BmpShow.cpp(15KB)
----Test.dsp(4KB)
----Test.h(1KB)