Article ID: 196833
Article Last Modified on 11/21/2006
119591 How to Obtain Microsoft Support Files from Online Services
void CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar != 13) // Ignore ENTER key.
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar == 27) // Esc means "Cancel".
{
SetWindowText("");
ShowWindow(SW_HIDE);
GetParent()->SetFocus();
}
else if (nChar == 13) // Enter means "OK".
GetParent()->SetFocus();
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}
public:
CEditWnd m_edit;
long m_lBorderWidth;
long m_lBorderHeight;
int m_nLogX;
int m_nLogY;
void CEditGrid::PreSubclassWindow()
{
// Calculate border size.
SetRow(0);
SetCol(0);
m_lBorderWidth = GetCellLeft();
m_lBorderHeigth = GetCellTop();
// To convert grid rect from twips to DC units you need
// pixels per inch.
CDC* pDC = GetDC();
m_nLogX = pDC->GetDeviceCaps(LOGPIXELSX);
m_nLogY = pDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pDC);
// Create invisible edit control.
m_edit.Create(WS_CHILD|ES_MULTILINE|ES_WANTRETURN,
CRect(0,0,0,0), this, GetDlgCtrlID());
}
EditGrid.h
protected:
afx_msg void OnKeyPressGrid(short FAR* KeyAscii);
afx_msg void OnDblClickGrid();
afx_msg void OnUpdateGrid();
DECLARE_EVENTSINK_MAP()
EdtGrid.cpp
BEGIN_EVENTSINK_MAP(CEditGrid, CMSFlexGrid)
// {{AFX_EVENTSINK_MAP(CEditGrid)
// }}AFX_EVENTSINK_MAP
ON_EVENT_REFLECT(CEditGrid, -603 /* KeyPress */, OnKeyPressGrid,
VTS_PI2)
ON_EVENT_REFLECT(CEditGrid, -601 /* DblClick */, OnDblClickGrid,
VTS_NONE)
ON_EVENT_REFLECT(CEditGrid, 72 /* LeaveCell */, OnUpdateGrid,
VTS_NONE)
END_EVENTSINK_MAP()
void CEditGrid::OnDblClickGrid()
{
short i = 13;
OnKeyPressGrid(&i); // Simulate a return.
}
void CEditGrid::OnKeyPressGrid(short FAR* KeyAscii)
{
ASSERT (KeyAscii != NULL);
m_edit.SetWindowText(GetText());
if (*KeyAscii == 13)
m_edit.SetSel(0,-1);
else
{
char buf[] = " ";
buf[0] = (char)*KeyAscii;
m_edit.SetSel(-1,-1);
m_edit.ReplaceSel(buf);
}
// Adjust for border height and convert from twips to screen
// units.
m_edit.MoveWindow(((GetCellLeft() - m_lBorderWidth) *
m_nLogX)/1440,
((GetCellTop() - m_lBorderHeight) * m_nLogY)/1440,
(GetCellWidth()* m_nLogX)/1440,
(GetCellHeight()* m_nLogY)/1440, FALSE);
m_edit.ShowWindow(SW_SHOW);
m_edit.SetFocus();
}
void CEditGrid::OnUpdateGrid()
{
// Check to see if edit is visible.
BOOL bVisible = ::GetWindowLong(m_edit.GetSafeHwnd(), GWL_STYLE)
& WS_VISIBLE;
if (bVisible)
{
CString cStr;
m_edit.GetWindowText(cStr);
SetText(cStr);
m_edit.SetWindowText("");
m_edit.ShowWindow(SW_HIDE);
}
}
UINT CEditGrid::OnGetDlgCode()
{
return DLGC_WANTALLKEYS;
}
void CEditGrid::OnSetFocus(CWnd* pOldWnd)
{
CMSFlexGrid::OnSetFocus(pOldWnd);
OnUpdateGrid();
}
Cols = 6
Rows = 20
FillStyle = 1 - Repeat
FocusRect = 2 - Heavy
Keywords: kbdownload kbcontainer kbctrl kbfile kbsample KB196833