|
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_
|
|
|
|
|
Hi,
Try to think of something that interests you and that you could write some software to help you with. For instance if you likes music then a database of your music collection or it you liked travel you could write a currency convertor. With a little imagination you can make these simple projects as complex as you need for a starter project.
If you simply cannot think of anything relating to you personally, then write a simple game such as 'Noughts and Crosses'.
Hope I've sparked a few ideas, good luck with your studies,
Ali
|
|
|
|
|
|
As a beginer, you can make simple console based Point of Sale system. Other options are Student Registration System, Library management system etc.
You can make them either console based or using MFC.
Good luck
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
subikchya wrote: What are the general as well as simple projects for a beginer like me to work?
The project which prints "Hello world!" on the screen!
Maxwell Chen
|
|
|
|
|
First my program and very nice but its not good for project
|
|
|
|
|
WhiteSky wrote: First my program and very nice but its not good for project
Every newbie has to experience the pleasure of "Hello world".
Maxwell Chen
|
|
|
|
|
I am new to VC++ and MFC and not very much strong on it... I am having this problem.
I have a dialog application which contains a ListView control. I want to have the column names in Urdu. so here what I do.
TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;
As my Dialog class, UrduAppDlg contains the ListView contorl, what I do is that place the above mentioned defination of Unicode string in UrduAppDlg.h file before the clas defination... Right? So far so good... But when I build the solution, I get the following error
UrduTextAnalyzer error LNK2005: "wchar_t * szCol7" (?szCol7@@3PA_WA) already defined in UrduTextAnalyzer.obj
But placing the same defination in UrduTextDlg.cpp does not create any problems and I get my job done... Please tell me what this phenomen is and why? Where should I put such data like col names? I cannot use resource compiler I think becuase Its not Unicode compatible I think... Please guide me in this regard.
Mohsin
Polite Programmer
More Object Oriented then C#
|
|
|
|
|
I guess you have accidently included the .cpp file instead of the .h file or you have forgotten to add #pragma once to the top of the .h file.
Nibu thomas
Software Developer
Faqs by Michael dunn
|
|
|
|
|
I think the reason is that szCol7 is defined in a header that is included in multiple .CPP files and thus defined multiple times. Use something like this instead:
TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;
extern TCHAR szCol7[];
You include the header file into and .CPP file from which you want to access szCol7 .
Steve
|
|
|
|
|
yes i agree with Nibu thomas i guess you have forgotten #pragma once in header file
or change location szCol7 from header file
|
|
|
|