Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmisc.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Applications Manager 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/applications/rapps/misc.c 00005 * PURPOSE: Misc functions 00006 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org) 00007 */ 00008 00009 #include "rapps.h" 00010 00011 00012 /* SESSION Operation */ 00013 #define EXTRACT_FILLFILELIST 0x00000001 00014 #define EXTRACT_EXTRACTFILES 0x00000002 00015 00016 static HANDLE hLog = NULL; 00017 00018 typedef struct 00019 { 00020 int erfOper; 00021 int erfType; 00022 BOOL fError; 00023 } ERF, *PERF; 00024 00025 struct FILELIST 00026 { 00027 LPSTR FileName; 00028 struct FILELIST *next; 00029 BOOL DoExtract; 00030 }; 00031 00032 typedef struct 00033 { 00034 INT FileSize; 00035 ERF Error; 00036 struct FILELIST *FileList; 00037 INT FileCount; 00038 INT Operation; 00039 CHAR Destination[MAX_PATH]; 00040 CHAR CurrentFile[MAX_PATH]; 00041 CHAR Reserved[MAX_PATH]; 00042 struct FILELIST *FilterList; 00043 } SESSION; 00044 00045 HRESULT (WINAPI *pfnExtract)(SESSION *dest, LPCSTR szCabName); 00046 00047 00048 INT 00049 GetSystemColorDepth(VOID) 00050 { 00051 DEVMODE pDevMode; 00052 INT ColorDepth; 00053 00054 pDevMode.dmSize = sizeof(DEVMODE); 00055 pDevMode.dmDriverExtra = 0; 00056 00057 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &pDevMode)) 00058 { 00059 /* TODO: Error message */ 00060 return ILC_COLOR; 00061 } 00062 00063 switch (pDevMode.dmBitsPerPel) 00064 { 00065 case 32: ColorDepth = ILC_COLOR32; break; 00066 case 24: ColorDepth = ILC_COLOR24; break; 00067 case 16: ColorDepth = ILC_COLOR16; break; 00068 case 8: ColorDepth = ILC_COLOR8; break; 00069 case 4: ColorDepth = ILC_COLOR4; break; 00070 default: ColorDepth = ILC_COLOR; break; 00071 } 00072 00073 return ColorDepth; 00074 } 00075 00076 int 00077 GetWindowWidth(HWND hwnd) 00078 { 00079 RECT Rect; 00080 00081 GetWindowRect(hwnd, &Rect); 00082 return (Rect.right - Rect.left); 00083 } 00084 00085 int 00086 GetWindowHeight(HWND hwnd) 00087 { 00088 RECT Rect; 00089 00090 GetWindowRect(hwnd, &Rect); 00091 return (Rect.bottom - Rect.top); 00092 } 00093 00094 int 00095 GetClientWindowWidth(HWND hwnd) 00096 { 00097 RECT Rect; 00098 00099 GetClientRect(hwnd, &Rect); 00100 return (Rect.right - Rect.left); 00101 } 00102 00103 int 00104 GetClientWindowHeight(HWND hwnd) 00105 { 00106 RECT Rect; 00107 00108 GetClientRect(hwnd, &Rect); 00109 return (Rect.bottom - Rect.top); 00110 } 00111 00112 VOID 00113 CopyTextToClipboard(LPCWSTR lpszText) 00114 { 00115 if(OpenClipboard(NULL)) 00116 { 00117 HGLOBAL ClipBuffer; 00118 WCHAR *Buffer; 00119 00120 EmptyClipboard(); 00121 ClipBuffer = GlobalAlloc(GMEM_DDESHARE, (wcslen(lpszText) + 1) * sizeof(TCHAR)); 00122 Buffer = (WCHAR*)GlobalLock(ClipBuffer); 00123 wcscpy(Buffer, lpszText); 00124 GlobalUnlock(ClipBuffer); 00125 00126 SetClipboardData(CF_UNICODETEXT, ClipBuffer); 00127 00128 CloseClipboard(); 00129 } 00130 } 00131 00132 VOID 00133 SetWelcomeText(VOID) 00134 { 00135 WCHAR szText[MAX_STR_LEN*3]; 00136 00137 LoadStringW(hInst, IDS_WELCOME_TITLE, szText, sizeof(szText) / sizeof(WCHAR)); 00138 NewRichEditText(szText, CFE_BOLD); 00139 00140 LoadStringW(hInst, IDS_WELCOME_TEXT, szText, sizeof(szText) / sizeof(WCHAR)); 00141 InsertRichEditText(szText, 0); 00142 00143 LoadStringW(hInst, IDS_WELCOME_URL, szText, sizeof(szText) / sizeof(WCHAR)); 00144 InsertRichEditText(szText, CFM_LINK); 00145 } 00146 00147 VOID 00148 ShowPopupMenu(HWND hwnd, UINT MenuID) 00149 { 00150 HMENU hPopupMenu = GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID)), 0); 00151 POINT pt; 00152 00153 GetCursorPos(&pt); 00154 00155 SetForegroundWindow(hwnd); 00156 TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL); 00157 00158 DestroyMenu(hPopupMenu); 00159 } 00160 00161 BOOL 00162 StartProcess(LPWSTR lpPath, BOOL Wait) 00163 { 00164 PROCESS_INFORMATION pi; 00165 STARTUPINFOW si; 00166 DWORD dwRet; 00167 MSG msg; 00168 00169 ZeroMemory(&si, sizeof(si)); 00170 si.cb = sizeof(si); 00171 si.wShowWindow = SW_SHOW; 00172 00173 if (!CreateProcessW(NULL, lpPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) 00174 { 00175 return FALSE; 00176 } 00177 00178 CloseHandle(pi.hThread); 00179 if (Wait) EnableWindow(hMainWnd, FALSE); 00180 00181 while (Wait) 00182 { 00183 dwRet = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLEVENTS); 00184 if (dwRet == WAIT_OBJECT_0 + 1) 00185 { 00186 while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) 00187 { 00188 TranslateMessage(&msg); 00189 DispatchMessage(&msg); 00190 } 00191 } 00192 else 00193 { 00194 if (dwRet == WAIT_OBJECT_0 || dwRet == WAIT_FAILED) 00195 break; 00196 } 00197 } 00198 00199 CloseHandle(pi.hProcess); 00200 00201 if (Wait) 00202 { 00203 EnableWindow(hMainWnd, TRUE); 00204 SetForegroundWindow(hMainWnd); 00205 SetFocus(hMainWnd); 00206 } 00207 00208 return TRUE; 00209 } 00210 00211 00212 BOOL 00213 ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath) 00214 { 00215 HINSTANCE hCabinetDll; 00216 CHAR szCabName[MAX_PATH]; 00217 SESSION Dest; 00218 HRESULT Result; 00219 00220 hCabinetDll = LoadLibraryW(L"cabinet.dll"); 00221 if (hCabinetDll) 00222 { 00223 pfnExtract = (void *) GetProcAddress(hCabinetDll, "Extract"); 00224 if (pfnExtract) 00225 { 00226 ZeroMemory(&Dest, sizeof(SESSION)); 00227 00228 WideCharToMultiByte(CP_ACP, 0, lpOutputPath, -1, Dest.Destination, MAX_PATH, NULL, NULL); 00229 WideCharToMultiByte(CP_ACP, 0, lpCabName, -1, szCabName, MAX_PATH, NULL, NULL); 00230 Dest.Operation = EXTRACT_FILLFILELIST; 00231 00232 Result = pfnExtract(&Dest, szCabName); 00233 if (Result == S_OK) 00234 { 00235 Dest.Operation = EXTRACT_EXTRACTFILES; 00236 Result = pfnExtract(&Dest, szCabName); 00237 if (Result == S_OK) 00238 { 00239 FreeLibrary(hCabinetDll); 00240 return TRUE; 00241 } 00242 } 00243 } 00244 FreeLibrary(hCabinetDll); 00245 } 00246 00247 return FALSE; 00248 } 00249 00250 VOID 00251 InitLogs(VOID) 00252 { 00253 WCHAR szBuf[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\ReactOS Application Manager\\ReactOS Application Manager"; 00254 WCHAR szPath[MAX_PATH]; 00255 DWORD dwCategoryNum = 1; 00256 DWORD dwDisp, dwData; 00257 HKEY hKey; 00258 00259 if (!SettingsInfo.bLogEnabled) return; 00260 00261 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, 00262 szBuf, 0, NULL, 00263 REG_OPTION_NON_VOLATILE, 00264 KEY_WRITE, NULL, &hKey, &dwDisp) != ERROR_SUCCESS) 00265 { 00266 return; 00267 } 00268 00269 if (!GetCurrentDirectoryW(MAX_PATH, szPath)) return; 00270 wcscat(szPath, L"\\rapps.exe"); 00271 00272 if (RegSetValueExW(hKey, 00273 L"EventMessageFile", 00274 0, 00275 REG_EXPAND_SZ, 00276 (LPBYTE)szPath, 00277 (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) 00278 { 00279 RegCloseKey(hKey); 00280 return; 00281 } 00282 00283 dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | 00284 EVENTLOG_INFORMATION_TYPE; 00285 00286 if (RegSetValueExW(hKey, 00287 L"TypesSupported", 00288 0, 00289 REG_DWORD, 00290 (LPBYTE)&dwData, 00291 sizeof(DWORD)) != ERROR_SUCCESS) 00292 { 00293 RegCloseKey(hKey); 00294 return; 00295 } 00296 00297 if (RegSetValueExW(hKey, 00298 L"CategoryMessageFile", 00299 0, 00300 REG_EXPAND_SZ, 00301 (LPBYTE)szPath, 00302 (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS) 00303 { 00304 RegCloseKey(hKey); 00305 return; 00306 } 00307 00308 if (RegSetValueExW(hKey, 00309 L"CategoryCount", 00310 0, 00311 REG_DWORD, 00312 (LPBYTE)&dwCategoryNum, 00313 sizeof(DWORD)) != ERROR_SUCCESS) 00314 { 00315 RegCloseKey(hKey); 00316 return; 00317 } 00318 00319 RegCloseKey(hKey); 00320 00321 hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager"); 00322 } 00323 00324 00325 VOID 00326 FreeLogs(VOID) 00327 { 00328 if (hLog) DeregisterEventSource(hLog); 00329 } 00330 00331 00332 BOOL 00333 WriteLogMessage(WORD wType, DWORD dwEventID, LPWSTR lpMsg) 00334 { 00335 if (!SettingsInfo.bLogEnabled) return TRUE; 00336 00337 if (!ReportEventW(hLog, 00338 wType, 00339 0, 00340 dwEventID, 00341 NULL, 00342 1, 00343 0, 00344 (LPCWSTR*)&lpMsg, 00345 NULL)) 00346 { 00347 return FALSE; 00348 } 00349 00350 return TRUE; 00351 } Generated on Sun May 27 2012 04:16:46 for ReactOS by
1.7.6.1
|