Click here to Skip to main content
15,877,051 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: A complex macro definition Pin
samzcs21-Mar-17 2:22
samzcs21-Mar-17 2:22 
GeneralRe: A complex macro definition Pin
Jochen Arndt21-Mar-17 2:32
professionalJochen Arndt21-Mar-17 2:32 
GeneralRe: A complex macro definition Pin
samzcs21-Mar-17 2:36
samzcs21-Mar-17 2:36 
Questiondev c Pin
Alvi ZaDa20-Mar-17 7:18
Alvi ZaDa20-Mar-17 7:18 
RantRe: dev c Pin
Richard Deeming20-Mar-17 8:47
mveRichard Deeming20-Mar-17 8:47 
AnswerRe: dev c Pin
Victor Nijegorodov20-Mar-17 9:58
Victor Nijegorodov20-Mar-17 9:58 
AnswerRe: dev c Pin
Patrice T20-Mar-17 11:45
mvePatrice T20-Mar-17 11:45 
QuestionChange from Cstring to double in listview vc++ Pin
lolici20-Mar-17 1:31
lolici20-Mar-17 1:31 
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);

	//Fill the LVITEM structure with the 
	//values given as parameters.
	LVITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = nRow;
	lvItem.pszText = szString;
	lvItem.iSubItem = nCol;
	if (nCol >0)
		//set the value of listItem
		::SendMessage(hWnd1, LVM_SETITEM,
		(WPARAM)0, (WPARAM)&lvItem);
	else
		//Insert the value into List
		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)
{
	//LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: Add your control notification handler code here
	//*pResult = 0;
	Invalidate();
	HWND hWnd1 = ::GetDlgItem(m_hWnd, IDC_LIST1);
	LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE)pNMHDR;
	RECT rect;
	//get the row number
	nItem = temp->iItem;
	//get the column number
	nSubItem = temp->iSubItem;
	if (nSubItem == 0 || nSubItem == -1 || nItem == -1)
		return;
	//Retrieve the text of the selected subItem 
	//from the list
	CString str = GetItemText(hWnd1, nItem,
		nSubItem);

	RECT rect1, rect2;
	// this macro is used to retrieve the Rectanle 
	// of the selected SubItem
	ListView_GetSubItemRect(hWnd1, temp->iItem,
		temp->iSubItem, LVIR_BOUNDS, &rect);
	//Get the Rectange of the listControl
	::GetWindowRect(temp->hdr.hwndFrom, &rect1);
	//Get the Rectange of the Dialog
	::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));
	//Draw a Rectangle around the SubItem
	::Rectangle(::GetDC(temp->hdr.hwndFrom),
		rect.left, rect.top - 1, rect.right, rect.bottom);
	//Set the listItem text in the EditBox
	::SetWindowText(::GetDlgItem(m_hWnd, IDC_EDIT1), str);
	*pResult = 0;
}


void CDataDialog::OnOK()
{
	CWnd* pwndCtrl = GetFocus();
	// get the control ID which is 
	// presently having the focus
	int ctrl_ID = pwndCtrl->GetDlgCtrlID();
	double str;
	switch (ctrl_ID)
	{   //if the control is the EditBox 
	case IDC_EDIT1:
		//get the text from the EditBox
		GetDlgItemText(IDC_EDIT1, str);

		//set the value in the listContorl with the
		//specified Item & SubItem values
		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! Smile | :)
AnswerRe: Change from Cstring to double in listview vc++ Pin
Jochen Arndt20-Mar-17 2:02
professionalJochen Arndt20-Mar-17 2:02 
GeneralRe: Change from Cstring to double in listview vc++ Pin
lolici20-Mar-17 2:56
lolici20-Mar-17 2:56 
GeneralRe: Change from Cstring to double in listview vc++ Pin
Jochen Arndt20-Mar-17 3:00
professionalJochen Arndt20-Mar-17 3:00 
GeneralRe: Change from Cstring to double in listview vc++ Pin
lolici20-Mar-17 3:32
lolici20-Mar-17 3:32 
GeneralRe: Change from Cstring to double in listview vc++ Pin
Jochen Arndt20-Mar-17 3:39
professionalJochen Arndt20-Mar-17 3:39 
GeneralRe: Change from Cstring to double in listview vc++ Pin
lolici20-Mar-17 8:02
lolici20-Mar-17 8:02 
AnswerRe: Change from Cstring to double in listview vc++ Pin
Victor Nijegorodov20-Mar-17 6:56
Victor Nijegorodov20-Mar-17 6:56 
GeneralRe: Change from Cstring to double in listview vc++ Pin
lolici20-Mar-17 7:58
lolici20-Mar-17 7:58 
QuestionRe: Change from Cstring to double in listview vc++ Pin
David Crow20-Mar-17 9:52
David Crow20-Mar-17 9:52 
QuestionCrc 32 bit Pin
yagokhan19-Mar-17 21:58
yagokhan19-Mar-17 21:58 
AnswerRe: Crc 32 bit Pin
Jochen Arndt19-Mar-17 22:15
professionalJochen Arndt19-Mar-17 22:15 
AnswerRe: Crc 32 bit Pin
yagokhan19-Mar-17 22:20
yagokhan19-Mar-17 22:20 
GeneralRe: Crc 32 bit Pin
Richard MacCutchan19-Mar-17 22:57
mveRichard MacCutchan19-Mar-17 22:57 
GeneralRe: Crc 32 bit Pin
yagokhan19-Mar-17 22:59
yagokhan19-Mar-17 22:59 
GeneralRe: Crc 32 bit Pin
Richard MacCutchan19-Mar-17 23:19
mveRichard MacCutchan19-Mar-17 23:19 
GeneralRe: Crc 32 bit Pin
yagokhan19-Mar-17 23:22
yagokhan19-Mar-17 23:22 
GeneralRe: Crc 32 bit Pin
Jochen Arndt20-Mar-17 2:36
professionalJochen Arndt20-Mar-17 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.