|
If you used Write() to write the integer and then used something like Notepad to view the file, it will indeed not look like you'd expect. This is a difference between "binary" and "text" files.
Try something like:
CString s;
s.Format(_T("%d\n"), m_nCon);
file.WriteString(s);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
It worked!!I didn't know the difference! Thank you very much for your answer and the explication!!
|
|
|
|
|
To write list control records into text file use structure
you can write and read entire row of list control.
it will be better to seek the file pointer while reading and writing
|
|
|
|
|
Hi i created a Combobox Button in toolbar. It working fine in my machine. But when i testing it on other machines not all but some with win 10 and 7. It case to stop running application.
ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset)
LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM)
{
UINT uiToolBarId = (UINT)wp;
switch (uiToolBarId)
{
case IDR_MAINFRAME:
case IDR_MAINFRAME_256:
{
CMFCToolBarComboBoxButton comboButton(ID_COMBO, GetCmdMgr()->GetCmdImage(ID_COMBO, FALSE), CBS_DROPDOWNLIST);
comboButton.AddItem(_T("opt 1"));
comboButton.AddItem(_T("opt 2"));
comboButton.AddItem(_T("opt 3"));
comboButton.SelectItem(0);
m_wndToolBar.ReplaceButton(ID_COMBO, comboButton);
}
break;
}
return 0;
}
Im out of ideas How to make it working.
modified 24-Mar-17 9:49am.
|
|
|
|
|
vojtee wrote: How to make it working. The first thing you need to do is to find out why it is "not working", and explain exactly what "not working" means. Without that information it is impossible to help.
|
|
|
|
|
I cant describe it better than not working .
So i have 2 application. In first app that code is included and in second app that code is not included. First application don't work on some machines but on thers works fine.
Windows do not generate any error. It just start and close immediately.
Second app working fine everywhere.
|
|
|
|
|
Well I am sorry but it is impossible to guess what your code is doing. You have the source code so you need to add some debugging to your program to find out where it is going wrong.
|
|
|
|
|
Put some traces inside your code, so you can know what is going wrong at some PC.
|
|
|
|
|
Hello everyone,
I have created an editable list control (report style) with numbers. How could I save all content of list in a text file, each edited "number" below the other. I tried something like this:
void CDataDialog::OnOK()
{
CWnd* pwndCtrl = GetFocus();
int ctrl_ID = pwndCtrl->GetDlgCtrlID();
CString str;
ofstream outFile;
outFile.open("sample.txt");
switch (ctrl_ID)
{
case IDC_EDIT1:
GetDlgItemText(IDC_EDIT1, str);
for (int i = 1; i <= m_nCon; i++)
{
outFile << str <<endl;
outFile << m_nCon << endl;
}
outFile.close();
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;
}
}
but by this way I can save only the last edited item in text file. Thank you in advance!!
|
|
|
|
|
Something like:
CStdioFile file("sample.txt", CFile::modeCreate);
int nCount = listControl.GetItemCount();
for (int x = 0; x < nCount; x++)
{
CString strText = listControl.GetItemText(x, 0);
file.WriteString(strText);
}
file.Close();
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I wrote this:
void CDataDialog::OnBnClickedOk()
{
CStdioFile file("over1.txt", CFile::modeCreate);
int nCount = m_List.GetItemCount();
for (int x = 0; x < nCount; x++)
{
CString strText = m_List.GetItemText(x, 0);
file.WriteString(strText);
}
file.Close();
}
and when execute it I get this statement: "Debug assertion failed". Is this because I already use CString CDataDialog::GetItemText(HWND hWnd, int nItem, int nSubItem) const??? Sorry I didn't mention it in the first post.
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;
}
|
|
|
|
|
lolici wrote: ...and when execute it I get this statement: "Debug assertion failed". You'll need to step through the code using the debugger to find the line that is asserting.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
The problem is here:
int nCount = m_List.GetItemCount();
I need another function than GetItemCount?
|
|
|
|
|
That line is NOT asserting. You need to step into the GetItemCount() method (until you find an ASSERT() macro).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
lolici wrote: I wrote this:
void CDataDialog::OnBnClickedOk()
{
CStdioFile file("over1.txt", CFile::modeCreate);
<pre>
<span class="code-keyword">int</span> nCount = m_List.GetItemCount();</pre></blockquote>
What is m_List? Where and how is it defiled/initialized?
lolici wrote: 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;
}
Why do you iplement your own function rather than use CListCtrl::GetItemText (MFC) method?
|
|
|
|
|
m_list is the control variable I declared about list control. I used CListCtrl::GetItemText (MFC)
but didn't work either :/
|
|
|
|
|
Then please show your code how this variable was attached to the list control: did you use MFC DDX_... mechanism or something else?
|
|
|
|
|
Here it is :
public: CListCtrl m_List;
void CDataDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_List);
}
I could also upload the project or the executable if it is possible.
|
|
|
|
|
lolici wrote: I could also upload the project or the executable if it is possible.
Please, read the rules about asking the question here to know whether it is possible.
|
|
|
|
|
# define blHeadTable ((V_ROM1_FAR tblHead V_ROM2_FAR V_ROM3 *)(BL_HEAD_ADDRESS))
# define GetblDID1() (blHeadTable->DID[1])
I am a little confused in the first macro declaration.
Appreciate any explanation.
|
|
|
|
|
Basically it casts the fixed address BL_HEAD_ADDRESS as a pointer to some type:
# define someTypeAddr ((someType *)(BL_HEAD_ADDRESS))
In your case the type is V_ROM1_FAR tblHead V_ROM2_FAR V_ROM3 .
Assuming that V_ROM1_FAR and V_ROM2_FAR are something like far * , the type is a pointer in V_ROM3 that points to a tblHead pointer.
Effectively it will assign a pointer to a tblHead structure at a fixed address.
|
|
|
|
|
I understand it's like:
# define someTypeAddr ((someType *)(BL_HEAD_ADDRESS))
But the type:
V_ROM1_FAR tblHead V_ROM2_FAR V_ROM3
I am still a little confused with it.
int a Char short, is that similar?
Thanks
|
|
|
|
|
You have to lookup first how V_ROM1_FAR and V_ROM2_FAR are defined.
Then it will be something like
far * tblHead far * V_ROM3 far is a compiler and platform specific keyword. See Far pointer - Wikipedia[^].
See also Cx51 User's Guide: Abstract Pointers[^] (I did not found a better link that explains such castings).
|
|
|
|
|
Thanks, I understand it.
Looked into V_ROM2_FAR V_ROM3, V_ROM2_FAR be defined as const, V_ROM3 blank
|
|
|
|
|
i hv problem in using basic rules of dev c
|
|
|
|