|
hi...
am using windows mobile 6.0.
here in my application to show tha current date i used the following code
CString pDate, pDate2;
SYSTEMTIME ct;
CMonthCalCtrl m_MonthCal_1;
m_MonthCal_1.GetCurSel(&ct);
//int day = ct.GetDay();
m_MonthCal_1.GetToday(&ct);
pDate.Format(_T("%d/%d/%d"),ct.wDay,ct.wMonth,ct.wYear);
AfxMessageBox(pDate); // just for testing
but it not shows the current date.
what is the mistake in my code...
can u pls anyone tell the reason?
thank you...
paulraj
|
|
|
|
|
gnanapaul wrote: CMonthCalCtrl m_MonthCal_1;
Why are you creating a new instance of the control ?
How did you create the control in fact ? Did you use the resource editor ? If yes, then you first need to associate a variable to this control and use that variable to interact with the control.
|
|
|
|
|
Possibly you've first to initialize the control with current time, via SetToday method, for instance:
COleDateTime now = COleDateTime::GetCurrentTime();
m_MonthCal_1.SetToday(now);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks for ur guidance...
its working smartly. it shows the current date.
how to show the user selected date?
paulraj
modified on Monday, July 7, 2008 3:58 AM
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
gnanapaul wrote: how to show the user selected date?
GetCurSel method should do the job.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thank you once again for your kind guidence
paulraj
|
|
|
|
|
Hi
I'm having the following error message when compiling a project with VS2005
e:\projects\netsim\netsim\grafo.cpp(66) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Vector_const_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)
with
[
_Ty=Ligacao *,
_Alloc=std::allocator<Ligacao *>
]
c:\program files (x86)\microsoft visual studio 8\vc\include\vector(392): could be 'std::_Vector_iterator<_Ty,_Alloc> &std::_Vector_iterator<_Ty,_Alloc>::operator =(const std::_Vector_iterator<_Ty,_Alloc> &)'
with
[
_Ty=Ligacao *,
_Alloc=std::allocator<Ligacao *>
]
while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, std::_Vector_const_iterator<_Ty,_Alloc> )'
with
[
_Ty=Ligacao *,
_Alloc=std::allocator<Ligacao *>
]
The code is:
std::vector<Ligacao *>::iterator it;
for (it=this->_m_graf_map[_onde].begin() ; it != this->_m_graf_map[_onde].end() ; it++)
{
if (
((*it)->esquerda()->id() == _esq && (*it)->direita()->id() == _dir) ||
((*it)->esquerda()->id() == _dir && (*it)->direita()->id() == _esq)
) return true;
}
Where _m_graf_map is defined as:
std::vector<std::vector<Ligacao *> > _m_graf_map;
Does anybody know what am I doing wrong?
Fratelli
|
|
|
|
|
if _m_graf_map is like
std::vector<std::vector<Ligacao *> > _m_graf_map;
Then the iterator it should be defined like
std::vector<std::vector<Ligacao *> >::iterator it;
isnt it?
|
|
|
|
|
At first I tried it too, but I'm not actually iterating through _m_graf_map but _m_graf_map[_ond], which has type std::vector<Ligacao *>.
best regards
Fratelli
|
|
|
|
|
Hi,
I don't see it either, but you can try to split the code up to make it easier top spot it.
According to the error messages the iterator believes it should use the const iterator instead of the non-const version.
std::vector<ligacao> lstLigacao = this->_m_graf_map[_onde];
std::vector<ligacao>::iterator it;
for(it = lstLigacao.begin() ; it != lstLigacao.end() ; it++)
{
if (
((*it)->esquerda()->id() == _esq && (*it)->direita()->id() == _dir) ||
((*it)->esquerda()->id() == _dir && (*it)->direita()->id() == _esq)
) return true;
}</ligacao></ligacao>
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
That works! But I can't afford to copy an entire array like that =/
If that's the case, I rather use vector<>::size_type to iterate through the elements
But why does this happen? I mean, lstLigacao and _m_graf_map[_ond] have exactly the same type, right? So why does the iterator work with one, but not the other?
Best regards
Fratelli
|
|
|
|
|
Hi,
I have tried your code, and it works. I'm using VS2005.
But you don't need to copy the array, you could use a reference to it;
std::vector<Ligacao *>& refList = _m_graf_map[_ond];
and use the reference
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
I actually get another error =/
e:\projects\netsim\netsim\grafo.cpp(64) : error C2440: 'initializing' : cannot convert from 'const std::vector<_Ty>' to 'std::vector<_Ty> &'
with
[
_Ty=Ligacao *
]
Conversion loses qualifiers
The code is:
std::vector<ligacao> &ref = this->_m_graf_map[_onde];</ligacao>
Regards
Fratelli
|
|
|
|
|
Hi,
I think i got it.
The function where you use this list is probably defined as const.
Therefore all calls are made to the constant versions of the vector object.
Either change the function not to be const (not good) or use
const std::vector<ligacao*>& ref = lstTT[1];
for (std::vector<ligacao*>::const_iterator it = ref.begin(); it != ref.end(); ++it)
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
It works! You were right, the function is const.
Just two things I don't get, though:
1) Why does the iterator must be constant too?
2) Why do you say that making the function not const is not good? I'm asking this because I've seen different opinions in this matter. On one hand, they would argue that making a function const allows the compiler to optimize the function in several ways. On the other hand, I remember reading an article that said that "marking a function const is only a guarantee you're giving to the user that the method will not change the class's attributes" (nor its input, I think...). What do you think?
Regards
Fratelli
|
|
|
|
|
AndreFratelli wrote: 2) Why do you say that making the function not const is not good?
- When marking a member function as const. You're telling the user of the class that this call to will not change the internal data of the class. This is 'guaranteed'.
- You're alsoo telling the compiler to help you the writer too fulfill this design requirement. The compiler will modify for example a member int m_x; to const int m_x;
AndreFratelli wrote: 1) Why does the iterator must be constant too?
- The compiler has modified the constantness of this member, meaning that this member cannot be changed. Hence you need to use the const version of the iterator;
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
All clear now =D
Thanks a lot !
Best regards
Fratelli
|
|
|
|
|
Glad I could help
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
AndreFratelli wrote: std::vector<std::vector xmlns:std="#unknown"><ligacao> >
Just a suggestion!
Use a typedef to create type for this vector and will make things easier for you...
typedef std::vector<std::vector<Ligacao *> > LigacaoVector2d; Then create iterators like
LigacaoVector2d::iterator it;
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Yes, I usually do that.. But when dealing with arrays I also define an "iterator" type, like:
typedef std::vector<std::vector<Ligacao *> > LigacaoVector2d;
typeded LigacaoVector2d::iterator iterator;
That way, I can even do:
iterator it;
Thx anyway =)
best regards
Fratelli
|
|
|
|
|
AndreFratelli wrote: typeded LigacaoVector2d::iterator iterator;
It's better to use it directly so that readers of your code can understand from where this iterator is being used/to which vector this iterator belongs. Isn't it?
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
True =) but, on the other hand, if you have a class with the following definitions:
template <typename T> class MyClass
{
typedef vector<T> my_vector;
typedef my_vector::iterator iterator;
}; Then you/others can do something like:
int main()
{
MyClass<type>::iterator it;
return 0;
} Instead of:
int main()
{
MyClass<type>::my_vector::iterator it;
} Would you agree that it is practical?
regards
Fratelli
|
|
|
|
|
AndreFratelli wrote: Would you agree that it is practical?
Yeah, I thought you were letting the iterator typedef float around, if it's in a class then should be fine.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I'm writing a windows socket wrapper class in c++ from scratch and i cannot get events to work.
So inside the class i'll have several events.
let's pretend i have the following class:
class SocketTree
{
public:
int Close();
virtual void OnClose();
}
SocketTree::Close()
{
OnClose();
return 0;
}
And now i'll have the derived class that will receive the event:
class SckHandle : public SocketTree
{
public:
virtual void OnClose();
}
SckHandle::OnClose()
{
printf("working.");
}
And here's the main procedure:
int main()
{
SckHandle sHnd;
sHnd.Close();
return 0;
}
when sHand.Close() is executed, i wanted the event OnClose() to be fired, but it won't... anyone knows what is happening in here and what should i do to handle events correctly?
thank you 
|
|
|
|