advadp.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "precomp.h"
  2. #include "setcdcl.hxx"
  3. #include "device.hxx"
  4. /*****************************************************************
  5. *
  6. * GetVerInfo
  7. *
  8. *****************************************************************/
  9. LPTSTR GetVerInfo(LPBYTE lpbVerInfo, LPTSTR pszKey) {
  10.     TCHAR szVersionKey[MAX_PATH];
  11.     LPTSTR pVerInfo;
  12.     UINT cb = 0;
  13.     //
  14.     // Try to get info in the local language
  15.     //
  16.     if (lpbVerInfo)
  17.     {
  18.         wsprintf(szVersionKey, TEXT("\StringFileInfo\%04X04B0\%ws"),
  19.                 LANGIDFROMLCID(GetUserDefaultLCID()), pszKey);
  20.         VerQueryValue(lpbVerInfo, szVersionKey, (LPVOID*)&pVerInfo, &cb);
  21.         if (cb == 0)
  22.         {
  23.             //
  24.             // No local language, try US English
  25.             //
  26.             wsprintf(szVersionKey, TEXT("\StringFileInfo\040904B0\%ws"), pszKey);
  27.             VerQueryValue(lpbVerInfo, szVersionKey, (LPVOID*)&pVerInfo, &cb);
  28.         }
  29.     }
  30.     if (cb == 0)
  31.     {
  32.         pVerInfo = NULL;
  33.     }
  34.     return pVerInfo;
  35. }
  36. /*****************************************************************
  37. *
  38. * CDLGCHGADAPTOR class
  39. *
  40. *        derived from CDIALOG
  41. *
  42. *****************************************************************/
  43. CDLGCHGADAPTOR::CDLGCHGADAPTOR() : iRet(RET_NO_CHANGE) {
  44.     this->iDlgResID = DLG_SET_CHANGE_VID;
  45. }
  46. BOOL CDLGCHGADAPTOR::InitDlg(HWND hwndFocus) {
  47.     LPDISPLAY_DEVICE pDisplayDevice = (LPDISPLAY_DEVICE) (this->lParam);
  48.     //DLI: make it compile CREGVIDOBJ crvo((&(pDisplayDevice->DeviceName[0]));
  49. #ifdef UNICODE
  50.     CREGVIDOBJ crvo(&(pDisplayDevice->DeviceName[0]));
  51. #else
  52.     CREGVIDOBJ crvo((char *) &(pDisplayDevice->DeviceName[0]));
  53. #endif
  54.     LPTSTR psz;
  55.     TCHAR noVersion[MAX_PATH];
  56.     TCHAR szPath[MAX_PATH];
  57.     HDC hdc;
  58.     ULONG DrivVer;
  59.     HARDWARE_INFO hardwareInfo;
  60.     DWORD i;
  61.     DWORD cb;
  62.     DWORD dwHandle;
  63.     LPBYTE lpbVerInfo = NULL;
  64.     LPTSTR lpInfo;
  65.     LoadString(hInstance, IDS_NO_VERSION_INFO, noVersion, sizeof(noVersion));
  66.     //
  67.     // Get the installed driver names and put them in the dialog
  68.     //
  69.     psz = crvo.CloneDisplayFileNames(TRUE);
  70.     if (psz) {
  71.         this->SendCtlMsg(ID_ADP_CURFILES, WM_SETTEXT, 0, (LPARAM)psz);
  72.         LocalFree(psz);
  73.     }
  74.     //
  75.     // display the adaptor type
  76.     //
  77.     this->SendCtlMsg(ID_ADP_ADAPTOR,
  78.                      WM_SETTEXT,
  79.                      0,
  80.                      (LPARAM) (&(pDisplayDevice->DeviceString[0])));
  81.     //
  82.     // Get the miniport driver path
  83.     //
  84.     wsprintf(szPath, TEXT("drivers\%s.sys"), crvo.GetMiniPort());
  85.     //
  86.     // Open the file version resource for the driver
  87.     //
  88.     cb = GetFileVersionInfoSize(szPath, &dwHandle);
  89.     if (cb != 0) {
  90.         lpbVerInfo = (LPBYTE)LocalAlloc(LPTR, cb);
  91.         if (lpbVerInfo != NULL) {
  92.             GetFileVersionInfo(szPath, dwHandle, cb, lpbVerInfo);
  93.         }
  94.     }
  95.     //
  96.     // Get the company name and put it in the dialog
  97.     //
  98.     lpInfo = GetVerInfo(lpbVerInfo, TEXT("CompanyName"));
  99.     this->SendCtlMsg(ID_ADP_MANUFACT,
  100.                      WM_SETTEXT,
  101.                      0,
  102.                      (ULONG) (lpInfo ? lpInfo : noVersion));
  103.     //
  104.     // Get the version number from the miniport, and append "," and the
  105.     // display driver version number.
  106.     //
  107.     hdc = GetDC(this->hwnd);
  108.     DrivVer = GetDeviceCaps(hdc, DRIVERVERSION);
  109.     ReleaseDC(this->hwnd, hdc);
  110.     lpInfo = GetVerInfo(lpbVerInfo, TEXT("FileVersion"));
  111.     wsprintf(szPath, TEXT("%s, %d.%d.%d"),
  112.              lpInfo ? lpInfo : noVersion,
  113.              (DrivVer >> 12) & 0xF,
  114.              (DrivVer >> 8) & 0xF,
  115.              DrivVer & 0xFF);
  116.     this->SendCtlMsg(ID_ADP_VERSION, WM_SETTEXT, 0, (LPARAM)szPath);
  117.     if (lpbVerInfo != NULL)
  118.         LocalFree(lpbVerInfo);
  119.     //
  120.     // Now put in the hardware information.
  121.     //
  122.     crvo.GetHardwareInformation(&hardwareInfo);
  123.     this->SendCtlMsg(ID_ADP_CHIP,       WM_SETTEXT, 0, (LPARAM)hardwareInfo.ChipType);
  124.     this->SendCtlMsg(ID_ADP_DAC,        WM_SETTEXT, 0, (LPARAM)hardwareInfo.DACType);
  125.     this->SendCtlMsg(ID_ADP_MEM,        WM_SETTEXT, 0, (LPARAM)hardwareInfo.MemSize);
  126.     this->SendCtlMsg(ID_ADP_ADP_STRING, WM_SETTEXT, 0, (LPARAM)hardwareInfo.AdapString);
  127.     this->SendCtlMsg(ID_ADP_BIOS_INFO,  WM_SETTEXT, 0, (LPARAM)hardwareInfo.BiosString);
  128.     for (i=0; i < 5; i++) {
  129.         if ( *(((LPTSTR *) (&hardwareInfo)) + i) != NULL) {
  130.             LocalFree(*(((LPTSTR *) (&hardwareInfo)) + i));
  131.         }
  132.     }
  133.     return TRUE;
  134. }
  135. BOOL CDLGCHGADAPTOR::DoCommand(int idControl, HWND hwndControl, int iNoteCode ) {
  136.     return FALSE;
  137. }
  138. //
  139. // DoNotify method
  140. //
  141. BOOL CDLGCHGADAPTOR::DoNotify(int idControl, NMHDR *lpnmh, UINT iNoteCode ) {
  142.     switch (iNoteCode) {
  143.     case PSN_APPLY:
  144.         // use ID_PRESTARTWINDOWS to mean something has changed.
  145.         //
  146.         // NOTE: the PropSheet_RestartWindows() does NOT cause
  147.         // windows to restart.  It just sets the return code
  148.         // from the property sheet.
  149.         //
  150.         if (this->iRet != RET_NO_CHANGE)
  151.             PropSheet_RestartWindows(this->hwndParent);
  152.         //
  153.         // NOTE: read the above comment!!!
  154.         //
  155.         SetWindowLong(this->hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
  156.         break;
  157. #if 0
  158.     case PSN_RESET:
  159.         this->iRet = RET_NO_CHANGE;
  160.         break;
  161. #endif
  162.     default:
  163.         return FALSE;
  164.     }
  165.     return TRUE;
  166. }
  167. ///////////////////////////////////////////////////////////////////////////
  168. //
  169. // Start of "C" code!
  170. //
  171. ///////////////////////////////////////////////////////////////////////////
  172. /***************************************************************************
  173. * AdvAdaptorPageProc
  174. *
  175. *   Dialog Proc callable from PropertyPage code.
  176. *
  177. * History:
  178. * 10-Oct-1996 JonPa Created it
  179. ***************************************************************************/
  180. BOOL CALLBACK AdvAdaptorPageProc(
  181.     HWND hwnd,
  182.     UINT msg,
  183.     WPARAM wParam,
  184.     LPARAM lParam
  185.     )
  186. {
  187.     PCDLGCHGADAPTOR pddDialog;
  188.     switch (msg) {
  189.     case WM_INITDIALOG:
  190.         pddDialog = new CDLGCHGADAPTOR;
  191.         pddDialog->hwndParent = NULL;
  192.         pddDialog->hmodModule = hInstance;
  193.         pddDialog->lParam = ((LPPROPSHEETPAGE)lParam)->lParam;
  194.         // dli -- moved to multimon.cpp
  195.         //ghwndPropSheet = GetParent(hwnd);
  196.         lParam =  (LPARAM)pddDialog;
  197.         break;
  198.     case WM_NCDESTROY:
  199.         pddDialog = (PCDLGCHGADAPTOR)GetWindowLong(hwnd, DWL_USER);
  200.         SetWindowLong(hwnd, DWL_USER, NULL);
  201.         delete pddDialog;
  202.         break;
  203.     }
  204.     return CDialogProc(hwnd, msg, wParam, lParam );
  205. }
  206. BOOL GetAdvAdapterPropPageParam(LPVOID lpv, LPFNADDPROPSHEETPAGE lpfnAdd, LPARAM lparam, LPARAM lparamPage) {
  207.     // Create a property page and call lpfnAdd to add it in.
  208.     HPROPSHEETPAGE page = NULL;
  209.     PROPSHEETPAGE psp;
  210.     BOOL fRet = FALSE;
  211.     psp.dwSize = sizeof(psp);
  212.     psp.dwFlags = PSP_DEFAULT;
  213.     psp.hInstance = hInstance;
  214.     psp.pfnDlgProc = AdvAdaptorPageProc;
  215.     psp.pszTemplate = MAKEINTRESOURCE(DLG_SET_CHANGE_VID);
  216.     psp.lParam = lparamPage;
  217.     if ((page = CreatePropertySheetPage(&psp)) != NULL) {
  218.         fRet = TRUE;
  219.         if (!lpfnAdd(page, lparam)) {
  220.             DestroyPropertySheetPage(page);
  221.             page = NULL;
  222.             fRet = FALSE;
  223.         }
  224.     }
  225.     return fRet;
  226. }