|
i need to sort an object of type std::list
i have something like this:
(.h)
struct _Selected
{
_decimal ent;
_decimal docNum;
}Selected;
typedef list<_Selected, allocator<_Selected> > LISTSTR;
LISTSTR arrSelected;
and i need to sort 'arrSelected'
how can i do this?
thanks
Nuno Henrique Mendes
|
|
|
|
|
NHM wrote:
and i need to sort 'arrSelected'
how can i do this?
std::sort? Did you even *read* the documentation before asking?
|
|
|
|
|
Mike Nordell wrote:
std::sort? Did you even *read* the documentation before asking?
Ehm.
Documentation[^] states that you need a Random access iterator[^] to use std::sort, and std::list::iterator is a Bidirectional iterator[^]
Anyway, his problem is that he has no < operator defined for his struct, which is easy enough to fix. Then he can use std::list::sort
|
|
|
|
|
Mike Nordell wrote:
std::sort? Did you even *read* the documentation before asking?
Nemanja Trifunovic pitched in:
Ehm.
Documentation states that you need a Random access iterator to use std::sort ...
*slap* (that was the sound of one hand clapping). OK, I'm a moron. I stand corrected and bow my head in shame.
|
|
|
|
|
Hi,
I try to use the DumpElements function to dump specific information from a CMap. If I define the Dump function has follow:
template <> void AFXAPI DumpElements<cstring> (CDumpContext& dc, const CString* pElements, INT_PTR nCount)
{
… do something
}
I get a linker error (LNK2005) that this function is already defined in a other obj. The only thing defined in this obj is a other CMap of CStrig.
Is there any sample available on you to properly use this function?
Thank you
Sascha Schantz
|
|
|
|
|
Hi,
I'm overriding PreTranslateMessage() for my CView-derived class because I want to detect when the user presses ctrl-z (undo). I know that pMsg->wParam has the key code, but how can I check if the ctrl key is also pressed? On a sidenote, why can't I get ctrl-z in the OnKeyDown() of a CView? I already removed ctrl-z from my accelerator table but I still cannot get ctrl-z to show up in OnKeyDown(). Thanks for all hints!
cheers,
roel
|
|
|
|
|
You do not have to use PreTranslateMessage for this. You can your view's OnKeyDown message handler. Use GetKeyState(VK_CONTROL) to check the status of the control keys.
if ((nChar == 'z' || nChar == 'Z') && GetKeyState(VK_CONTROL) & 0x80))
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Myself I'd use an accellerator for CTRL+Z that mapped to UNDO.
|
|
|
|
|
Mike Nordell wrote:
Myself I'd use an accellerator for CTRL+Z that mapped to UNDO.
I would to, but roel said he(she?) removed the accelerator. He must have done that for a reason?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
'He', thank you very much
I did it because the CView is in a library that I'd like to keep as separate as possible from the application it is going to be used in.
Anyway, the problem turned out to be that I tried to use nFlags in OnKeyDown to determine the state of the Ctrl key - for some reason I thought that nFlags & VK_CONTROL was supposed to give me the state. GetKeyState() was the solution! Thanks to both of you.
cheers,
roel
|
|
|
|
|
I try to place a file into the clipboard so I can later paste them in Explorer. I can place text, bitmap etc, but how can I place a file into the clipboard?
Thanks
|
|
|
|
|
Perhaps you should examine what the clipboard contains after you select "Copy" on a file from the explorer? Preferrably before asking.
|
|
|
|
|
I am trying to optimize the inner loop of an interpreter, and looking at the generated machine code I notice that the compiler always writes a local variable back to the stack frame after it has been modified, even though the variable is held in the same register throughout the entire loop & its lifetime. Sometimes it randomly loads it from the stack as well, even though it was already in the same register just before, and no control flow is present in between.
The variable is not static/volatile, is not aliased (its address is never taken), and its register is never used for other purposes in the generated code. I have all optimisations on max and even have /Oa on. Using vs.net.
How do I stop the superfluous flushing/loading from happening?
|
|
|
|
|
You could use the register keyword, but I'm not sure if the compiler honours that any more. If you optimise for speed, it should use only the register anyway.
Use the /Oe option to optimise register-allocation, and the compiler should be able to sort this out.
If neither of these work, either you can write the algorithm in assembly, use a different compiler, or just accept it
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
You could use the register keyword,
Or you could read the documentation that states the register keyword is disregarded. The choice is yours, but knowing this compiler I think you'd be wrong to not trust the documentation.
|
|
|
|
|
Did you only read the first half of the sentence? Just wondering...
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
The register keyword is indeed useless.
/Oe doesn't help either, the optimisation I am looking at is all inside a single function (a local variable).
I don't want to write it in assembly, it has to be portable across a great many architectures, of which x86 happens to be the most important one. I am just attempting to write C++ that doesn't stop msvc from making important optimisations.
|
|
|
|
|
Aardappel wrote:
How do I stop the superfluous flushing/loading from happening?
You don't.
No, really. When the compiler wants one thing and you want another, the compiler *always* wins - I've been in this position too when it allocated regs like a drunk. I had to rewrite my code, using C++ and especially inlined templated functions (no matter how insane it seems, the basically 4 registers the compiler selects from had a profound difference) to get it to allocate and (not) flush regs where (not) needed.
Basically, when the compiler screws you, you have no voice - accept or rewrite.
One *can* of course fall back to ASM, but it suck when one have payed $$$ for an "optimizing" compiler that M$ had over a decade to "optimize", doesn't it. (btw, try to use the "intrinsic" versions of e.g. str* and mem* and you know what MS "quality" is...)
|
|
|
|
|
Yup, I am very much aware of this. But when it comes to optimisations, you can often help it by writing your code in a certain way. For example, if I had written &var of the variable somewhere, I would understand that it flushes the var everywhere: it can be accessed by an alias after all. But in my case, I never do anything like this. So I want to find out what code exactly confuses the compiler.
Would be good if the compiler had optimisation warnings
|
|
|
|
|
whoops, that was my reply, not Anonymous. I should get an account.
|
|
|
|
|
All my icons that are associated with a program look
so boring and plain. What really drives me nuts though
is that the icon in the upper left corner of the program
in Windows 98 or 2000 look okay, but the same program on
XP and the icon looks blurry.
How can I take a nice looking bitmap and make that into
a icon, rather than using that little 32x32 box that
Visual C++ forces the developer to create icons with?
There has to be a way since everyone else has a nice
looking icon associated with their software.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
Use any icon creation programs like
Axialis Ax-Icons
Awicons
MicroAngelo
Awicons is my favorite.
Sorry all are shareware. But 30 days is enough for creating an icon.
Hari Krishnan
|
|
|
|
|
DanYELL wrote:
How can I take a nice looking bitmap and make that into
a icon, rather than using that little 32x32 box that
Visual C++ forces the developer to create icons with?
Perhaps by reading up on, and downloading code for, high quality scaling? Google is your friend.
Give a man his food and he'll be back tomorrow for more. Teach him how to fish and he's self-sustained.
|
|
|
|
|
I need to make program, that will open given video file in any
format for which the system has installed codec.
All I need to do is getting the movie length in seconds.
How to do this in most simple way ?
I don't know anything about direct show, and I won't study
whole the thing because I don't need more than getting
movie length.
Does anyone have piece of code for this, or idea where to
start ?
Thank you
rrrado
|
|
|
|
|
Hi There!
Probably the best (quickest) way to do this is using the IMediaDet interface in DirectShow.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/htm/usingthemediadetector.asp
This article talks about retrieving all sorts of information from a media file - assuming that the codec is installed on the machine we should be able to work out the stream time. Perhaps someone else has some code which will do this straight away for you.
Good Luck!
|
|
|
|