From: RB on
Hello, I am a non professional programmer that writes stuff for my work as a
Civil Engineering Cad drafter. So please excuse inexperience. My question is,
I'm currently working with a struct that has an unsigned int declared in the
WINUSER.H file as
typedef struct tagDRAWITEMSTRUCT {
UINT CtlType;
UINT CtlID;
UINT itemID; //<- this guy here
UINT itemAction;
UINT itemState;
HWND hwndItem;
HDC hDC;
RECT rcItem;
DWORD itemData;
} DRAWITEMSTRUCT;

But in the docs for this structure it is said that for an empty list box this member is
a negative value How can an unsigned int (UINT ) be a negative value ???
Shouldn't this be declared as an int ?


From: Giovanni Dicanio on
"RB" <NoMail(a)NoSpam> ha scritto nel messaggio
news:uGA3$nLsKHA.4652(a)TK2MSFTNGP02.phx.gbl...

> typedef struct tagDRAWITEMSTRUCT {
> UINT CtlType;
> UINT CtlID;
> UINT itemID; //<- this guy here

> But in the docs for this structure it is said that for an empty list box
> this member is
> a negative value How can an unsigned int (UINT ) be a negative value
> ???

Here:

http://msdn.microsoft.com/en-us/library/bb775802(VS.85).aspx

it reads:

"For an empty list box or combo box, this member can be -1."

Probably "-1" in the above sentence is a shortcut for 0xFFFFFFFF (i.e. all
the bits in the 32-bit "slot" of data member 'itemID' are set).

Giovanni


From: David Scambler on

> UINT itemID; //<- this guy here

As Giovanni said -1 presumably means all bits on.

It is horrible to have to code like this, but valid constructs include:

itemID = (UINT)-1;
if (itemID == (UINT)-1) ...
if ((int)itemID == -1) ...

etc.

But this will definitely not work:

if (itemID < 0) ...

dave


From: RB on

ugh well yes I gather the bit thing as I'm aware the sign bit, and the msdn link
he gave me was the same as my VC helps files which I was quoting from to start with.
My question was "why is the struct written that way?" I.e. if it was designed to
sometimes hold a negative value....Why didn't they just make it an int ?

---------previous message-------------------------
"David Scambler" <aa(a)aa> wrote in message news:Xns9D246547E2FDCDavidScambler(a)203.50.5.233...
>
>> UINT itemID; //<- this guy here
>
> As Giovanni said -1 presumably means all bits on.
>
> It is horrible to have to code like this, but valid constructs include:
>
> itemID = (UINT)-1;
> if (itemID == (UINT)-1) ...
> if ((int)itemID == -1) ...
>
> etc.
>
> But this will definitely not work:
>
> if (itemID < 0) ...
>
> dave
>
>


From: David Scambler on
"RB" <NoMail(a)NoSpam> wrote in
news:OdTxapPsKHA.1352(a)TK2MSFTNGP06.phx.gbl:

>
> ugh well yes I gather the bit thing as I'm aware the sign bit, and the
> msdn link he gave me was the same as my VC helps files which I was
> quoting from to start with. My question was "why is the struct written
> that way?" I.e. if it was designed to sometimes hold a negative
> value....Why didn't they just make it an int ?
>

It is probably futile to speculate what they were thinking. But here goes
anyway...

<speculation>

Valid itemIDs are indeed unsigned but they wanted to overload the field
with a reserved "undefined" flag. I guess it is just sloppy documentation
and/or imprecise specification. They could have defined a specific macro
for ((UINT)-1) then "-1" would not have been mentioned. Defining the field
as int would be inappropriate for the primary purpose of the field, namely
to use it as a control index.

</speculation>