<commit_before>// MessageBoxEx.cpp : ʵļ
//

#include "stdafx.h"
#include "afxwin.h"
#include "DacrsUI.h"
#include "MessageBoxEx.h"
#include "afxdialogex.h"


// CMessageBoxEx Ի

IMPLEMENT_DYNAMIC(CMessageBoxEx, CDialogBase)

CMessageBoxEx::CMessageBoxEx(CString strText,CString strTip ,UINT uType ,CWnd* pParent /*=NULL*/)
	: CDialogBase(CMessageBoxEx::IDD, pParent)
{
	m_Text = strText;
	m_Tip  = strTip ;
	m_uType = uType ;
	m_pBmp = NULL;
	SetBkBmpNid( IDB_BITMAP_MESSAGE_H ) ;
}

CMessageBoxEx::~CMessageBoxEx()
{
	if( NULL != m_pBmp ) {
		DeleteObject(m_pBmp) ;
		m_pBmp = NULL ;
	}
}

void CMessageBoxEx::DoDataExchange(CDataExchange* pDX)
{
	CDialogBase::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_QUIT, m_quit);
	DDX_Control(pDX, IDC_OK, m_OK);
	DDX_Control(pDX, IDC_CANCEL, m_cancel);
	DDX_Control(pDX, IDC_TEXT, m_strText);
	DDX_Control(pDX, IDC_TIP, m_strTip);
}


BEGIN_MESSAGE_MAP(CMessageBoxEx, CDialogBase)
	ON_BN_CLICKED(IDC_OK, &CMessageBoxEx::OnBnClickedOk)
	ON_BN_CLICKED(IDC_QUIT, &CMessageBoxEx::OnBnClickedQuit)
	ON_BN_CLICKED(IDC_CANCEL, &CMessageBoxEx::OnBnClickedCancel)
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR()
	ON_WM_NCHITTEST()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()


// CMessageBoxEx Ϣ

void CMessageBoxEx::SetBkBmpNid( UINT nBitmapIn ) 
{
	if( NULL != m_pBmp ) {
		::DeleteObject( m_pBmp ) ;
		m_pBmp = NULL ;
	}
	m_pBmp	= NULL ;
	HINSTANCE	hInstResource = NULL;	
	hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nBitmapIn), RT_BITMAP);
	if( NULL != hInstResource ) {
		m_pBmp = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapIn), IMAGE_BITMAP, 0, 0, 0);
	}
}

void CMessageBoxEx::SetBitmap(UINT uBmpResource)
{
	HBITMAP hBitmap; //meaasgeboxеͼƬ 
	CStatic *pStatic = (CStatic *)GetDlgItem(IDC_IMAGE); 
	//ͼƬID 
	hBitmap = (HBITMAP)LoadImage(    
	AfxGetInstanceHandle(), 
	MAKEINTRESOURCE(uBmpResource), 
	IMAGE_BITMAP, 
	0, 
	0, 
	LR_LOADMAP3DCOLORS); 
	pStatic->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE); 
	pStatic->SetBitmap(hBitmap); 
}

BOOL CMessageBoxEx::OnInitDialog()
{
	CDialogBase::OnInitDialog();
	int nIconLeftMargin = 25;    //ͼʾ߾
	int nIconTopMargin = 45;     //ͼʾϱ߾
	int nBtBottomMargin = 10;    //ťʾ±߾
	int nBtRightMargin = 15;     //ťʾұ߾

	int nLeftMargin = 75;    //static߾
	int nRightMargin = 55;   //staticұ߾
    int nBottomMargin = 65;  //static±߾
	int nStaticHeigh = 0;    //static߶
	int nStaticWidth = 0;    //static
	int nDialogWidth = 0;
	int nDialogHight = 0;
	CClientDC dc(this);   
	//ݳȼʾĴС
	int nRow = 1;
	CSize nFontSize = dc.GetTextExtent(m_Text);
	if(nFontSize.cx > MAX_WIDTH - nLeftMargin -nRightMargin) {
		nDialogWidth = MAX_WIDTH;
		nStaticWidth = MAX_WIDTH - nLeftMargin -nRightMargin;
		nRow =  nFontSize.cx / nStaticWidth;
	}
	else {
		nDialogWidth = nFontSize.cx + nLeftMargin + nRightMargin;	
		nStaticWidth = nFontSize.cx;
		
	}
	nRow += m_Text.Replace("\n", "\n");
	nDialogHight = nRow * nFontSize.cy + nBottomMargin + nIconTopMargin;
	nStaticHeigh = nRow * nFontSize.cy;

	// TODO:  ڴӶĳʼ
	UpdateData(FALSE);
	
	CRect rect;
	theApp.m_pMainWnd->GetWindowRect(&rect);
	theApp.m_pMainWnd->ClientToScreen(rect);
	MoveWindow((rect.left + rect.right)/2 - nDialogWidth/2,(rect.top + rect.bottom)/2 - nDialogHight/2 ,nDialogWidth, nDialogHight, FALSE);
	CenterWindow();
	
	m_fontGrid.CreatePointFont(100,_T(""));
<commit_msg>修改提示框字符高度计算<commit_after>// MessageBoxEx.cpp : ʵļ
//

#include "stdafx.h"
#include "afxwin.h"
#include "DacrsUI.h"
#include "MessageBoxEx.h"
#include "afxdialogex.h"


// CMessageBoxEx Ի

IMPLEMENT_DYNAMIC(CMessageBoxEx, CDialogBase)

CMessageBoxEx::CMessageBoxEx(CString strText,CString strTip ,UINT uType ,CWnd* pParent /*=NULL*/)
	: CDialogBase(CMessageBoxEx::IDD, pParent)
{
	m_Text = strText;
	m_Tip  = strTip ;
	m_uType = uType ;
	m_pBmp = NULL;
	SetBkBmpNid( IDB_BITMAP_MESSAGE_H ) ;
}

CMessageBoxEx::~CMessageBoxEx()
{
	if( NULL != m_pBmp ) {
		DeleteObject(m_pBmp) ;
		m_pBmp = NULL ;
	}
}

void CMessageBoxEx::DoDataExchange(CDataExchange* pDX)
{
	CDialogBase::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_QUIT, m_quit);
	DDX_Control(pDX, IDC_OK, m_OK);
	DDX_Control(pDX, IDC_CANCEL, m_cancel);
	DDX_Control(pDX, IDC_TEXT, m_strText);
	DDX_Control(pDX, IDC_TIP, m_strTip);
}


BEGIN_MESSAGE_MAP(CMessageBoxEx, CDialogBase)
	ON_BN_CLICKED(IDC_OK, &CMessageBoxEx::OnBnClickedOk)
	ON_BN_CLICKED(IDC_QUIT, &CMessageBoxEx::OnBnClickedQuit)
	ON_BN_CLICKED(IDC_CANCEL, &CMessageBoxEx::OnBnClickedCancel)
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR()
	ON_WM_NCHITTEST()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()


// CMessageBoxEx Ϣ

void CMessageBoxEx::SetBkBmpNid( UINT nBitmapIn ) 
{
	if( NULL != m_pBmp ) {
		::DeleteObject( m_pBmp ) ;
		m_pBmp = NULL ;
	}
	m_pBmp	= NULL ;
	HINSTANCE	hInstResource = NULL;	
	hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nBitmapIn), RT_BITMAP);
	if( NULL != hInstResource ) {
		m_pBmp = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapIn), IMAGE_BITMAP, 0, 0, 0);
	}
}

void CMessageBoxEx::SetBitmap(UINT uBmpResource)
{
	HBITMAP hBitmap; //meaasgeboxеͼƬ 
	CStatic *pStatic = (CStatic *)GetDlgItem(IDC_IMAGE); 
	//ͼƬID 
	hBitmap = (HBITMAP)LoadImage(    
	AfxGetInstanceHandle(), 
	MAKEINTRESOURCE(uBmpResource), 
	IMAGE_BITMAP, 
	0, 
	0, 
	LR_LOADMAP3DCOLORS); 
	pStatic->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE); 
	pStatic->SetBitmap(hBitmap); 
}

BOOL CMessageBoxEx::OnInitDialog()
{
	CDialogBase::OnInitDialog();
	int nIconLeftMargin = 25;    //ͼʾ߾
	int nIconTopMargin = 45;     //ͼʾϱ߾
	int nBtBottomMargin = 10;    //ťʾ±߾
	int nBtRightMargin = 15;     //ťʾұ߾

	int nLeftMargin = 75;    //static߾
	int nRightMargin = 55;   //staticұ߾
    int nBottomMargin = 65;  //static±߾
	int nStaticHeigh = 0;    //static߶
	int nStaticWidth = 0;    //static
	int nDialogWidth = 0;
	int nDialogHight = 0;
	CClientDC dc(this);   
	//ݳȼʾĴС
	int nRow = 1;
	CSize nFontSize = dc.GetTextExtent(m_Text);
	if(nFontSize.cx > MAX_WIDTH - nLeftMargin -nRightMargin) {
		nDialogWidth = MAX_WIDTH;
		nStaticWidth = MAX_WIDTH - nLeftMargin -nRightMargin;
		
	}
	else {
		nDialogWidth = nFontSize.cx + nLeftMargin + nRightMargin;	
		nStaticWidth = nFontSize.cx;
		
	}
	int nPos = m_Text.ReverseFind('\n');
	if(nPos != -1) {
		nRow = m_Text.Replace("\n", "\n");
		CString substr = m_Text.Right(m_Text.GetLength()-nPos);
		CSize nSubstrSize = dc.GetTextExtent(substr);
		nRow +=  nSubstrSize.cx / nStaticWidth;
	}else {
		nRow =  nFontSize.cx / nStaticWidth;
	}
	
	nDialogHight = nRow * nFontSize.cy + nBottomMargin + nIconTopMargin;
	nStaticHeigh = nRow * nFontSize.cy;

	// TODO:  ڴӶĳʼ
	UpdateData(FALSE);
	
	CRect rect;
	theApp.m_pMainWnd->GetWindowRect(&rect);
	theApp.m_pMainWnd->ClientToScreen(rect);
	MoveWindow((rect.left + rect.right)/2 - nDialogWidth/2,(rect.top + rect.bottom)/2 - nDialogHight/2 ,nDialogWidth, nDialogHight, FALSE);
	CenterWindow();
	
	m_fontGrid.CreatePointFont(100,_T(""));

{'fraction_non_alphanumeric': 0.1306510607168983, 'fraction_numerical': 0.009802487198244331, 'mean_word_length': 4.807986406117247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3676477', 'n_tokens_mistral': 3150, 'n_tokens_neox': 3051, 'n_words': 477}