tags:

views:

29

answers:

2

A standard enumeration in System.Windows.Forms:

[Flags]
public enum DragDropEffects
{
    Scroll = -2147483648,
    //
    // Summary:
    //     The combination of the System.Windows.DragDropEffects.Copy, System.Windows.Forms.DragDropEffects.Link,
    //     System.Windows.Forms.DragDropEffects.Move, and System.Windows.Forms.DragDropEffects.Scroll
    //     effects.
    All = -2147483645,
    None = 0,
    Copy = 1,
    Move = 2,
    Link = 4,
}

Quite a strange value for Scroll, don't you think?

As I understand these values all come from "the old times" of COM\OLE DROPEFFECT... But why were they chosen so in the first place? Did author try to reserve the interval between 8 and 0x80000000 for something? Is it usefule somehow or is there an interesting story behind it or it's just another long-lived illustration of the YAGNI principle?

A: 

Yes, it looks like an "interesting" hack of some sort. Common sense would suggest using 8, but maybe there's some Windows version related reason why 8 couldn't be used, and so the author used -2147483645 (-0x80000000) instead. It's not that unusual a number - whoever wrote it is just starting with a binary '1' from the high significant end rather than the low significant end.

Perhaps scrolling was regarded in some other group of drag/drop effects to copy/move/link, and so the author wanted to place it at the other end of the word, along with any other future similarly different effects.

Maybe there's some awful piece of logic somewhere to test to see if a DragDropEffects variable is greater than zero (intending to mean "anything that isn't none"), and Scroll should not fall in that range?

Bit of a mystery. At the very least you'd think they would put the constant in as hex, to show it's not just some totally random number.

NeilDurant
Whether it's shown in decimal or hex is a consequence of the decompiler options used, and tells you nothing about the original source code.
Ben Voigt
+1  A: 

It is a status flag, separate from the principal drop effects (Copy/Move/Link). Short from leaving room for future drop effects, picking the high bit allows a trick like checking if the value is negative. Same kind of idea as an HRESULT or the GetAsyncKeyState return value.

Hans Passant
What's that trick with the negative value and HRESULT? I don't think I remember that... =(
Yacoder
If it is less than zero then the call failed. That's what the FAILED(hr) macro does.
Hans Passant