SDC C-Project CF Review 프로그램
LYW
2021-07-01 668b40db8e394058c7e0abad2fbe539a631043c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// InPlaceEdit.cpp : implementation file
//
 
#include "stdafx.h"
#include "InPlaceEdit.h"
#include "ListCtrlEx.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static TCHAR THIS_FILE[] = _T(__FILE__);
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit
 
CInPlaceEdit::CInPlaceEdit(int iItem, int iSubItem, CString sInitText) : m_sInitText(sInitText)
{
    m_iItem = iItem ;
    m_iSubItem = iSubItem ;
    m_bESC = FALSE ;
 
}
 
CInPlaceEdit::~CInPlaceEdit()
{            
 
}
 
 
BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit)
    //{{AFX_MSG_MAP(CInPlaceEdit)
    ON_WM_KILLFOCUS()
    ON_WM_NCDESTROY()
    ON_WM_CHAR()
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit message handlers
 
 
void CInPlaceEdit::OnKillFocus(CWnd* pNewWnd) 
{
    CEdit::OnKillFocus(pNewWnd);
    
    // TODO: Add your message handler code here
 
    DestroyWindow() ;
    
}
 
void CInPlaceEdit::OnNcDestroy() 
{
    CEdit::OnNcDestroy();
    
    // TODO: Add your message handler code here
 
}
 
void CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
    // TODO: Add your message handler code here and/or call default
    if (nChar == VK_ESCAPE || nChar == VK_RETURN)
    {
        if(nChar == VK_ESCAPE)
            m_bESC = TRUE ;
        GetParent()->SetFocus() ;
        return ;
    }
    
    CEdit::OnChar(nChar, nRepCnt, nFlags);
 
    CString str ;
 
    GetWindowText(str) ;
    CWindowDC dc(this) ;
    CFont *pFont = GetParent()->GetFont() ;
    CFont *pFontDC = dc.SelectObject(pFont) ;
    CSize size = dc.GetTextExtent(str) ;
    dc.SelectObject(pFontDC) ;
    size.cx += 5 ;
 
    CRect rect, parentrect = CRect(0,0,0,0) ;
    GetClientRect(&rect) ;
    GetParent()->ScreenToClient(&rect) ;
 
    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) ;
    }
}
 
int CInPlaceEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CEdit::OnCreate(lpCreateStruct) == -1)
        return -1;
    
    // TODO: Add your specialized creation code here
//    long style;
//    style = GetWindowLong(this->m_hWnd,GWL_STYLE);
//    style |= ES_AUTOVSCROLL;
//    SetWindowLong(this->m_hWnd,GWL_STYLE,style);
 
    CFont* font = GetParent()->GetFont() ;
    SetFont(font) ;
 
    SetWindowText(m_sInitText) ;
    SetFocus() ;
    SetSel(0, -1) ;
 
    return 0;
}
 
BOOL CInPlaceEdit::PreTranslateMessage(MSG* pMsg) 
{
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->message == WM_KEYDOWN)
    {
        if(pMsg->wParam == VK_RETURN || pMsg->wParam == VK_DELETE
                || pMsg->wParam == VK_ESCAPE
                || GetKeyState(VK_CONTROL))
        {
            ::TranslateMessage(pMsg) ;
            ::DispatchMessage(pMsg) ;
 
            if(pMsg->wParam == VK_RETURN)
            {
                CString str ;
                GetWindowText(str) ;
 
                ((CListCtrlEx*)GetParent())->InsertListItem(m_iItem,m_iSubItem,(LPTSTR)(LPCTSTR)str);
            }
            return TRUE ;
        }
    }
 
    return CEdit::PreTranslateMessage(pMsg);
}