Posted to tcl by patthoyts at Sun Nov 04 01:02:09 GMT 2007view raw

  1. /* Dump some system parameters.
  2. *
  3. * Build using:
  4. * cl -nologo -W3 -O2 -MD -o metrics.exe metrics.c -link -release -subsystem:console
  5. */
  6.  
  7. #define STRICT
  8. #define WIN32_LEAN_AND_MEAN
  9. #define WINVER 0x0501
  10. #define UNICODE
  11. #if defined(UNICODE) && !defined(_UNICODE)
  12. #define _UNICODE
  13. #endif
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <tchar.h>
  17.  
  18. #if _MSC_VER >= 100
  19. #pragma comment(lib, "user32")
  20. #pragma comment(lib, "gdi32")
  21. #endif
  22.  
  23. void
  24. Fonts()
  25. {
  26. HDC hdc;
  27. NONCLIENTMETRICS ncMetrics = {0};
  28.  
  29. hdc = GetDC(NULL);
  30.  
  31. ncMetrics.cbSize = sizeof(ncMetrics);
  32. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncMetrics), &ncMetrics, 0);
  33. _tprintf(_T("Message font: %s %d\n"), ncMetrics.lfMessageFont.lfFaceName,
  34. -MulDiv(ncMetrics.lfMessageFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  35. _tprintf(_T("Menu font: %s %d\n"), ncMetrics.lfMenuFont.lfFaceName,
  36. -MulDiv(ncMetrics.lfMenuFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  37. _tprintf(_T("Caption font: %s %d\n"), ncMetrics.lfCaptionFont.lfFaceName,
  38. -MulDiv(ncMetrics.lfCaptionFont.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  39.  
  40. {
  41. HFONT hFont;
  42. HGDIOBJ hOld;
  43. TEXTMETRIC tm = {0};
  44. TCHAR szFaceName[LF_FACESIZE];
  45. hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
  46. hOld = SelectObject(hdc, hFont);
  47. GetTextMetrics(hdc, &tm);
  48. GetTextFace(hdc, LF_FACESIZE, szFaceName);
  49. SelectObject(hdc, hOld);
  50. _tprintf(_T("ANSI_FIXED_FONT: %s %d"), szFaceName,
  51. (MulDiv(tm.tmHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY))));
  52. }
  53. }
  54.  
  55. int
  56. _tmain (int argc, TCHAR *const argv[])
  57. {
  58. int n;
  59. #define E(x) { _T(#x) , x}
  60. struct {
  61. const TCHAR *name; int id;
  62. } map[] = {
  63. E(SM_ARRANGE), E(SM_CLEANBOOT), E(SM_CMONITORS),
  64. E(SM_CXBORDER), E(SM_CYBORDER),
  65. E(SM_CXCURSOR), E(SM_CYCURSOR),
  66. E(SM_CXDLGFRAME), E(SM_CYDLGFRAME),
  67. E(SM_CXDOUBLECLK), E(SM_CYDOUBLECLK),
  68. E(SM_CXDRAG), E(SM_CYDRAG),
  69. E(SM_CXEDGE), E(SM_CYEDGE),
  70. E(SM_CXFIXEDFRAME), E(SM_CYFIXEDFRAME),
  71. /* E(SM_CXFOCUSBORDER), E(SM_CYFOCUSBORDER), */
  72. E(SM_CXFRAME), E(SM_CYFRAME),
  73. E(SM_CXFULLSCREEN), E(SM_CYFULLSCREEN),
  74.  
  75. E(SM_CXSIZEFRAME), E(SM_CYSIZEFRAME),
  76. E(SM_CXVIRTUALSCREEN), E(SM_CYVIRTUALSCREEN),
  77. E(SM_XVIRTUALSCREEN), E(SM_YVIRTUALSCREEN),
  78. };
  79. for (n = 0; n < sizeof(map)/sizeof(map[0]); n++) {
  80. _tprintf(_T("%s = %d\n"), map[n].name, GetSystemMetrics(map[n].id));
  81. }
  82.  
  83. Fonts();
  84.  
  85. return 0;
  86. }