Annotation of mstools/samples/getsys/getsys.c, revision 1.1

1.1     ! root        1: /**************************************************************************\
        !             2: *  getsys.c -- sample program demonstrating the GetSys... APIs
        !             3: *
        !             4: *  In this sample the main window is a dialog box.  There is no need to
        !             5: *   register a new window class or create a new window.  Instead just call
        !             6: *   DialogBox() and use the template defined in the .RC file.  All of the
        !             7: *   interesting code is thus in the window procedure for the dialog box.
        !             8: *   In this case, simply respond to the button command messsages and fill
        !             9: *   the list box with appropriate values.
        !            10: *
        !            11: *  The dialog template currently specifies a "monospaced font."  This makes
        !            12: *   the dialog look somewhat odd, but makes text formatting much easier.  If
        !            13: *   the specified font does not exist on the system running this sample, the
        !            14: *   program will work fine, but the contents of the listbox will not look
        !            15: *   very good.
        !            16: *
        !            17: \**************************************************************************/
        !            18: 
        !            19: #include <windows.h>
        !            20: #include "getsys.h"
        !            21: 
        !            22: 
        !            23: /**************************************************************************\
        !            24: *
        !            25: *  function:  WinMain()
        !            26: *
        !            27: *  input parameters:  c.f. generic sample
        !            28: *
        !            29: \**************************************************************************/
        !            30: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        !            31:                      LPSTR lpCmdLine, int nCmdShow)
        !            32: {
        !            33: int ret;
        !            34: 
        !            35:     UNREFERENCED_PARAMETER( hPrevInstance );
        !            36:     UNREFERENCED_PARAMETER( lpCmdLine );
        !            37:     UNREFERENCED_PARAMETER( nCmdShow);
        !            38: 
        !            39:     ret = DialogBox (hInstance, "getsysDlg", NULL, (DLGPROC)MainDlgProc);
        !            40:     return ret;
        !            41: }
        !            42: 
        !            43: 
        !            44: 
        !            45: /**************************************************************************\
        !            46: *
        !            47: *  function:  MainDlgProc()
        !            48: *
        !            49: *  input parameters:  standard window procedure parameters.
        !            50: *
        !            51: \**************************************************************************/
        !            52: LRESULT MainDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        !            53: {
        !            54:   UNREFERENCED_PARAMETER(lParam);
        !            55: 
        !            56: 
        !            57:   switch (message) {
        !            58: 
        !            59:     /********************************************************************\
        !            60:     * WM_SYSCOMMAND
        !            61:     *
        !            62:     * ignore all syscommand messages, except for SC_CLOSE.
        !            63:     *  on this one, call EndDialog().
        !            64:     \********************************************************************/
        !            65:     case WM_SYSCOMMAND:
        !            66:       if (wParam == SC_CLOSE) {
        !            67:         EndDialog (hwnd, TRUE);
        !            68:         return TRUE;
        !            69:       } else
        !            70:         return FALSE;
        !            71:     break;
        !            72: 
        !            73: 
        !            74:     /********************************************************************\
        !            75:     * WM_COMMAND
        !            76:     *
        !            77:     * When the different buttons are hit, clear the list box, disable
        !            78:     *  updating to it, call the function which will fill it, reenable
        !            79:     *  updating, and then force a repaint.
        !            80:     *
        !            81:     \********************************************************************/
        !            82:     case WM_COMMAND:
        !            83: 
        !            84:       /* if the list box sends back messages, return.  Otherwise we will
        !            85:        *  clear it out, and that is not what we want to do at this point.
        !            86:        */
        !            87:       if (LOWORD(wParam)==DID_LISTBOX) return TRUE;
        !            88: 
        !            89:       SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW,    FALSE, 0);
        !            90:       SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0,     0);
        !            91: 
        !            92:       /* switch on the control ID of the button that is pressed. */
        !            93:       switch (LOWORD(wParam)) {
        !            94:         case DID_SYSCOLORS : doSysColors (hwnd); break;
        !            95:         case DID_DIRECTORY : doDirectory (hwnd); break;
        !            96:         case DID_INFO      : doInfo      (hwnd); break;
        !            97:         case DID_METRICS   : doMetrics   (hwnd); break;
        !            98:         case DID_PALETTE   : doPalette   (hwnd); break;
        !            99:         case DID_TIME      : doTime      (hwnd); break;
        !           100:       } /* end switch (LOWORD()) */
        !           101: 
        !           102:       SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
        !           103:       InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
        !           104:       return TRUE;
        !           105:     break; /* end WM_COMMAND */
        !           106: 
        !           107: 
        !           108:     default: return FALSE;
        !           109:   } /* end switch(message) */
        !           110: }
        !           111: 
        !           112: 
        !           113: 
        !           114: 
        !           115: 
        !           116: 
        !           117: /**************************************************************************\
        !           118: *
        !           119: *  functions:  do...()
        !           120: *
        !           121: * In all of the functions that follow, first set the text int the static
        !           122: *  text field to label the contents of the list box.  Then, query the
        !           123: *  desired system information, format it into strings, and add those strings
        !           124: *  to the listbox.
        !           125: *
        !           126: *  input parameters:  HWND - window handle for the dialog box.
        !           127: *  global variables:  buffer - array of char's to hold string w/ info.
        !           128: *
        !           129: \**************************************************************************/
        !           130: 
        !           131: VOID doSysColors (HWND hwnd)
        !           132: {
        !           133: int i;
        !           134: DWORD answer;
        !           135: 
        !           136:   SetDlgItemText (hwnd, DID_TEXT, "System Colors");
        !           137: 
        !           138:   for (i = 0; i<NSYSCOLORS; i++) {
        !           139: 
        !           140:     /*******************************************************/
        !           141:     /*******************************************************/
        !           142:     answer = GetSysColor (SysColors[i].Value);
        !           143:     /*******************************************************/
        !           144:     /*******************************************************/
        !           145: 
        !           146:     wsprintf (buffer, SysColors[i].String, (int)answer);
        !           147:     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           148:   }
        !           149:   return;
        !           150: }
        !           151: 
        !           152: 
        !           153: 
        !           154: VOID doDirectory (HWND hwnd)
        !           155: {
        !           156: char buffer[MAX_PATH];
        !           157: 
        !           158:   SetDlgItemText (hwnd, DID_TEXT, "System Directory");
        !           159: 
        !           160:   /*******************************************************/
        !           161:   /*******************************************************/
        !           162:   GetSystemDirectory (buffer, MAX_PATH);
        !           163:   /*******************************************************/
        !           164:   /*******************************************************/
        !           165: 
        !           166:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           167: 
        !           168:   return;
        !           169: }
        !           170: 
        !           171: 
        !           172: VOID doInfo(HWND hwnd)
        !           173: {
        !           174: SYSTEM_INFO  si;
        !           175: 
        !           176:   SetDlgItemText (hwnd, DID_TEXT, "SYSTEM_INFO");
        !           177: 
        !           178:   /*******************************************************/
        !           179:   /*******************************************************/
        !           180:   GetSystemInfo (&si);
        !           181:   /*******************************************************/
        !           182:   /*******************************************************/
        !           183: 
        !           184:   wsprintf (buffer, "dwOemId             \t%d",  (int) si.dwOemId                    );
        !           185:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           186:   wsprintf (buffer, "dwPageSize          \t%d",  (int) si.dwPageSize                 );
        !           187:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           188:   wsprintf (buffer, "lpMinimumApplicationAddress \t%08lx", (LONG)si.lpMinimumApplicationAddress );
        !           189:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           190:   wsprintf (buffer, "lpMaximumApplicationAddress \t%08lx", (LONG)si.lpMaximumApplicationAddress );
        !           191:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           192:   wsprintf (buffer, "dwActiveProcessorMask \t%d",  (int) si.dwActiveProcessorMask      );
        !           193:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           194:   wsprintf (buffer, "dwNumberOfProcessors  \t%d",  (int) si.dwNumberOfProcessors       );
        !           195:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           196:   wsprintf (buffer, "dwProcessorType       \t%d",  (int) si.dwProcessorType            );
        !           197:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           198:   wsprintf (buffer, "dwProcessorRevision   \t%d",  (int) si.dwProcessorRevision        );
        !           199:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           200:   wsprintf (buffer, "dwProcessorOptions    \t%d",  (int) si.dwProcessorOptions         );
        !           201:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           202: 
        !           203:   return;
        !           204: }
        !           205: 
        !           206: 
        !           207: 
        !           208: VOID doMetrics   (HWND hwnd)
        !           209: {
        !           210: int  i;
        !           211: int  answer;
        !           212: 
        !           213:   SetDlgItemText (hwnd, DID_TEXT, "System Metrics");
        !           214: 
        !           215:   for (i = 0; i<NSYSMETRICS; i++) {
        !           216: 
        !           217:     /*******************************************************/
        !           218:     /*******************************************************/
        !           219:     answer = GetSystemMetrics (SystemMetrics[i].Value);
        !           220:     /*******************************************************/
        !           221:     /*******************************************************/
        !           222: 
        !           223:     wsprintf (buffer, SystemMetrics[i].String, (int)answer);
        !           224:     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           225:   }
        !           226: 
        !           227:   return;
        !           228: }
        !           229: 
        !           230: 
        !           231: 
        !           232: VOID doPalette(HWND hwnd)
        !           233: {
        !           234: int nEntries;
        !           235: HDC hdc;
        !           236: int i;
        !           237: LPPALETTEENTRY  lpp;
        !           238: 
        !           239:   SetDlgItemText (hwnd, DID_TEXT, "System Palette");
        !           240: 
        !           241:   /* this function is slightly different because the amount of information
        !           242:    * is not known until run time.  First find the number of entries in the
        !           243:    * palette (16 for VGA, but 256 for 8514, ...), then allocate enough
        !           244:    * space to hold all of them, query the information, put it in the list
        !           245:    * box, and then free up the memory allocated.
        !           246:    */
        !           247:   hdc = GetDC (hwnd);
        !           248:   nEntries = GetSystemPaletteEntries (hdc, 0,0, NULL);
        !           249:   lpp = (LPPALETTEENTRY)LocalAlloc (LPTR,
        !           250:                            (DWORD) (nEntries* sizeof (PALETTEENTRY)));
        !           251: 
        !           252:   if (lpp == NULL) {
        !           253:     MessageBox (hwnd, "Memory allocation failed.", "Warning", MB_ICONSTOP | MB_OK);
        !           254:     return;
        !           255:   }
        !           256: 
        !           257:   /*******************************************************/
        !           258:   /*******************************************************/
        !           259:   nEntries = GetSystemPaletteEntries (hdc, 0,nEntries, lpp);
        !           260:   /*******************************************************/
        !           261:   /*******************************************************/
        !           262: 
        !           263:   ReleaseDC (hwnd, hdc);
        !           264: 
        !           265:   for (i = 0; i<nEntries; i++) {
        !           266:     wsprintf (buffer, "%d) \t%x \t%x \t%x \t%x", i,
        !           267:               lpp[i].peRed, lpp[i].peGreen, lpp[i].peBlue, lpp[i].peFlags);
        !           268:     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           269:   }
        !           270: 
        !           271:   LocalFree (LocalHandle ((LPSTR)lpp));
        !           272:   return;
        !           273: }
        !           274: 
        !           275: 
        !           276: 
        !           277: 
        !           278: VOID doTime (HWND hwnd)
        !           279: {
        !           280: SYSTEMTIME  st;
        !           281: 
        !           282:   SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");
        !           283: 
        !           284:   /*******************************************************/
        !           285:   /*******************************************************/
        !           286:   GetSystemTime (&st);
        !           287:   /*******************************************************/
        !           288:   /*******************************************************/
        !           289: 
        !           290:   wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
        !           291:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           292:   wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
        !           293:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           294:   wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
        !           295:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           296:   wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
        !           297:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           298:   wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
        !           299:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           300:   wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
        !           301:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           302:   wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
        !           303:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           304:   wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
        !           305:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        !           306:   return;
        !           307: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.