|
Mark J. Miller wrote: Any recommendations for a good C website?
What's wrong with this one? If you are already familar with C++, then there's very little about C that will surprise you.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
May be we should ask Chris to rename the forum as C/C++/VC++
Jemmy : Deadline? Pfft, a real programmer eats deadlines for breakfast. :P
Mark: I thought real programmers ignored deadlines
Best wishes to Rexx[^]
|
|
|
|
|
As always I got what I needed. You guys at CP are the best.
|
|
|
|
|
You've got any questions with Assemblers?
Jemmy : Deadline? Pfft, a real programmer eats deadlines for breakfast. :P
Mark: I thought real programmers ignored deadlines
Best wishes to Rexx[^]
|
|
|
|
|
|
Is there a way to serialize an enumerated type using CArchive?
// I have an enumerated type in my header file and a member of that type,
typedef enum
{
ONE,
TWO,
THREE
} SomeType;
SomeType m_someVariable;
When I try to serialize it in the classes serialize method, I get...
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CSomething::SomeType' (or there is no acceptable conversion)
|
|
|
|
|
easiest way is to cast the enum to an int when saving, and cast the int to an enum when loading.
|
|
|
|
|
That's not working for me here. Are you on 6.0 or 2003.
I'm going to try this on a VC++ 6.0 project to see what happens as my current project is in VC++ 2003.
Thanks for the advice either way.
|
|
|
|
|
bob16972 wrote: Are you on 6.0 or 2003
doesn't matter. this is a pretty basic C++ issue, the kind of thing you run into everywhere.
int t;
ar >> t;
enumVal = (enumType)t;
ar << (int)enumVal;
|
|
|
|
|
My apologies.
I would never have suspected that was necessary but I live and learn.
Thank you very much for helping me over that hurdle.
|
|
|
|
|
Do you have something similar to:
class CSomething
{
public:
enum
{
ONE,
TWO,
THREE
} SomeType;
void Serialize( CArchive &ar )
{
if (ar.IsStoring())
ar << (int) SomeType;
else
ar >> (int) SomeType;
}
};
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That's basically it. I needed a typedef in front of the enum. I've tried a couple variations which should effectively be the same thing in the end but none get me past the error.
I tried the cast operation an it didn't change the error.
I'm not sure if this matters, but I've noticed from past posts you use VC++ 6.0 exclusively and this project is on Visual C++ 2003, so if that's working for you in your environment, I'll give it try in a Visual C++ 6.0 project to see if the 2003 compiler just changed the rules.
|
|
|
|
|
bob16972 wrote: ...if that's working for you in your environment, I'll give it try in a Visual C++ 6.0 project...
You might have to tweak it a bit like:
if (ar.IsStoring())
{
int x = SomeType;
ar << x;
}
else
{
int x;
ar >> x;
SomeType = (_SomeType) x;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I feel silly now but a tad bit smarter.
Thanks for helping me out. I learned something new.
|
|
|
|
|
Why have you written the underscore in the casting by loading???
I mean: SomeType = (_SomeType) x;
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: Why have you written the underscore in the casting by loading???
To differentiate between a type and a value.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi,
Is there a possibility to get the previous item selection in a LVN_ONITEMCHANGING handler.
The handler provides the item that is about to change from unselected to selected, but I can not
find a way to get the item that loses the selection.
void CMPRSDlg::OnItemChangingMPRSLst(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_LISTVIEW *pNMListView = (NM_LISTVIEW *) pNMHDR;
*pResult = 0;
// TODO : Add your control notification handler code here.
if (pNMListView->uChanged & LVIF_STATE)
{
int nItem = pNMListView->iItem;
// An item's state is about to change.
if (!(pNMListView->uOldState & LVIS_SELECTED) && (pNMListView->uNewState & LVIS_SELECTED))
{
// Item will go from unselected to selected.
ASSERT(::IsWindow(m_ctlMPRSLst.m_hWnd));
POSITION pos = m_ctlMPRSLst.GetFirstSelectedItemPosition();
/// THIS DOES NOT WORK. pos = NULL ???? Is there another way ?
:
:
// Prevent selection if the item is locked.
CMPRSEntry *pEntry = (CMPRSEntry *) m_ctlMPRSLst.GetItemData(nItem);
if (pEntry->m_SKU.IsLocked())
{
*pResult = 1;
return;
}
}
}
}
|
|
|
|
|
If the number of items is not very big and the time is not critical you can deal with it using a help-array.
I mean:
void CMPRSDlg::OnItemChangingMPRSLst(NMHDR *pNMHDR, LRESULT *pResult)
{
for (int i = 0; i < number_of_items; i++)
{
if (Help_array[i] == 1)
{
last_item = i;
Help_array[i] = 0;
break;
}
last_item = -1;
}
Help_array[index_of_changing_item] = 1;
}
Where Help_Array has zero in ALL positions at the beggining.
Hope it helps.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
You can always store the HITEM of the currently selected item, which will be
the last selected item when a new item is selected.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, but where to I have to do this.
I want to achieve the following :
I want to prevent that in a multiselection CListCtrl some items which have a particular
flag set bound to the item with SetItemData() are getting selected. But selection can occur in many different ways. Through a mouseclick, through the keyboard interface and particular with the Ctrl and Shift keys. I can not find a place to do the saving which handles all these cases.
tia
|
|
|
|
|
I'm not understanding what you want to do.
Do you want to prevent items from being selected?
You get a notification when the state of an item is about to change, which you can prevent.
You also get a notification when an item's state is changed.
You can use LVM_GETSELECTEDCOUNT and LVM_GETNEXTITEM to enumerate the selected items.
Can you implement the logic you want using these?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I want to prevent multiple items from being selected by skipping the unwanted ones and
setting the selection back to the first item which is wanted( without flag), depending on the direction of the selection.
|
|
|
|
|
paper67 wrote: I want to prevent multiple items from being selected
Always or sometimes?
If always, then the LVS_SINGLESEL style should be used for the control.
If sometimes, the control isn't going to keep track of this for you AFAIK.
Depending on the complexity of the logic involved, you may need to handle
item selection yourself, overriding the control's default behavior.
Default List-View Message Processing[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Don't you like my first answer? or is not what you need? Is a bypass and may take a bit of time in performance, but it can work.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|