Hello everyone!
I've used a list control to display data and an edit box to edit them. So I used this function:
void CDataDialog::SetCell(HWND hWnd1,
CString value, int nRow, int nCol)
I want to make this change:
void CDataDialog::SetCell(HWND hWnd1,
double value, int nRow, int nCol)
but I have problem with other functions such as GetDlgItemText which I don't know how to change. Here is the code:
void CDataDialog::SetCell(HWND hWnd1,
double value, int nRow, int nCol)
{
TCHAR szString[256];
swprintf(szString, value, 0);
LVITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = nRow;
lvItem.pszText = szString;
lvItem.iSubItem = nCol;
if (nCol >0)
::SendMessage(hWnd1, LVM_SETITEM,
(WPARAM)0, (WPARAM)&lvItem);
else
ListView_InsertItem(hWnd1, &lvItem);
}
CString CDataDialog::GetItemText(
HWND hWnd, int nItem, int nSubItem) const
{
LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.iSubItem = nSubItem;
CString str;
int nLen = 128;
int nRes;
do
{
nLen *= 2;
lvi.cchTextMax = nLen;
lvi.pszText = str.GetBufferSetLength(nLen);
nRes = (int)::SendMessage(hWnd,
LVM_GETITEMTEXT, (WPARAM)nItem,
(LPARAM)&lvi);
} while (nRes == nLen - 1);
str.ReleaseBuffer();
return str;
}
void CDataDialog::OnClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
Invalidate();
HWND hWnd1 = ::GetDlgItem(m_hWnd, IDC_LIST1);
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE)pNMHDR;
RECT rect;
nItem = temp->iItem;
nSubItem = temp->iSubItem;
if (nSubItem == 0 || nSubItem == -1 || nItem == -1)
return;
CString str = GetItemText(hWnd1, nItem,
nSubItem);
RECT rect1, rect2;
ListView_GetSubItemRect(hWnd1, temp->iItem,
temp->iSubItem, LVIR_BOUNDS, &rect);
::GetWindowRect(temp->hdr.hwndFrom, &rect1);
::GetWindowRect(m_hWnd, &rect2);
int x = rect1.left - rect2.left;
int y = rect1.top - rect2.top;
if (nItem != -1)
::SetWindowPos(::GetDlgItem(m_hWnd, IDC_EDIT1),
HWND_TOP, rect.left + x, rect.top + 4,
rect.right - rect.left - 3,
rect.bottom - rect.top - 1, NULL);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_SHOW);
::SetFocus(::GetDlgItem(m_hWnd, IDC_EDIT1));
::Rectangle(::GetDC(temp->hdr.hwndFrom),
rect.left, rect.top - 1, rect.right, rect.bottom);
::SetWindowText(::GetDlgItem(m_hWnd, IDC_EDIT1), str);
*pResult = 0;
}
void CDataDialog::OnOK()
{
CWnd* pwndCtrl = GetFocus();
int ctrl_ID = pwndCtrl->GetDlgCtrlID();
double str;
switch (ctrl_ID)
{
case IDC_EDIT1:
GetDlgItemText(IDC_EDIT1, str);
SetCell(::GetDlgItem(m_hWnd, IDC_LIST1),
str, nItem, nSubItem);
::SendDlgItemMessage(m_hWnd, IDC_EDIT1,
WM_KILLFOCUS, 0, 0);
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1),
SW_HIDE);
break;
default:
break;
}
}
Thank you in advance! 
|