www.digitalmars.com         C & C++   DMDScript  

D - A little trick

reply Patrick Down <pat codemoon.com> writes:
Here's a little trick I've used when building
a module for various windows functions that
aren't in Walter's windows.d yet.  A number 
of structures in the windows API require the 
first member to be a UINT with the structure 
size in it.  Which can be initialized in the
structure definition like this.

struct MENUITEMINFO
{
  UINT cbSize = MENUITEMINFO.size;
  UINT fMask;
  UINT fType;
  UINT fState;
  UINT wID;
  HMENU hSubMenu;
  HBITMAP hbmpChecked;
  HBITMAP hbmpUnchecked;
  DWORD dwItemData;
  LPTSTR dwTypeData;
  UINT cch;
  HBITMAP hbmpItem; 
}

Ok, it's not much of a trick, but simple
things make me happy. :-)
Aug 22 2002
next sibling parent Pavel Minayev <evilone omen.ru> writes:
On Fri, 23 Aug 2002 03:20:24 +0000 (UTC) Patrick Down <pat codemoon.com> wrote:

 
 Here's a little trick I've used when building
 a module for various windows functions that
 aren't in Walter's windows.d yet.  A number 
 of structures in the windows API require the 
 first member to be a UINT with the structure 
 size in it.  Which can be initialized in the
 structure definition like this.
A neat one! Never really thought of the fact that struct members can be initialized... It is also interesting that it can determine size of the struct before it had even been declared.
Aug 22 2002
prev sibling parent "Walter" <walter digitalmars.com> writes:
I love it when neat things like this are discovered!
Aug 24 2002