GME  13
AboutDlg.cpp
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 
00003 #include "GMEVersion.h"
00004 #include "GMEApp.h"
00006 // CAboutDlg dialog used for App About
00007 
00008 class CAboutDlg : public CDialog
00009 {
00010 public:
00011         CAboutDlg();
00012 
00013 // Dialog Data
00014         //{{AFX_DATA(CAboutDlg)
00015         enum { IDD = IDD_ABOUTBOX };
00016         CStatic m_bmpAbout;
00017         //}}AFX_DATA
00018 
00019         // ClassWizard generated virtual function overrides
00020         //{{AFX_VIRTUAL(CAboutDlg)
00021         protected:
00022         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
00023         //}}AFX_VIRTUAL
00024 
00025 // Implementation
00026 protected:
00027         //{{AFX_MSG(CAboutDlg)
00028         afx_msg void OnAboutPicture();
00029         virtual BOOL OnInitDialog();
00030         //}}AFX_MSG
00031         DECLARE_MESSAGE_MAP()
00032 public:
00033         afx_msg void OnEnChangeRichedit21();
00034 };
00035 
00036 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
00037 {
00038         //{{AFX_DATA_INIT(CAboutDlg)
00039         //}}AFX_DATA_INIT
00040 }
00041 
00042 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
00043 {
00044         CDialog::DoDataExchange(pDX);
00045         //{{AFX_DATA_MAP(CAboutDlg)
00046         DDX_Control(pDX, IDC_BMPABOUT, m_bmpAbout);
00047         //}}AFX_DATA_MAP
00048 }
00049 
00050 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
00051         //{{AFX_MSG_MAP(CAboutDlg)
00052         ON_BN_CLICKED(IDC_BMPABOUT, OnAboutPicture)
00053         //}}AFX_MSG_MAP
00054 END_MESSAGE_MAP()
00055 
00056 // App command to run the dialog
00057 void CGMEApp::OnAppAbout()
00058 {
00059         CAboutDlg aboutDlg;
00060         aboutDlg.DoModal();
00061 }
00062 
00063 void CAboutDlg::OnAboutPicture() 
00064 {
00065         // TODO: Add your control notification handler code here
00066         CDLLInfoDlg dllDlg;
00067         dllDlg.DoModal();               
00068 }
00069 
00070 BOOL CAboutDlg::OnInitDialog() 
00071 {
00072         CDialog::OnInitDialog();
00073         
00074         CStatic* version = (CStatic*)GetWindow(GW_CHILD);
00075         ASSERT(version);
00076 
00077 #if defined(_M_IX86)
00078         version->SetWindowTextW(CString(GME_VERSION_STR) + " x86");
00079 #elif defined(_M_X64)
00080         version->SetWindowTextW(CString(GME_VERSION_STR) + " x64");
00081 #else
00082 #error Unknown arch
00083 #endif
00084 
00085         CRect rectAbout;
00086         GetClientRect( rectAbout );
00087         CBitmap bmpAbout;
00088         bmpAbout.LoadBitmap( IDB_ABOUT );
00089         BITMAP bmpStruct;
00090         bmpAbout.GetBitmap( &bmpStruct );
00091         m_bmpAbout.MoveWindow( ( rectAbout.Width() - bmpStruct.bmWidth )  / 2, rectAbout.TopLeft().y + 10, bmpStruct.bmWidth, bmpStruct.bmHeight );
00092         
00093         return TRUE;  // return TRUE unless you set the focus to a control
00094                       // EXCEPTION: OCX Property Pages should return FALSE
00095 }
00096 
00097 
00098 
00100 // CDLLInfoDlg dialog
00101 
00102 
00103 CDLLInfoDlg::CDLLInfoDlg(CWnd* pParent /*=NULL*/)
00104         : CDialog(CDLLInfoDlg::IDD, pParent)
00105 {
00106         //{{AFX_DATA_INIT(CDLLInfoDlg)
00107         //}}AFX_DATA_INIT
00108 }
00109 
00110 
00111 void CDLLInfoDlg::DoDataExchange(CDataExchange* pDX)
00112 {
00113         CDialog::DoDataExchange(pDX);
00114         //{{AFX_DATA_MAP(CDLLInfoDlg)
00115         DDX_Control(pDX, IDC_DLL_LIST, m_DLLList);
00116         //}}AFX_DATA_MAP
00117 }
00118 
00119 
00120 BEGIN_MESSAGE_MAP(CDLLInfoDlg, CDialog)
00121         //{{AFX_MSG_MAP(CDLLInfoDlg)
00122         //}}AFX_MSG_MAP
00123 END_MESSAGE_MAP()
00124 
00126 // CDLLInfoDlg message handlers
00127 #include <Tlhelp32.h>
00128 
00129 static BOOL EnumModules(HMODULE *modules, DWORD modsize, LPDWORD needed)
00130 {
00131         
00132       OSVERSIONINFO  osver ;
00133       HINSTANCE      hInstLib ;
00134       HANDLE         hSnapShot ;
00135       MODULEENTRY32  moduleentry ;
00136       HANDLE         hProcess ;
00137           BOOL                   bFlag;
00138       
00139 
00140           hProcess = ::GetCurrentProcess();
00141           if (!hProcess)
00142                   return FALSE;
00143                 
00144       // ToolHelp Function Pointers.
00145       HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
00146       BOOL (WINAPI *lpfModule32First)(HANDLE,LPMODULEENTRY32) ;
00147       BOOL (WINAPI *lpfModule32Next)(HANDLE,LPMODULEENTRY32) ;
00148 
00149       // PSAPI Function Pointers.
00150       BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *,
00151          DWORD, LPDWORD );
00152         
00153       osver.dwOSVersionInfoSize = sizeof( osver ) ;
00154       if( !GetVersionEx( &osver ) )
00155       {
00156          return FALSE ;
00157       }
00158 
00159         
00160       // If Windows NT:
00161       if( osver.dwPlatformId == VER_PLATFORM_WIN32_NT )
00162       {
00163          hInstLib = LoadLibraryA( "PSAPI.DLL" ) ;
00164          if( hInstLib == NULL )
00165             return FALSE ;
00166 
00167          // Get procedure addresses.
00168          lpfEnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *,
00169             DWORD, LPDWORD)) GetProcAddress( hInstLib,
00170             "EnumProcessModules" ) ;
00171          if(!lpfEnumProcessModules) {
00172                          FreeLibrary( hInstLib );
00173                          return FALSE ;
00174          }
00175          if( !lpfEnumProcessModules( hProcess, modules, modsize, needed ) ) {
00176                          FreeLibrary( hInstLib ) ;
00177                          return FALSE;
00178          }
00179          FreeLibrary( hInstLib ) ;
00180           }
00181           else if( osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
00182                   hInstLib = LoadLibraryA( "Kernel32.DLL" ) ;
00183                   if( hInstLib == NULL )
00184                           return FALSE ;                
00185                   
00186          lpfCreateToolhelp32Snapshot=
00187             (HANDLE(WINAPI *)(DWORD,DWORD))
00188             GetProcAddress( hInstLib,
00189             "CreateToolhelp32Snapshot" ) ;
00190          lpfModule32First=
00191             (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32))
00192             GetProcAddress( hInstLib, "Module32First" ) ;
00193          lpfModule32Next=
00194             (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32))
00195             GetProcAddress( hInstLib, "Module32Next" ) ;
00196          if( lpfModule32Next == NULL ||
00197             lpfModule32First == NULL ||
00198             lpfCreateToolhelp32Snapshot == NULL )
00199          {
00200             FreeLibrary( hInstLib ) ;
00201             return FALSE ;
00202          }
00203                  hSnapShot = lpfCreateToolhelp32Snapshot(
00204             TH32CS_SNAPMODULE, 0 ) ;
00205          if( hSnapShot == INVALID_HANDLE_VALUE )
00206          {
00207             FreeLibrary( hInstLib ) ;
00208             return FALSE ;
00209          }
00210                  moduleentry.dwSize = sizeof(MODULEENTRY32);
00211                  bFlag = lpfModule32First( hSnapShot, &moduleentry );
00212                  unsigned int cntMod = 0;
00213                  while (bFlag) {
00214                          if ( (modsize/sizeof(HMODULE)) > cntMod) {
00215                                 modules[cntMod++] = moduleentry.hModule;
00216                          }
00217                          bFlag = lpfModule32Next( hSnapShot, &moduleentry );
00218                  }
00219                  *needed = cntMod*sizeof(HMODULE);
00220                  FreeLibrary( hInstLib ) ;
00221           }
00222           else {
00223                   return FALSE;
00224           }
00225           return TRUE;
00226                  
00227 
00228 }
00229 
00230 BOOL CDLLInfoDlg::OnInitDialog() 
00231 {
00232         CDialog::OnInitDialog();
00233         
00234         CRect rect;
00235         m_DLLList.GetClientRect(&rect);
00236         m_DLLList.InsertColumn(0, _T("Dynamic Library Path"), LVCFMT_LEFT, rect.Size().cx-::GetSystemMetrics(SM_CXVSCROLL));
00237         // TODO: Add extra initialization here
00238         HMODULE modules[1024];
00239         DWORD   needed;
00240         bool    success = true;
00241 
00242         if (EnumModules(modules, sizeof(modules), &needed)) {
00243                 if (needed > sizeof(modules)) {
00244                         success = false;                        // Not so nice...
00245                 }
00246                 for (unsigned int i=0; i< ((needed/sizeof(HMODULE))-1); i++) {
00247                         TCHAR moduleName[255];
00248                         if (::GetModuleFileName(modules[i], moduleName, (sizeof(moduleName)/sizeof(TCHAR)) )) {
00249                                 m_DLLList.InsertItem(i, moduleName);
00250                         }
00251                         else {
00252                                 success = false;
00253                         }
00254                 }
00255         }
00256         else {
00257                 success = false;
00258         }
00259         
00260         if (!success) {
00261                 AfxMessageBox(_T("Error in EnumProcessModules()."));
00262         }
00263         return TRUE;  // return TRUE unless you set the focus to a control
00264                       // EXCEPTION: OCX Property Pages should return FALSE
00265 }
00266 void CAboutDlg::OnEnChangeRichedit21()
00267 {
00268         // TODO:  If this is a RICHEDIT control, the control will not
00269         // send this notification unless you override the CDialog::OnInitDialog()
00270         // function and call CRichEditCtrl().SetEventMask()
00271         // with the ENM_CHANGE flag ORed into the mask.
00272 
00273         // TODO:  Add your control notification handler code here
00274 }