Results 1 to 3 of 3

Thread: Please look at this confusing code!

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Please look at this confusing code!

    I wrote a program (not my own code) which displays some properties of my window and some other stuff. I am learning window API from a book and this is one of the examples given in that book but if you look at following code(it is a header file), it dont even uderstand a word about it.
    I am confused with the array which is made, the multiplication signs, all the other strings and variables which are lined up, and the NUMLINES variable
    (please download this file and then look at the source code)

    If are a good and wise programmer then can you please explain what all that stuff is and what does it do?

    Please download the attachment and review the source and header file


    This is just a messed up version of my header file which i am not understanding!

    Code:
    /*----------------------------------------------------------------
    			SYSTEMS>H - System metrics display structure
    -----------------------------------------------------------------*/
    
    #define NUMLINES (int)(sizeof sysmetrics / sizeof sysmetrics [0])
    
    struct
    {
    	int iIndex;
    	char * szlabel;
    	char * szdesc;
    }
    sysmetrics [] = 
    {
    	SM_CXSCREEN,		"SM_CXSCREEN",		"Screen width in pixels",
    	SM_CYSCREEN,		"SM_CYSCREEN",		"Screen height in pixels",
    	SM_CXVSCROLL,		"SM_CYHSCROLL",		"Vetical Scroll arrow width",
    	SM_CYCAPTION,		"SM_CYCAPTION",		"Caption Bar Height",
    	SM_CXBORDER	,		"SM_CXBORDER",		"Windows Border width",
    	SM_CYBORDER	,		"SM_CYBORDER",		"Windows Border Height",
    	SM_CXDLGFRAME,		"SM_CXDLGFRAME",	"Dialog Window Frame width",
    	SM_CYDLGFRAME,		"SM_CYDLGFRAME",	"Dialog Window Frame Height",
    	SM_CYVTHUMB	,		"SM_CYVTHUMB",		"Vertical Scroll Thumb Height",
    	SM_CXHTHUMB,		"SM_CXHTHUMB",		"Horizontal Scroll Thumb Width",
    	SM_CXICON,			"SM_CXICON",		"Icon Width",
    	SM_CYICON,			"SM_CYICON",		"Icon Height",
    	SM_CXCURSOR,		"SM_CXCURSOR",		"Cursor Width",
    	SM_CYCURSOR,		"SM_CYCURSOR",		"Cursor Height",
    	SM_CYMENU,			"SM_CYMENU",		"Menu bar height",
    	SM_CXFULLSCREEN,	"SM_CXFULLSCREEN",	"Full screen client area width",
    	SM_CYFULLSCREEN,	"SM_CYFULLSCREEN",	"Full screen client area height",
    	SM_CYKANJIWINDOW,	"SM-CYKANJIWINDOW",	"Kanji window height",
    	SM_MOUSEPRESENT,	"SM-MOUSEPRESENT",	"Mouse present flag",
    	SM_CYVSCROLL,		"SM-CYVSCROLL",		"Vertical Scroll arrow height",
    	SM_CXHSCROLL,		"SM-CXHSCROLL",		"Horizontal scroll arrow width",
    	SM_DEBUG,			"SM_DEBUG",			"Debug version flah",
    	SM_SWAPBUTTON,		"SM_SWAPBUTTON",	"Mouse Buttons swapped flah",
    	SM_RESERVED1,		"SM_RESERVED1",		"Reserved",		
    	SM_RESERVED2,		"SM_RESERVED2",		"Reserved",
    	SM_RESERVED3,		"SM_RESERVED3",		"Reserved",
    	SM_RESERVED4,		"SM_RESERVED4",		"Reserved",
    	SM_CXMIN,			"SM_CXMIN",			"Minimum windows height",
    	SM_CYMIN,			"SM_CYMIN",			"Minimum windows width",
    	SM_CXSIZE,			"SM_CXSIZE",		"Minimum/Maximized icon width",
    	SM_CYSIZE,			"SM_CYSIZE",		"Minimum/Maximized icon height",
    	SM_CXFRAME,			"SM_CXFRAME",		"Windows frame width",
    	SM_CYFRAME,			"SM_CYFRAME",		"Windows frame height",
    	SM_CXMINTRACK,		"SM_CXMINTRACK",	"Minimum windows tracking width",
    	SM_CYMINTRACK,		"SM_CYMINTRACK",	"Minimum windows tracking height",
    	SM_CXDOUBLECLK,		"SM_CXDOUBLECLK",	"Double click x tolerance",
    	SM_CYDOUBLECLK,		"SM_CYDOUBLECLK",	"Double click y tolerance",
    	SM_CXICONSPACING,	"SM_CXICONSPACING",	"Horizontal icon spacing",
    	SM_CYICONSPACING,	"SM_CYICONSPACING",	"Vertical icon spacing",
    	SM_MENUDROPALIGNMENT,	"SM_MENUDROPALIGNMENT",	"Left or right menu drop",
    	SM_PENWINDOWS,		"SM_PENWINDOWS",	"Pen extensions installed",
    	SM_DBCSENABLED,		"SM_DBCSENABLED",	"Double-Byte Char Set enabled",
    	SM_CMOUSEBUTTONS,	"SM_CMOUSEBUTTONS",	"Number of mouse buttons",
    	SM_SHOWSOUNDS,		"SM_SHOWSOUNDS",	"Presents sounds visually"
    };

    Please help me with this or I wont be able to go further in the book!
    Attached Files Attached Files
    Baaaaaaaaah

  2. #2

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    And here is the header file!

    Can you also tell me how to post more than one file in one post because the whole project was too big
    Attached Files Attached Files
    Baaaaaaaaah

  3. #3
    evileconomist
    Guest
    The struct is written in a way which is "non-textbook", in a textbook it would read as follows:

    struct sysmetrics
    {
    int iIndex;
    char * szlabel;
    char * szdesc;
    };

    sysmetrics[] =
    {
    SM_CXSCREEN, "SM_CXSCREEN", "Screen width in pixels",
    ...

    SM_SHOWSOUNDS, "SM_SHOWSOUNDS", "Presents sounds visually
    }

    I hope this form makes more sense to you.


    #define NUMLINES (int)(sizeof sysmetrics / sizeof sysmetrics [0])

    (int) is a cast, the result of sizeof sysmetrics / sizeof sysmetrics [0] is a double by default thus we cast it to an integer.

    in fact it's a preprocceser instruction. It tells the compiler to swap NUMLINES to (int)(sizeof sysmetrics / sizeof sysmetrics [0])

    /Joachim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width