📄 myedit.cpp
字号:
// Copyright (c) Iuri Apollonio 1998
// Use & modify as you want & need, and leave those 4 lines.
// Strongly based on article "Inplace edit control" of Mario Contestabile and "Editable subitems" of Zafir
// http://www.codeguru.com
// GfxGroupEdit.cpp : implementation file
//
#include "stdafx.h"
//#include "micq.h"
#include "MyEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyEdit
CMyEdit::CMyEdit()
{
bEscapeKey=false;
bAlwaysshow=false;
bEnable=true;
}
CMyEdit::~CMyEdit()
{
}
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
//{{AFX_MSG_MAP(CMyEdit)
ON_WM_KILLFOCUS()
ON_WM_CREATE()
ON_WM_CHAR()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyEdit message handlers
void CMyEdit::OnKillFocus(CWnd* pNewWnd)
{
if(!bAlwaysshow)
{
PostMessage(WM_CLOSE, 0, 0);
if (!bEscapeKey)
{
CString s;
GetWindowText(s);
if (s.GetBuffer(100))
{
if(lstrlen(((CMyLabel *)pParent)->cName)>0)
delete ((CMyLabel *)pParent)->cName;
((CMyLabel *)pParent)->cName = new char[lstrlen(s.GetBuffer(100))+1];
ASSERT(((CMyLabel *)pParent)->cName);
lstrcpy(((CMyLabel *)pParent)->cName, s.GetBuffer(100));
}
}
((CMyLabel *)pParent)->bEditShow=false;
}
else
{
CString s;
GetWindowText(s);
if (s.GetBuffer(100))
{
if(lstrlen(((CMyLabel *)pParent)->cName)>0)
delete ((CMyLabel *)pParent)->cName;
((CMyLabel *)pParent)->cName = new char[lstrlen(s.GetBuffer(100))+1];
ASSERT(((CMyLabel *)pParent)->cName);
lstrcpy(((CMyLabel *)pParent)->cName, s.GetBuffer(100));
}
}
CEdit::OnKillFocus(pNewWnd);
}
BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
if(!bAlwaysshow)
{
if (pMsg->wParam == VK_RETURN)
{
PostMessage(WM_CLOSE, 0, 0);
return TRUE;
}
else if (pMsg->wParam == VK_ESCAPE)
{
PostMessage(WM_CLOSE, 0, 0);
return bEscapeKey = TRUE;
}
}
else //一直显示
{
if (pMsg->wParam == VK_RETURN)
{
CString s;
GetWindowText(s);
strcat(s.GetBuffer(2000),"\n\r");
SetWindowText(s);
SetSel(lstrlen(s.GetBuffer(2000)),lstrlen(s.GetBuffer(2000)));
}
}
return CEdit::PreTranslateMessage(pMsg);
}
void CMyEdit::PostNcDestroy()
{
CEdit::PostNcDestroy();
delete this;
}
int CMyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
SendMessage(WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT),MAKELPARAM(TRUE,0));
return 0;
}
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(!bEnable)return;
if(!bAlwaysshow)
{
if (nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if (nChar == VK_ESCAPE) bEscapeKey = TRUE;
GetParent()->SetFocus();
return;
}
}
else //一直显示
{
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
void CMyEdit::Create(DWORD dwStyle, CWnd *parentWnd, void *label,int id)
{
pParentWnd=parentWnd;
pParent=label; //因为此控件由CMyLabel调用
CEdit::Create(dwStyle|WS_VISIBLE|WS_BORDER|WS_CHILD,editRC,pParentWnd,WM_USER + 1000+id);
if(!bAlwaysshow)SetWindowText(((CMyLabel *)pParent)->cName);
((CMyLabel *)pParent)->bEditShow=true;
SetFocus();
}
void CMyEdit::setAlwaysShow(bool show)
{
bAlwaysshow=show;
}
void CMyEdit::setPos(CRect rc)
{
editRC=rc;
}
void CMyEdit::setEnable(bool enable)
{
bEnable=enable;
}
void CMyEdit::OnLButtonDown(UINT nFlags, CPoint point)
{
SetFocus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -