📄 notepaddlg.cpp
字号:
// NotepadDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Notepad.h"
#include "NotepadDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNotepadDlg dialog
#define Width 480
#define Height 272
#define TEXT_LEFT 160
#define TEXT_TOP 63
#define TEXT_RIGHT 405
#define TEXT_BOTTOM 210
_MYNOTEBTN g_notebtn[] = {
{UP, IDB_EXITUNSEL, IDB_EXITSEL, IDB_EXITUNSEL, {384,0,480,31}},
// {UP, IDB_NOTEPADTITLE, IDB_NOTEPADTITLE, IDB_NOTEPADTITLE, {20,50,120,220}},
{UP, IDB_TITLEUP, IDB_TITLEUP, IDB_TITLEUP, {23,40,117,87}},
{UP, IDB_TITLEBAR, IDB_TITLEBAR, IDB_TITLEBAR, {23,77,117,114}},
{UP, IDB_TITLEBAR, IDB_TITLEBAR, IDB_TITLEBAR, {23,114,117,151}},
{UP, IDB_TITLEBAR, IDB_TITLEBAR, IDB_TITLEBAR, {23,151,117,188}},
{UP, IDB_TITLEDOWN, IDB_TITLEDOWN, IDB_TITLEDOWN, {23,188,117,225}},
{UP, IDB_NOTEPADTEXT, IDB_NOTEPADTEXT, IDB_NOTEPADTEXT, {143,50,413,220}},
{DISABLE, IDB_UPPAGEUNSEL, IDB_UPPAGESEL, IDB_UPPAGEDISABLE, {414,50,460,96}},
{DISABLE, IDB_DOWNPAGEUNSEL, IDB_DOWNPAGESEL,IDB_DOWNPAGEDISABLE, {414,174,460,220}},
{UP, IDB_NOTEBTNUNSEL, IDB_NOTEBTNSEL, IDB_NOTEBTNUNSEL, {50,230,118,264}},
{UP, IDB_NOTEBTNUNSEL, IDB_NOTEBTNSEL, IDB_NOTEBTNUNSEL, {150,230,218,264}},
{UP, IDB_NOTEBTNUNSEL, IDB_NOTEBTNSEL, IDB_NOTEBTNUNSEL, {250,230,318,264}},
{UP, IDB_NOTEBTNUNSEL, IDB_NOTEBTNSEL, IDB_NOTEBTNUNSEL, {350,230,418,264}},
};
CNotepadDlg::CNotepadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNotepadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNotepadDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_Firstflag = true;
pInputDlg = NULL;
g_UpPageflag = false;
g_DownPageflag = false;
g_Row = 1;
g_col = 1;
g_DownRowflag = 0;
g_Notetextlen = 0;
g_templen = 0;
ptext = 0;
pArray = NULL;
g_TitleCount = 0;
g_downtitleflag = 0;
memset(NoteFileName, 0, sizeof(NoteFileName));
memset(m_Titleone, 0, sizeof(m_Titleone));
memset(m_Titletwo, 0, sizeof(m_Titletwo));
memset(m_Titlethree, 0, sizeof(m_Titlethree));
}
void CNotepadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNotepadDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNotepadDlg, CDialog)
//{{AFX_MSG_MAP(CNotepadDlg)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNotepadDlg message handlers
BOOL CNotepadDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
SetCursorPos(500,500);
InitResource();
m_Text = new TCHAR[5000];
memset(m_Text, 0, 5000);
pArray = new int;
pArray[0] = g_templen;
if (m_Firstflag)
{
for (int i = 0; i < NOTEPAD_END; i ++)
g_notebtn[i].status = UP;
g_notebtn[NOTE_UPPAGE].status = DISABLE;
g_notebtn[NOTE_DOWNPAGE].status = DISABLE;
m_Firstflag = false;
}
HKEY hkey;
DWORD dwType,dwSize;
DWORD dwState1 = 0;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, _T("ControlPanel\\NotePad"),0,0,&hkey))
{
dwSize = sizeof(dwSize);
RegQueryValueEx(hkey, _T("TitleCount"), 0, &dwType, (LPBYTE)&dwState1, &dwSize);
RegCloseKey(hkey);
}
if (dwState1 > 0)
g_TitleCount = dwState1;
if (g_TitleCount > 0)
{
FILE * pFile = _wfopen(_T("\\ResidentFlash\\FileName.txt"),_T("rb"));
if (pFile == NULL)
{
MessageBox(_T("Fail"), _T("Open file Fail"));
return FALSE;
}
else
{
TCHAR TitleName[50] = {0};
int len = fread(TitleName, 1, 3*16, pFile);
TitleName[len] = 0;
CString str = TitleName;
int length = str.GetLength();
if (g_TitleCount == 1)
wcscpy(m_Titleone, str.Left(6));
else if (g_TitleCount == 2)
{
wcscpy(m_Titleone, str.Left(6));
str = str.Right(8);
wcscpy(m_Titletwo, str.Left(6));
}
else
{
wcscpy(m_Titleone, str.Left(6));
str = str.Right(16);
wcscpy(m_Titletwo, str.Left(6));
str = str.Right(8);
wcscpy(m_Titlethree, str.Left(6));
}
fclose(pFile);
}
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CNotepadDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CNotepadDlg::InitResource()
{
bitmapback.LoadBitmap(IDB_BMPBACK);
ExitbmpSel.LoadBitmap(IDB_EXITSEL);
ExitbmpUnsel.LoadBitmap(IDB_EXITUNSEL);
NoteTextbmp.LoadBitmap(IDB_NOTEPADTEXT);
DownpagebmpSel.LoadBitmap(IDB_DOWNPAGESEL);
DownpagebmpUnsel.LoadBitmap(IDB_DOWNPAGEUNSEL);
DownpagebmpDis.LoadBitmap(IDB_DOWNPAGEDISABLE);
UppagebmpSel.LoadBitmap(IDB_UPPAGESEL);
UppagebmpUnsel.LoadBitmap(IDB_UPPAGEUNSEL);
UppagebmpDis.LoadBitmap(IDB_UPPAGEDISABLE);
TitleDownbmp.LoadBitmap(IDB_TITLEDOWN);
TitleUpbmp.LoadBitmap(IDB_TITLEUP);
TitleBarbmp.LoadBitmap(IDB_TITLEBAR);
NoteBtnSel.LoadBitmap(IDB_NOTEBTNSEL);
NoteBtnUnsel.LoadBitmap(IDB_NOTEBTNUNSEL);
}
BOOL CNotepadDlg::OnEraseBkgnd(CDC * pDC)
{
if (9 < g_Row)
{
g_DownPageflag = true;
g_notebtn[NOTE_DOWNPAGE].status = DOWN;
}
CBitmap membitmap;
membitmap.CreateCompatibleBitmap(pDC, Width, Height);
CDC memDC, tempDC;
tempDC.CreateCompatibleDC(pDC);
memDC.CreateCompatibleDC(pDC);
CBitmap * tOldbitmap = tempDC.SelectObject(&bitmapback);
CBitmap * pOldbitmap = memDC.SelectObject(&membitmap);
memDC.BitBlt(0, 0, Width, Height, &tempDC, 0, 0, SRCCOPY);
tempDC.SelectObject(tOldbitmap);
tempDC.DeleteDC();
CBitmap * btn_bmp = NULL;
for (int i = 0; i < NOTEPAD_END; i++)
{
int top,left,bottom,right;
if (i == NOTE_EXIT)
{
right = 96;
bottom = 31;
if (UP == g_notebtn[i].status)
btn_bmp = &ExitbmpUnsel;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &ExitbmpSel;
else
btn_bmp = &ExitbmpUnsel;
}
else if (i == NOTE_UPPAGE || i == NOTE_DOWNPAGE)
{
right = 46;
bottom = 46;
if (i == NOTE_UPPAGE)
if (UP == g_notebtn[i].status)
btn_bmp = &UppagebmpUnsel;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &UppagebmpSel;
else
btn_bmp = &UppagebmpDis;
else
if (UP == g_notebtn[i].status)
btn_bmp = &DownpagebmpUnsel;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &DownpagebmpSel;
else
btn_bmp = &DownpagebmpDis;
}
else if (i == NOTE_TEXT)
{
right = 270;
bottom = 170;
btn_bmp = &NoteTextbmp;
}
else if (i >= NOTE_NEW && i <= NOTE_DEL)
{
right = 68;
bottom = 34;
if (UP == g_notebtn[i].status)
btn_bmp = &NoteBtnUnsel;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &NoteBtnSel;
else
btn_bmp = &NoteBtnUnsel;
}
else
{
right = 94;
bottom = 37;
if (i == NOTE_TITLEUP)
{
if (UP == g_notebtn[i].status)
btn_bmp = &TitleUpbmp;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &TitleUpbmp;
else
btn_bmp = &TitleUpbmp;
}
else if (i == NOTE_TITLEDOWN)
{
if (UP == g_notebtn[i].status)
btn_bmp = &TitleDownbmp;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &TitleDownbmp;
else
btn_bmp = &TitleDownbmp;
}
else
{
if (UP == g_notebtn[i].status)
btn_bmp = &TitleBarbmp;
else if (DOWN == g_notebtn[i].status)
btn_bmp = &TitleBarbmp;
else
btn_bmp = &TitleBarbmp;
}
}
top = g_notebtn[i].rectbtn.top;
left = g_notebtn[i].rectbtn.left;
CDC btn_memDC;
btn_memDC.CreateCompatibleDC(&memDC);
CBitmap * pbtn_Oldbmp = btn_memDC.SelectObject(btn_bmp);
if (i == NOTE_UPPAGE || i == NOTE_DOWNPAGE)
TransparentImage(memDC.GetSafeHdc(), left, top, right, bottom,
btn_memDC.GetSafeHdc(), 0, 0, right, bottom, btn_memDC.GetPixel(1,1));
else
memDC.BitBlt(left, top, right, bottom, &btn_memDC, 0, 0, SRCCOPY);
btn_memDC.SelectObject(pbtn_Oldbmp);
btn_memDC.DeleteDC();
CPoint m_ptOrigin = CPoint(TEXT_LEFT,TEXT_TOP);
if (i == NOTE_TEXT)
{
if (0 < g_Notetextlen) //GetTextExtent
{
memDC.SetTextColor(RGB(255,255,255));
TCHAR m_displaytext[5000] = {0};
if (g_Row > 9)
wcscpy(m_displaytext, &m_Text[ptext]);
else
wcscpy(m_displaytext, m_Text);
DrawTextToBack(&memDC, 16, 6, TEXT_LEFT, TEXT_TOP, TEXT_RIGHT, TEXT_BOTTOM, RGB(255,255,255),
DT_LEFT|DT_WORDBREAK|DT_EDITCONTROL, m_displaytext, _T("Arial"));
if (0 == g_Notetextlen%20)
m_ptOrigin.x = TEXT_LEFT;
else
m_ptOrigin.x = TEXT_LEFT + (g_Notetextlen - (g_Row*20-20)) * 14;
if (g_Row > 9)
m_ptOrigin.y = TEXT_TOP + 8 * 17;
else
m_ptOrigin.y = TEXT_TOP + (g_Row - 1) * 17;
// CRect rect = CRect(TEXT_LEFT, TEXT_TOP, TEXT_RIGHT, TEXT_BOTTOM);
// int len = wcslen(m_Text);
// m_Text[len] = 0;
// int i = memDC.DrawText(m_Text,-1,rect,DT_CALCRECT);
SetCaretPos(m_ptOrigin);
ShowCaret();
}
else
{
memDC.SetTextColor(RGB(255,255,255));
TEXTMETRIC tm;
memDC.GetOutputTextMetrics(&tm);
tm.tmHeight = 16;
CreateSolidCaret(2, 16);
SetCaretPos(m_ptOrigin);
ShowCaret();
}
}
if ((i >= NOTE_NEW && i <= NOTE_DEL) || (i >= NOTE_TITLEONE && i <= NOTE_TITLETHREE))
DrawNotepadBtnText(i, &memDC);
}
pDC->BitBlt(0, 0, Width, Height, &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldbitmap);
membitmap.DeleteObject();
memDC.DeleteDC();
return TRUE;
}
void CNotepadDlg::DrawNotepadBtnText(int nID, CDC * pDC)
{
TCHAR text[7] = {0};
RECT rect = g_notebtn[nID].rectbtn;
rect.top += 8;
switch(nID)
{
case NOTE_NEW:
wcscpy(text, _T("新建"));
break;
case NOTE_OPEN:
wcscpy(text, _T("打开"));
break;
case NOTE_SAVE:
wcscpy(text, _T("保存"));
break;
case NOTE_DEL:
wcscpy(text, _T("删除"));
break;
case NOTE_TITLEONE:
if (0 < wcslen(m_Titleone))
wcscpy(text, m_Titleone);
else
wcscpy(text, _T(""));
break;
case NOTE_TITLETWO:
if (0 < wcslen(m_Titletwo))
wcscpy(text, m_Titletwo);
else
wcscpy(text, _T(""));
break;
case NOTE_TITLETHREE:
if (0 < wcslen(m_Titlethree))
wcscpy(text, m_Titlethree);
else
wcscpy(text, _T(""));
break;
default:
break;
}
DrawTextToBackforTZ(pDC, 16, 6, rect.left, rect.top, rect.right, rect.bottom,
RGB(0,0,0), DT_CENTER|DT_TOP|DT_SINGLELINE, text, _T("Arial"));
}
int CNotepadDlg::GetBtnIDFormPoint(POINT pt)
{
for (int i = 0; i < NOTEPAD_END; i ++)
{
if (PtInRect(&g_notebtn[i].rectbtn, pt))
break;
}
return i;
}
void CNotepadDlg::OnBtnTitleOne()
{
memset(NoteFileName, 0, sizeof(NoteFileName));
wcscpy(NoteFileName, m_Titleone);
OnNotepadBtnOpen();
}
void CNotepadDlg::OnBtnTitleTwo()
{
memset(NoteFileName, 0, sizeof(NoteFileName));
wcscpy(NoteFileName, m_Titletwo);
OnNotepadBtnOpen();
}
void CNotepadDlg::OnBtnTitleThree()
{
memset(NoteFileName, 0, sizeof(NoteFileName));
wcscpy(NoteFileName, m_Titlethree);
OnNotepadBtnOpen();
}
void CNotepadDlg::OnBtnTitleUp()
{
if (g_TitleCount > 3 && g_downtitleflag > 0)
{
g_downtitleflag --;
FILE * pFile = _wfopen(_T("\\ResidentFlash\\FileName.txt"),_T("rb"));
if (pFile == NULL)
{
MessageBox(_T("Fail"), _T("Open file Fail"));
return ;
}
else
{
TCHAR TitleName[5000] = {0};
int len = fread(TitleName, 1, 5000, pFile);
TitleName[len] = 0;
CString str = TitleName;
int length = str.GetLength();
str = str.Left(24 + g_downtitleflag*8);
if (g_TitleCount > 4)
str = str.Right(24);
wcscpy(m_Titleone, str.Left(6));
m_Titleone[6] = 0;
str = str.Right(16);
wcscpy(m_Titletwo, str.Left(6));
m_Titletwo[6] = 0;
str = str.Right(8);
wcscpy(m_Titlethree, str.Left(6));
m_Titlethree[6] = 0;
fclose(pFile);
InvalidateRect(&g_notebtn[NOTE_TITLEONE].rectbtn, TRUE);
InvalidateRect(&g_notebtn[NOTE_TITLETWO].rectbtn, TRUE);
InvalidateRect(&g_notebtn[NOTE_TITLETHREE].rectbtn, TRUE);
}
}
}
void CNotepadDlg::OnBtnTitleDown()
{
if (g_TitleCount >= 4 && (g_TitleCount - 3) > g_downtitleflag)
{
g_downtitleflag ++; //下移标示
FILE * pFile = _wfopen(_T("\\ResidentFlash\\FileName.txt"),_T("rb"));
if (pFile == NULL)
{
MessageBox(_T("Fail"), _T("Open file Fail"));
return ;
}
else
{
TCHAR TitleName[5000] = {0};
int len = fread(TitleName, 1, 5000, pFile);
TitleName[len] = 0;
CString str = TitleName;
int length = str.GetLength();
str = str.Right(length - g_downtitleflag*8); //从g_downtitleflag+1行开始
if (g_TitleCount > 4)
str = str.Left(24); //只用3组
wcscpy(m_Titleone, str.Left(6));
m_Titleone[6] = 0;
str = str.Right(16);
wcscpy(m_Titletwo, str.Left(6));
m_Titletwo[6] = 0;
str = str.Right(8);
wcscpy(m_Titlethree, str.Left(6));
m_Titlethree[6] = 0;
fclose(pFile);
}
InvalidateRect(&g_notebtn[NOTE_TITLEONE].rectbtn, TRUE);
InvalidateRect(&g_notebtn[NOTE_TITLETWO].rectbtn, TRUE);
InvalidateRect(&g_notebtn[NOTE_TITLETHREE].rectbtn, TRUE);
}
}
void CNotepadDlg::OnBtnUpPage()
{
if (g_DownRowflag > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -