00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "CATOSFuncs.h"
00015 #include "CATInternal.h"
00016 #include "CATStringTableCore.h"
00017
00018
00019
00020
00021
00022
00023 void CATInvalidateRect( CATWND window,
00024 const CATRect& rect )
00025 {
00026 RECT wRect = *(RECT*)&(CATRECT)rect;
00027 if (::IsWindow(window))
00028 {
00029 ::InvalidateRect(window,&wRect,FALSE);
00030 }
00031 }
00032
00033 BOOL CALLBACK FindFirstMonitor( HMONITOR hMonitor,
00034 HDC ,
00035 LPRECT ,
00036 LPARAM dwData)
00037 {
00038 HMONITOR *monitor = (HMONITOR*)dwData;
00039 *monitor = hMonitor;
00040 return FALSE;
00041 }
00042
00043 CATRect GetPrimaryMonitorRect()
00044 {
00045 HMONITOR primaryMonitor = 0;
00046 EnumDisplayMonitors(0,0,FindFirstMonitor,LPARAM(&primaryMonitor));
00047
00048 MONITORINFO monInfo;
00049 memset(&monInfo,0,sizeof(MONITORINFO));
00050 monInfo.cbSize = sizeof(MONITORINFO);
00051 ::GetMonitorInfo(primaryMonitor,&monInfo);
00052
00053 CATRect primaryRect = *(CATRECT*)&monInfo.rcWork;
00054 return primaryRect;
00055 }
00056
00057
00058 void CATPostQuit( CATInt32 exitCode)
00059 {
00060 ::PostQuitMessage(exitCode);
00061 }
00062
00063
00064 CATResult CATExecute(const CATWChar* shellCommand, CATWND wnd)
00065 {
00066 CATInt32 result = (CATInt32)(UINT_PTR)ShellExecute(wnd,L"open", shellCommand,0,0,SW_SHOW);
00067 if (result > 32)
00068 {
00069 return CAT_SUCCESS;
00070 }
00071
00072 switch (result)
00073 {
00074 case SE_ERR_OOM:
00075 case 0:
00076 return CATRESULT(CAT_ERR_OUT_OF_MEMORY);
00077
00078
00079 case ERROR_FILE_NOT_FOUND:
00080 return CATRESULTFILE(CAT_ERR_FILE_DOES_NOT_EXIST, shellCommand);
00081
00082 case ERROR_BAD_FORMAT:
00083 return CATRESULTFILE(CAT_ERR_FILE_CORRUPTED,shellCommand);
00084
00085 case SE_ERR_ACCESSDENIED:
00086 return CATRESULTFILE(CAT_ERR_FILE_ACCESS_DENIED,shellCommand);
00087
00088 case SE_ERR_PNF:
00089 return CATRESULTFILE(CAT_ERR_PATH_DOES_NOT_EXIST, shellCommand);
00090
00091 default:
00092 return CATRESULTFILE(CAT_ERR_EXECUTE_FAILED,shellCommand);
00093 }
00094 }
00095
00096 CATMODKEY GetModifierKeys()
00097 {
00098 CATMODKEY modKey = (((::GetKeyState(VK_CONTROL) & 0x8000 ) ? CATMODKEY_CTRL : CATMODKEY_NONE) |
00099 ((::GetKeyState(VK_SHIFT) & 0x8000 ) ? CATMODKEY_SHIFT: CATMODKEY_NONE) |
00100 ((::GetKeyState(VK_MENU) & 0x8000 ) ? CATMODKEY_ALT : CATMODKEY_NONE));
00101 return modKey;
00102 };
00103
00104
00105 CATResult OSLoadIconImage(const CATWChar* appPath,CATICON* icon, CATString& appName)
00106 {
00107 SHFILEINFO shfi;
00108 if (!SHGetFileInfo( appPath, 0, &shfi, sizeof( SHFILEINFO ),SHGFI_DISPLAYNAME|SHGFI_ICON | SHGFI_LARGEICON))
00109 {
00110 return CAT_ERR_FILE_NOT_FOUND;
00111 }
00112
00113 if (icon != 0)
00114 {
00115 *icon = shfi.hIcon;
00116 }
00117
00118 appName = shfi.szDisplayName;
00119
00120 DWORD dummyZero = 0;
00121 CATUInt32 infoSize = ::GetFileVersionInfoSize(appPath,&dummyZero);
00122
00123 struct LANGANDCODEPAGE {
00124 WORD wLanguage;
00125 WORD wCodePage;
00126 } *lpTranslate;
00127
00128 UINT cbTranslate = sizeof(lpTranslate);
00129
00130 if (infoSize > 0)
00131 {
00132 CATUInt8* dataBuffer = new CATUInt8[infoSize*sizeof(CATWChar)];
00133 if (::GetFileVersionInfo(appPath,dummyZero,infoSize,dataBuffer))
00134 {
00135
00136 VerQueryValue(dataBuffer,
00137 L"\\VarFileInfo\\Translation",
00138 (LPVOID*)&lpTranslate,
00139 &cbTranslate);
00140
00141 CATUInt32 langCode = (((CATUInt32)lpTranslate[0].wLanguage) << 16) | lpTranslate[0].wCodePage;
00142 CATString verPath = L"\\StringFileInfo\\";
00143 verPath.AppendHex(langCode,false);
00144 verPath << L"\\ProductName";
00145
00146 CATWChar* prodVerString = 0;
00147 unsigned int prodVerLen = 0;
00148
00149 VerQueryValue( dataBuffer,
00150 verPath,
00151 (LPVOID*)&prodVerString,
00152 &prodVerLen);
00153
00154 if (prodVerString)
00155 appName = prodVerString;
00156 }
00157
00158 delete [] dataBuffer;
00159 }
00160
00161
00162 return CAT_SUCCESS;
00163 }
00164
00165 CATResult OSGetWindowIcon(const CATWChar* windowName,CATICON* icon)
00166 {
00167 HWND hwnd = ::FindWindow(0,windowName);
00168 if (hwnd = 0)
00169 return CAT_ERR_FILE_NOT_FOUND;
00170
00171 (*icon) = (CATICON)::GetClassLong(hwnd,GCL_HICON);
00172
00173 return CAT_SUCCESS;
00174 }
00175
00176 CATString GetInstallLoc(const CATWChar* uninstKey)
00177 {
00178 CATString loc;
00179
00180 CATString regPath;
00181 regPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
00182 regPath << uninstKey;
00183
00184 HKEY hKey = 0;
00185 if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,regPath,0,KEY_READ,&hKey))
00186 {
00187 DWORD type = 0;
00188 DWORD size = 1024*2;
00189
00190 RegQueryValueEx(hKey,
00191 L"InstallLocation",
00192 0,
00193 &type,
00194 (LPBYTE)loc.GetUnicodeBuffer(size/2+2),&size);
00195 loc.ReleaseBuffer();
00196
00197 ::RegCloseKey(hKey);
00198 }
00199
00200
00201 return loc;
00202 }
00203
00204 CATString GetSoftwareReg(const CATWChar* regString)
00205 {
00206 CATString loc;
00207
00208 CATString tmpStr = regString;
00209 CATString regName = tmpStr.GetFilenameExt();
00210 CATString regPath = tmpStr.GetDriveDirectory();
00211
00212 HKEY hKey = 0;
00213 if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,regPath,0,KEY_READ,&hKey))
00214 {
00215 DWORD type = 0;
00216 DWORD size = 1024*2;
00217
00218 RegQueryValueEx(hKey,
00219 regName,
00220 0,
00221 &type,
00222 (LPBYTE)loc.GetUnicodeBuffer(size/2+2),&size);
00223 loc.ReleaseBuffer();
00224
00225 ::RegCloseKey(hKey);
00226 }
00227
00228 return loc;
00229 }