📄 texttooldlg.cpp
字号:
// TextToolDlg.cpp : implementation file
//
#include "stdafx.h"
#include "毕业设计.h"
#include "TextToolDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTextToolDlg dialog
CTextToolDlg::CTextToolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTextToolDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTextToolDlg)
m_text = _T("");
//}}AFX_DATA_INIT
par = pParent;
bmp = NULL;
contyp = NULL;
oldcontyp = 0;
bx = 0;
by = 0;
dy = 12;
num = 1;
dx[0] = 0;
utype = FALSE;
btype = FALSE;
itype = FALSE;
height = 12;
}
void CTextToolDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTextToolDlg)
DDX_Control(pDX, IDC_LIST1, m_t);
DDX_Control(pDX, IDC_COMBO1, m_name);
DDX_Control(pDX, IDC_COMBO2, m_h);
DDX_Text(pDX, IDC_EDIT1, m_text);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTextToolDlg, CDialog)
//{{AFX_MSG_MAP(CTextToolDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_WM_CLOSE()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_CBN_KILLFOCUS(IDC_COMBO2, OnKillfocusCombo2)
ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
ON_WM_TIMER()
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTextToolDlg message handlers
void CTextToolDlg::Close(){
OnOK();
}
int CALLBACK EnumFontsProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,DWORD dwStyle, LONG lParam)
{
UINT i ;
// check to see if the font is already there right off the bat
// and just continue the enumeration if it is...
i = SendDlgItemMessage((HWND) lParam, IDC_LIST1, LB_ADDSTRING, (WPARAM) 0,(LONG) (LPTSTR) lplf->lfFaceName) ;
return 1 ;
}
BOOL CTextToolDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// ::BringWindowToTop(m_hWnd);
// SetWindowPos(this,0,0,0,0,GetStyle( )&WS_EX_TOPMOST);
SetWindowPos(&wndTopMost,0,0,326,228,0);
if(bmp){
bmp->GetFont(lft);
if(lft.lfWeight==700){
btype = TRUE;
}
itype = lft.lfItalic;
utype = lft.lfUnderline;
height = lft.lfHeight;
}
m_h.AddString(" 8");
m_h.AddString(" 9");
m_h.AddString("10");
m_h.AddString("11");
m_h.AddString("12");
m_h.AddString("14");
m_h.AddString("16");
m_h.AddString("18");
m_h.AddString("20");
m_h.AddString("22");
m_h.AddString("24");
m_h.AddString("26");
m_h.AddString("28");
m_h.AddString("36");
m_h.AddString("48");
m_h.AddString("72");
HDC hdc;
hdc = ::GetDC(m_hWnd);
EnumFontFamilies(hdc, (LPTSTR) NULL, (FONTENUMPROC) EnumFontsProc, (LONG) m_hWnd) ;
::ReleaseDC(m_hWnd, hdc);
SetTimer(1015,10,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTextToolDlg::OnChangeEdit1()
{
// 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();
char s[1024];
int i = 0,j = 0;
strcpy(s,m_text);
num = 0;
do{
j = m_text.Find("\n",i);
if(j>=0){
s[j-1] = '\0';
}
dx[num] = strlen(&s[i])*8;
str[num] = &s[i];
i = j+1;
num++;
}while(j>=0);
bmp->TextTemp(bx,by,str,num,dy);
par->Invalidate(FALSE);
// TODO: Add your control notification handler code here
}
BOOL CTextToolDlg::Select(int x,int y){
int ti = (y-by)/dy;
if(ti>=0&&ti<num&&x>=bx&&x<bx+dx[ti]){
return TRUE;
}
else {
return FALSE;
}
}
void CTextToolDlg::Move(int x,int y){
bx+=x,by+=y;
bmp->TextTemp(bx,by,str,num,dy);
}
void CTextToolDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
*contyp = oldcontyp;
OnButton1();
par->Invalidate(FALSE);
CDialog::OnClose();
}
void CTextToolDlg::OnButton1()
{
// TODO: Add your control notification handler code here
if(m_text.GetLength()==0){
return;
}
bmp->TextOK(bx,by,str,num,dx,dy);
par->Invalidate(FALSE);
m_text = "";
UpdateData(FALSE);
num = 1;
dx[0] = 0;
bx = 0;
by = 0;
}
void CTextToolDlg::OnOK(){
OnButton1();
CDialog::OnOK();
}
void CTextToolDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CBitmap bbmp,ibmp,ubmp;
if(btype){
bbmp.LoadBitmap(IDB_WB2);
}
else{
bbmp.LoadBitmap(IDB_WB1);
}
if(itype){
ibmp.LoadBitmap(IDB_WI2);
}
else{
ibmp.LoadBitmap(IDB_WI1);
}
if(utype){
ubmp.LoadBitmap(IDB_WU2);
}
else{
ubmp.LoadBitmap(IDB_WU1);
}
CDC mdc;
mdc.CreateCompatibleDC(&dc);
CBitmap * obmp;
obmp = mdc.SelectObject(&bbmp);
dc.BitBlt(168,13,25,25,&mdc,0,0,SRCCOPY);
mdc.SelectObject(&ibmp);
dc.BitBlt(196,13,25,25,&mdc,0,0,SRCCOPY);
mdc.SelectObject(&ubmp);
dc.BitBlt(224,13,25,25,&mdc,0,0,SRCCOPY);
mdc.SelectObject(obmp);
// Do not call CDialog::OnPaint() for painting messages
}
void CTextToolDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.y>=13&&point.y<38){
if(point.x>=168&&point.x<=193){
btype = !btype;
}
else if(point.x>=196&&point.x<=221){
itype = !itype;
}
else if(point.x>=224&&point.x<=249){
utype = !utype;
}
lft.lfStrikeOut = FALSE;
lft.lfEscapement = 0;
lft.lfWeight = FW_NORMAL;//400;
if(btype){
lft.lfWeight = 700;
}
CString strs;
m_name.GetWindowText(strs);
lft.lfItalic = itype;
lft.lfUnderline = utype;
lft.lfHeight = height;
lft.lfClipPrecision = CLIP_LH_ANGLES;
strcpy(lft.lfFaceName,strs);
bmp->SetFont(lft);
bmp->TextTemp(bx,by,str,num,dy);
Invalidate(FALSE);
par->Invalidate(FALSE);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CTextToolDlg::OnKillfocusCombo2()
{
// TODO: Add your control notification handler code here
OnSelchangeCombo2();
}
void CTextToolDlg::OnSelchangeCombo2()
{
// TODO: Add your control notification handler code here
// GetDlgItem(IDC_BUTTON1)->SetFocus();
SetTimer(15,10,NULL);
}
void CTextToolDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 15){
KillTimer(15);
CString strs;
m_name.GetWindowText(strs);
char ch[10];
m_h.GetWindowText(ch,10);
height = atoi(ch);
dy = height;
lft.lfStrikeOut = FALSE;
lft.lfEscapement = 0;
lft.lfWeight = FW_NORMAL;//400;
if(btype){
lft.lfWeight = 700;
}
lft.lfItalic = itype;
lft.lfUnderline = utype;
lft.lfHeight = -height;
lft.lfClipPrecision = CLIP_LH_ANGLES;
strcpy(lft.lfFaceName,strs);
bmp->SetFont(lft);
bmp->TextTemp(bx,by,str,num,dy);
par->Invalidate(FALSE);
}
else{
KillTimer(1015);
CString str;
int n = m_t.GetCount();
for(int i = 0;i<n;i++){
m_t.GetText(i,str);
m_name.AddString(str);
}
}
CDialog::OnTimer(nIDEvent);
}
void CTextToolDlg::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
SetTimer(15,10,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -