|
what's mean
"An attempt was made to access an unnamed file past its end
CFile file;
if(!file.Open(_T("persons.dat"),CFile::modeRead)){
AfxMessageBox(_T("Unable to open the file"));
exit(-1);
}
CArchive arr(&file,CArchive::load);
m_obDebtors.Serialize(arr);
arr.Close();
file.Close();
|
|
|
|
|
what's mean
"An attempt was made to access an unnamed file past its end
CFile file;
if(!file.Open(_T("persons.dat"),CFile::modeRead)){
AfxMessageBox(_T("Unable to open the file"));
exit(-1);
}
CArchive arr(&file,CArchive::load);
m_obDebtors.Serialize(arr);
arr.Close();
file.Close();
|
|
|
|
|
what's mean
"An attempt was made to access an unnamed file past its end
CFile file;
if(!file.Open(_T("persons.dat"),CFile::modeRead)){
AfxMessageBox(_T("Unable to open the file"));
exit(-1);
}
CArchive arr(&file,CArchive::load);
m_obDebtors.Serialize(arr);
arr.Close();
file.Close();
|
|
|
|
|
NoName II wrote: "An attempt was made to access an unnamed file past its end
I never heard about this error. It's perhaps because you try to load more objects than the file contains. So, you try to read after the end of the file. Can you confirm that your load and save parts serialize exactly the same objects in the same order ?
|
|
|
|
|
Hi,
would you please give a hand?
how to create a batch of button(more than 200) in the code?
use the array?
And then mapping the messages to one function onButtonClick()?
void onButtonClick(){
....// differentiate the buttons?
....//
}
..
-- modified at 3:12 Wednesday 10th May, 2006
|
|
|
|
|
Store these buttons inside a CTypedPtrMap or CTypedPtrList based on your requirements. Map requires key value pairs. For key you can use the Id of the button.
Override OnCommand to dynamically handle messages from these buttons instead of providing message map entries.
Nibu thomas
Software Developer
Faqs by Michael dunn
|
|
|
|
|
thank you for your kindness.
I'm afraid I don't know the way of "Store these buttons inside a CTypedPtrMap or CTypedPtrList based on your requirements. Map requires key value pairs. For key you can use the Id of the button."
would you show me the simple code?
and another base-question is dynamically creating button:
I wrote the (a) and (b) in function OnInitDialog()
(a)
CButton btn;
btn.Create("Hi,World",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20,80,40),this,104);
(b)
CButton *btn = new CButton;
btn->Create("Hi,World",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20,80,40),this,104);
it seems that the (a) can't work, but (b) is ok.
is there any different using pointer or not?
|
|
|
|
|
zeus_master wrote: it seems that the (a) can't work, but (b) is ok.
is there any different using pointer or not?
Yes, in your case: you are probably declaring the CButton inside the OnInitDialog function, so its scope is limited to the function. Once the function is finished, the CButton destructor will be called, thus removing the button from the dialog. You won't have the problem if it's a member variable of the class.
To store the buttons, you can also simply store them in a vector or list. Don't forget to change the ID of each button also (and be sure the range of ID's you are using is 'reserved' in the resource.h file, otherwise, some other controls could take the same id and you will be in troubles).
|
|
|
|
|
thank you again for your timely teaching.
I wrote it like this, but it was faild:
CButton * btn[5];// = new 5 CButton
int i =1;
CString str;
for (i=0;i<5;i++) {
str.Format("%0x",i); // for set button caption
btn[i]->Create(str,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20+30*i,80,40+30*i),this,104+i);
}
|
|
|
|
|
Try to use vector or list from the STL instead. In your class, delcare a member variable (don't forget to include vector):
#include <vector>
CMyClass
{
private:
std::vector<CButton> m_MyButtons;
};
Then in OnInitDialog (or where you create the buttons):
std::vector<CButton>:iterator iter = m_MyButtons.begin()
for(iter; iter!=m_MyButtons.end();iter++)
{
(*iter).Create(str,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20+30*i,80,40+30*i),this,104+i);
}
I didn't test the code so there are perhaps some errors.
I strongly suggest you read some tutorials on the use of containers of the STL (list, vectors, ...). They are VERY usefull and much more safer than dynamic arrays. There is some tutorials on this website.
|
|
|
|
|
is it std::vector<cbutton>::iterator?
how to initialize m_MyButtons?
std::vector<cbutton> m_MyButtons(0,5);?
I think my stupid project/question have made you crazy,sorry again.
|
|
|
|
|
zeus_master wrote: is it std::vector::iterator?
Yes sorry, it was a typo. (I suppose the < and > were removed in your post because you didn't check the 'Ignore HTML tags' check box).
zeus_master wrote: how to initialize m_MyButtons?
You don't initialize them. The constructor of the class is called and after that, you just need to call Create for all the button (see the code I posted).
|
|
|
|
|
Ooops, sorry, I just realized there is something missing in the code: buttons are never added in the vector (so basically what you have now is an empty vetor, not very usefull isn't ?).
So, to do that remove the code with the iterator and replace everything by this:
for (int i=0;i<10;i++)
{
CButton NewButton;
NewButton.Create(str,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20+30*i,80,40+30*i),this,104+i);
m_MyButtons.push_back(NewButton);
}
So, this will create 10 buttons and add them to the vector. Then, afterwards, if you need to access the buttons again, you can use the code I previously posted (with the iterator): it is used to retrieve data from the vector.
Hope this help, sorry to have forgotten that
|
|
|
|
|
I met compiler error below:
c:\program files\microsoft visual studio\vc98\include\xutility(39) : error C2582: 'CButton' : 'operator =' function is unavailable
c:\program files\microsoft visual studio\vc98\include\vector(170) : see reference to function template instantiation 'void __cdecl std::fill(class CButton *,class CButton *,const class CButton &)' being compiled
c:\program files\microsoft visual studio\vc98\include\xutility(25) : error C2582: 'CButton' : 'operator =' function is unavailable
c:\program files\microsoft visual studio\vc98\include\vector(174) : see reference to function template instantiation 'class CButton *__cdecl std::copy_backward(class CButton *,class CButton *,class CButton *)' being compiled
c:\program files\microsoft visual studio\vc98\include\xmemory(34) : error C2558: class 'CButton' : no copy constructor available
c:\program files\microsoft visual studio\vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CButton *,const class CButton &)' being compiled
Error executing cl.exe.
|
|
|
|
|
Operator = ?? What are you doing with this operator ?
Can you post the code ?
|
|
|
|
|
I didn't do anything.
I just creat a new dialog based project named stl.
and according your mean,add the code in the place your said:
stldlg.h
<code>// stlDlg.h : header file
//
#if !defined(AFX_STLDLG_H__0E3FD69C_3BD2_48E1_B6A9_3C850CD124FA__INCLUDED_)
#define AFX_STLDLG_H__0E3FD69C_3BD2_48E1_B6A9_3C850CD124FA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
/////////////////////////////////////////////////////////////////////////////
// CStlDlg dialog
class CStlDlg : public CDialog
{
// Construction
public:
CStlDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CStlDlg)
enum { IDD = IDD_STL_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CStlDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
private:
std::vector<CButton> m_MyButtons;
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CStlDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STLDLG_H__0E3FD69C_3BD2_48E1_B6A9_3C850CD124FA__INCLUDED_)
</code>
then add the initialization in BOOL CStlDlg::OnInitDialog()
<code>
// TODO: Add extra initialization here
CString str="stlbtn";
for (int i=0;i<10;i++)
{
CButton NewButton;
NewButton.Create(str,WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,20+30*i,80,40+30*i),this,104+i);
m_MyButtons.push_back(NewButton);
}
</code>
|
|
|
|
|
Ok, then it is because the CButton class doesn't allow 'copying' itself (needed to be stored in the vector).
Then, we can go the 'old way' : just use a plain C array:
CButton* m_pButtons;
And in the constructor:
m_pButtons = NULL;
In the destructor:
if (m_pButtons)
{
delete[] m_pButtons;
m_pButtons = NULL;
}
In OnInitDialog:
m_pButtons = new CButton(10);
for (int i=0;i<10;i++)
m_pButtons[i].Create(.....);
Sorry for the time lost
|
|
|
|
|
You can create dynamically the button (I mean, not through the resource editor but by calling the Create member function). Then, you can use the ON_COMMAND_RANGE[^] macro to specify a range of ID. Don't forget to 'reserve' this range in resource.h.
|
|
|
|
|
wow, It's really a wouldful method!
thany very much.
|
|
|
|
|
i m just a beginer in c++ language and my teacher has asked me to think about a project to work on it.What are the general as well as simple projects for a beginer like me to work?can u please suggest some??
|
|
|
|
|
What are u doing ?? which degree ?? & yr intrest ???
|
|
|
|
|
homework!?
Can you be more specific
you need to one project that work on it?
well what problem? you should select one subject and work on it and if you have problems then we can help to you
you said one suggestion but what? easy hard
|
|
|
|
|
i just need a simple project especially related to medical science.Due to lack of basic knowledge on c++ nothing is striking my help.
I would be thankful if u suggest some.
|
|
|
|
|
I suggest that you can see LSA i think its good
whitesky
|
|
|
|
|
Talking in a general layman's term a simple application could be to develop an application that is based on MFC.
The application can have 4-5 odd dialogs and controls like list box , listcontrols, edit boxes etc. If you want to have a database like support use the database api's to connect to MS-Access or whatever you choose. You can also go for using file handling if you have limited amount of data.
Using the above functionality you can develop a project related to management of some organization etc.
And if you want to develop advanced applications try using ATL, COM etc and the rest is upto what extent you can put you efforts in and how quickly you pick up the facts related to these technologies.
IF you want to create graphical applications like a speedometer etc you can use directx or openGL
_AnShUmAn_
|
|
|
|