📄 atlgroupedit.h
字号:
// 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
//
// =============================================================================
//
// Port to ATL/WTL Rashid Thadha 01/03/2001
//
// =============================================================================
#if !defined(ATL_GROUPEDIT_H__)
#define ATL_GROUPEDIT_H__
#include "atloutbarctrl.h"
class CGroupEdit : public CWindowImpl<CGroupEdit, CEdit>
{
// Construction
public:
CGroupEdit()
{
bEscapeKey = FALSE;
iIndex = -1;
msgSend = NM_OB_ONGROUPENDEDIT;
bNoDown = FALSE;
}
BEGIN_MSG_MAP(CGroupEdit)
MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
MESSAGE_HANDLER(WM_CHAR, OnChar)
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
// Attributes
public:
BOOL bEscapeKey;
CString text;
WPARAM msgSend;
BOOL bNoDown;
int iIndex;
virtual ~CGroupEdit()
{
}
LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostMessage(WM_CLOSE, 0, 0);
if (!bEscapeKey)
{
TCHAR cValue[1000];
GetWindowText(cValue, sizeof(cValue));
text = cValue;
CWindow wnd(GetParent());
if (text != "")
wnd.SendMessage(WM_OUTBAR_NOTIFY, msgSend, (LPARAM) this);
}
return 0;
}
LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
UINT nChar = (UINT)wParam;
if (nChar == VK_RETURN)
{
PostMessage(WM_CLOSE, 0, 0);
return 0;
}
else if (nChar == VK_ESCAPE)
{
PostMessage(WM_CLOSE, 0, 0);
bEscapeKey = TRUE;
return 0;
}
if (msgSend == NM_OB_ONGROUPENDEDIT)
{
bHandled = FALSE;
return 0;
}
// why do you need this ??
if (nChar == VK_ESCAPE || nChar == VK_RETURN)
{
if (nChar == VK_ESCAPE) bEscapeKey = TRUE;
CWindow wnd(GetParent());
wnd.SetFocus();
bHandled = TRUE;
return 0;
}
CWindow wnd(GetParent());
CString str;
CRect rect, parentrect;
GetClientRect(&rect);
wnd.GetClientRect(&parentrect);
ClientToScreen(&rect);
wnd.ScreenToClient(&rect);
TCHAR cValue[1000];
GetWindowText(cValue, sizeof(cValue));
str = cValue;
CWindowDC dc(m_hWnd);
HFONT pFont = wnd.GetFont();
HFONT pFontDC = dc.SelectFont(pFont);
CRect szrc(rect);
szrc.bottom = szrc.top;
if (bNoDown == TRUE)
{
dc.DrawText(str, -1, szrc, DT_CALCRECT);
if (szrc.right >= parentrect.right - 1) rect.right = parentrect.right - 1;
else rect.right = szrc.right;
MoveWindow(&rect);
bHandled = FALSE;
return 0;
}
dc.DrawText(str, -1, szrc, DT_WORDBREAK|DT_CENTER|DT_CALCRECT);
dc.SelectFont(pFontDC);
CSize size = szrc.Size();
if (size.cx > rect.Width())
{
if (size.cx + rect.left < parentrect.right) rect.right = rect.left + size.cx;
else rect.right = parentrect.right;
MoveWindow(&rect);
}
else if (size.cy > rect.Height())
{
if (size.cy + rect.bottom < parentrect.bottom) rect.bottom = rect.top + size.cy;
else rect.bottom = parentrect.bottom;
MoveWindow(&rect);
}
bHandled = FALSE;
return 0;
}
};
#endif //ATL_GROUPEDIT_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -