home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / sysinfo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.8 KB  |  344 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "slavewnd.h"
  21.  
  22. //  setting/winini/device change callback.
  23. void UpdateSystemInfo(UINT uMsg, WPARAM wParam, LPARAM lParam)
  24. {
  25.     //  Update any info we might have.
  26.     sysInfo.UpdateInfo();
  27. }
  28.  
  29. //  Global must be present early, as other globals may want
  30. //      to register early on.
  31. #pragma warning(disable:4073)
  32. #pragma init_seg(lib)
  33. CSysInfo sysInfo;
  34. #pragma warning(default:4073)
  35.  
  36. CSysInfo::CSysInfo()    {
  37.     //    Flag the method in which we'll attempt to determine
  38.     //        the operating system.
  39.     BOOL bUseGetversion = FALSE;
  40.  
  41.     //    Init variants we'd like to detect.
  42.     m_bWin32s = FALSE;
  43.     m_bWinNT = FALSE;
  44.     m_bWin4 = FALSE;
  45.  
  46.     //    Init os version major, minor, build.
  47.     m_dwMajor = (DWORD)-1;
  48.     m_dwMinor = (DWORD)-1;
  49.     m_dwBuild = (DWORD)-1;
  50.  
  51. #ifdef XP_WIN16
  52.     m_bWin16 = TRUE;
  53.     m_bWin32 = FALSE;
  54.  
  55.     //    Use GetVersion.
  56.     bUseGetversion = TRUE;
  57. #else
  58.     m_bWin16 = FALSE;
  59.     m_bWin32 = TRUE;
  60.  
  61.     OSVERSIONINFO osVer;
  62.     memset(&osVer, 0, sizeof(osVer));
  63.     osVer.dwOSVersionInfoSize = sizeof(osVer);
  64.     if(GetVersionEx(&osVer) == TRUE)    {
  65.         switch(osVer.dwPlatformId)    {
  66.         case VER_PLATFORM_WIN32s:
  67.             m_bWin32s = TRUE;
  68.             break;
  69.         case VER_PLATFORM_WIN32_NT:
  70.             m_bWinNT = TRUE;
  71.             break;
  72.         case VER_PLATFORM_WIN32_WINDOWS:
  73.             m_bWin4 = TRUE;
  74.             break;
  75.         default:
  76.             //    Hmm.....
  77.             bUseGetversion = TRUE;
  78.             break;
  79.         }
  80.  
  81.         if ( osVer.dwMajorVersion >= 4)
  82.             m_bWin4 = TRUE;
  83.  
  84.         //    Get even more information.
  85.         //    Only take the lower word of the version info.
  86.         //        Top also seems to be os version....
  87.         m_dwMajor = osVer.dwMajorVersion;
  88.         m_dwMinor = osVer.dwMinorVersion;
  89.         m_dwBuild = (WORD)osVer.dwBuildNumber;
  90.     } else {
  91.         //    Use getversion to attempt to determine
  92.         //        the OS flavor.
  93.         bUseGetversion = TRUE;
  94.     }
  95. #endif
  96.  
  97.     if(bUseGetversion == TRUE)    {
  98.         //    Attempt to determine exact OS flavor.
  99.         DWORD dwVersion = ::GetVersion();
  100.  
  101.         //    Win95 or what?
  102.         m_bWin4 = LOBYTE(dwVersion) >= 4;
  103.  
  104.         //    Clear 32s if Win4.
  105.         m_bWin32s = (dwVersion & 0x80000000UL) != 0;
  106.         if(m_bWin4 == TRUE)    {
  107.             m_bWin32s = FALSE;
  108.         }
  109.  
  110. #ifdef XP_WIN32
  111.         //    If neither 32s or 95 are set, then assume NT.
  112.         if(m_bWin4 == FALSE && m_bWin32s == FALSE)    {
  113.             m_bWinNT = TRUE;
  114.         }
  115. #endif
  116.  
  117.         //    Attempt to get version information if not already set.
  118.         if(m_dwMajor == (DWORD)-1)    {
  119.             m_dwMajor = LOBYTE(dwVersion);
  120.         }
  121.         if(m_dwMinor == (DWORD)-1)    {
  122.             m_dwMinor = HIBYTE(dwVersion);
  123.         }
  124.  
  125.         //    Don't care about build number in the get version stone age.
  126.  
  127. #ifdef XP_WIN16
  128.         //    However, if we aren't already set for 95, and our minor version
  129.         //        number is 95, then set us to be 95.
  130.         if(m_dwMinor >= 95)    {
  131.             m_bWin4 = TRUE;
  132.             m_bWin32s = FALSE;
  133.         }
  134. #endif
  135.     }
  136.  
  137.     m_bDBCS = FALSE;    
  138.     if (GetSystemMetrics(SM_DBCSENABLED))
  139.         m_bDBCS = TRUE;    
  140.  
  141.  
  142.     //    Clear out the color information.
  143.     m_hbrBtnFace = NULL;
  144.  
  145.     m_clrBtnFace = RGB(0,0,0);
  146.     m_clrBtnShadow = RGB(0,0,0);
  147.     m_clrBtnHilite = RGB(0,0,0);
  148.     m_clrBtnText = RGB(0,0,0);
  149.  
  150.     // Bits per pixel info.
  151.     m_iBitsPerPixel = 0;
  152.  
  153.     //    Here's the current window border sizes.
  154.     m_iBorderHeight = 0;
  155.     m_iBorderWidth = 0;
  156.  
  157.     //    The current scroll bar sizes.
  158.     m_iScrollWidth = 0;
  159.     m_iScrollHeight = 0;
  160.  
  161.     //    Zero out the winsock information.
  162.     //    Should be set later on.
  163.     memset(&m_wsaData, 0, sizeof(m_wsaData));
  164.     m_iMaxSockets = 0;
  165.  
  166.     //  Current screen dimensions.
  167.     m_iScreenWidth = 0;
  168.     m_iScreenHeight = 0;
  169.     
  170.     //  No printer yet.
  171.     m_bPrinter = FALSE;
  172.  
  173.     //    Load up color information, etc....
  174.     UpdateInfo();
  175.  
  176.     //  Let the slave window know that on any change
  177.     //      to the system, we want to be updated.
  178.     //  Note that WM_WININICHANGE is equal to WM_SETTINGCHANGE.
  179.     m_pWatchSettingChanges = slavewnd.Register(WM_WININICHANGE, UpdateSystemInfo);
  180.     m_pWatchDeviceModeChanges = slavewnd.Register(WM_DEVMODECHANGE, UpdateSystemInfo);
  181. #ifdef _WIN32
  182.     //  We'll want to update on this too (change of resolution).
  183.     //  However, I've never seen this work!!!!
  184.     m_pWatchDeviceChanges = slavewnd.Register(WM_DISPLAYCHANGE, UpdateSystemInfo);
  185. #else
  186.     m_pWatchDeviceChanges = NULL;
  187. #endif
  188.  
  189.     m_bOverrideWin95Tooltips = OverrideWin95ToolTips();
  190. }
  191.  
  192. CSysInfo::~CSysInfo()    {
  193.     //    Get rid of any brushes we have allocated.
  194.     if(m_hbrBtnFace != NULL)    {
  195.         ::DeleteObject(m_hbrBtnFace);
  196.     }
  197.  
  198.     if(m_hbrMenu != NULL) {
  199.         ::DeleteObject(m_hbrMenu);
  200.     }
  201.  
  202.     if(m_hbrHighlight != NULL){
  203.         ::DeleteObject(m_hbrHighlight);
  204.     }
  205.  
  206.     if(m_pWatchSettingChanges)  {
  207.         slavewnd.UnRegister(m_pWatchSettingChanges);
  208.         m_pWatchSettingChanges = NULL;
  209.     }
  210.     if(m_pWatchDeviceModeChanges)  {
  211.         slavewnd.UnRegister(m_pWatchDeviceModeChanges);
  212.         m_pWatchDeviceModeChanges = NULL;
  213.     }
  214.     if(m_pWatchDeviceChanges)  {
  215.         slavewnd.UnRegister(m_pWatchDeviceChanges);
  216.         m_pWatchDeviceChanges = NULL;
  217.     }
  218. }
  219.  
  220. void CSysInfo::UpdateInfo()    {
  221.     //    Set up all the known colors we'd like to cache...
  222.     //    There are lots of other possible colors we could get
  223.     //        here also.  Feel free to add.
  224.     m_clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
  225.     m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
  226.     m_clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  227.     m_clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
  228.     m_clrMenu = ::GetSysColor(COLOR_MENU);
  229.     m_clrHighlight = ::GetSysColor(COLOR_HIGHLIGHT);
  230.  
  231.     // Bits per pixel
  232.     HWND hTmp = ::GetDesktopWindow();
  233.     HDC hScreen = ::GetDC(hTmp);
  234.     m_iBitsPerPixel = ::GetDeviceCaps(hScreen, BITSPIXEL);
  235.     ::ReleaseDC(hTmp, hScreen);
  236.     hScreen = NULL;
  237.     hTmp = NULL;
  238.  
  239.     //    Determine window border sizes.
  240.     m_iBorderWidth = ::GetSystemMetrics(SM_CXBORDER);
  241.     m_iBorderHeight = ::GetSystemMetrics(SM_CYBORDER);
  242.  
  243.     //    On windows 95, NT4, 32 bit, we double the border size.
  244.     if(m_dwMajor >= 4 && m_bWin32)    {
  245.         m_iBorderWidth *= 2;
  246.         m_iBorderHeight *= 2;
  247.     }
  248.  
  249.     //    Determine scroll bar dimensions.
  250.     m_iScrollWidth = ::GetSystemMetrics(SM_CXVSCROLL);
  251.     m_iScrollHeight = ::GetSystemMetrics(SM_CYHSCROLL);
  252.  
  253.     //  Determine screen dimensions
  254.     m_iScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
  255.     m_iScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
  256.  
  257.     //    Free off brushes if previously allocated.
  258.     if(m_hbrBtnFace != NULL)    {
  259.         ::DeleteObject(m_hbrBtnFace);
  260.     }
  261.  
  262.     if(m_hbrMenu != NULL) {
  263.         ::DeleteObject(m_hbrMenu);
  264.     }
  265.  
  266.     if(m_hbrHighlight != NULL){
  267.         ::DeleteObject(m_hbrHighlight);
  268.     }
  269.  
  270.     //    Allocate brushes according to color.
  271.     m_hbrBtnFace = ::CreateSolidBrush(m_clrBtnFace);
  272.     m_hbrMenu = ::CreateSolidBrush(m_clrMenu);
  273.     m_hbrHighlight = ::CreateSolidBrush(m_clrHighlight);
  274.     
  275.     //  Attempt to detect printer, and cleanup.
  276.     m_bPrinter = FALSE;
  277.     PRINTDLG pd;
  278.     memset(&pd, 0, sizeof(pd));
  279.     pd.lStructSize = sizeof(pd);
  280.     pd.Flags = PD_RETURNDEFAULT;
  281.     ::PrintDlg(&pd);
  282.     if(pd.hDevMode) {
  283.         m_bPrinter = TRUE;
  284.         ::GlobalFree(pd.hDevMode);
  285.         pd.hDevMode = NULL;
  286.     }
  287.     if(pd.hDevNames) {
  288.         m_bPrinter = TRUE;
  289.         ::GlobalFree(pd.hDevNames);
  290.         pd.hDevNames = NULL;
  291.     }
  292. }
  293.  
  294. BOOL CSysInfo::OverrideWin95ToolTips(void)
  295. {
  296.     char comctrl32Path[MAX_PATH + 1];
  297.     CString csComCtrl32;
  298.     BOOL bResult = FALSE;
  299. #ifdef XP_WIN32
  300.     if(IsWin4_32() && !m_bWinNT) 
  301.     {
  302.         HMODULE hComCtl32 = GetModuleHandle("comctl32.dll");
  303.  
  304.         if(hComCtl32)
  305.         {
  306.             if(GetModuleFileName(hComCtl32, comctrl32Path, MAX_PATH) > 0)
  307.             {
  308.                 csComCtrl32 = comctrl32Path;
  309.  
  310.                 LPTSTR pComCtrl32 = csComCtrl32.LockBuffer();
  311.                 DWORD dwZero;
  312.                 DWORD dwSize = GetFileVersionInfoSize(pComCtrl32,&dwZero);
  313.  
  314.                 if(dwSize > 0)
  315.                 {
  316.                     BYTE *data = new BYTE[dwSize];
  317.                     if(data && GetFileVersionInfo(pComCtrl32, 0, dwSize, data));
  318.                     {
  319.                         VS_FIXEDFILEINFO *fileInfo = NULL;
  320.                         UINT size;
  321.  
  322.                         if (VerQueryValue(data, TEXT("\\"), (LPVOID*)&fileInfo, &size) && fileInfo)
  323.                         {
  324.                             WORD major = HIWORD(fileInfo->dwFileVersionMS);
  325.                             WORD minor = LOWORD(fileInfo->dwFileVersionMS);
  326.                             
  327.                             if(major == 4 && minor == 0)
  328.                                 bResult = TRUE;
  329.                         }
  330.   
  331.                     }
  332.                     if(data)
  333.                         delete data;
  334.  
  335.                 }
  336.  
  337.                 csComCtrl32.UnlockBuffer();
  338.             }
  339.         }
  340.     }
  341. #endif
  342.     return bResult;
  343. }
  344.