Prev: Combine list view with a tab ctrl
Next: CWnd derived parent, owner draw reflection does not work
From: RB on 18 Feb 2010 11:46 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 18 Feb 2010 13:15 "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 18 Feb 2010 17:57 > 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 18 Feb 2010 19:27 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 18 Feb 2010 20:19 "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>
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Combine list view with a tab ctrl Next: CWnd derived parent, owner draw reflection does not work |