Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
deskstat.cpp
Package: shell.rar [view]
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 188k
Category:
Windows Kernel
Development Platform:
Visual C++
- #include "stdafx.h"
- #pragma hdrstop
- #ifdef _WIN64
- extern "C" char * __cdecl StrTokEx(char ** pstring, const char * control);
- #else
- #include <iert.h>
- #endif
- #define DXA_GROWTH_CONST 10
- #define ZINDEX_START 1000
- #define MAXID_LENGTH 10 //Maximum number of digits in ID string plus 1.
- #if 0
- #define TF_DESKSTAT TF_CUSTOM2
- #define TF_DYNAMICHTML TF_CUSTOM1
- #else
- #define TF_DESKSTAT 0
- #define TF_DYNAMICHTML 0
- #endif
- IActiveDesktop *g_pActiveDesk = NULL;
- #define c_szRegStrDesktop REGSTR_PATH_DESKTOP
- #define c_szWallpaper REG_VAL_GENERAL_WALLPAPER
- #define c_szBackupWallpaper REG_VAL_GENERAL_BACKUPWALLPAPER
- #define c_szPattern TEXT("Pattern")
- #define c_szTileWall REG_VAL_GENERAL_TILEWALLPAPER
- #define c_szWallpaperStyle REG_VAL_GENERAL_WALLPAPERSTYLE
- #define c_szWallpaperTime REG_VAL_GENERAL_WALLPAPERTIME
- #define c_szRefreshDesktop TEXT("RefreshDesktop")
- #define c_szBufferedRefresh TEXT("BufferedRefresh")
- #define COMP_TYPE 0x00000003
- #define COMP_SELECTED 0x00002000
- #define COMP_NOSCROLL 0x00004000
- #ifdef DEBUG
- #define ENTERPROC EnterProcDS
- #define EXITPROC ExitProcDS
- void EnterProcDS(DWORD dwTraceLevel, LPSTR szFmt, ...);
- void ExitProcDS(DWORD dwTraceLevel, LPSTR szFmt, ...);
- extern DWORD g_dwDeskStatTrace;
- #else
- #ifndef CCOVER
- #pragma warning(disable:4002)
- #define ENTERPROC()
- #define EXITPROC()
- #else // ccover buildi
- // these are needed because of a bug in cl.exe that results in improper processing
- // of #pragma when run with cl -P, and then compiling
- #define ENTERPROC 1 ? (void) 0 : (void)
- #define EXITPROC 1 ? (void) 0 : (void)
- #endif //end of ccover
- #endif
- MAKE_CONST_BSTR(s_sstrBeforeEnd, L"BeforeEnd");
- MAKE_CONST_BSTR(s_sstrDeskMovr, L"DeskMovr");
- MAKE_CONST_BSTR(s_sstrDeskMovrW, L"DeskMovrW");
- MAKE_CONST_BSTR(s_sstrclassid, L"classid");
- MAKE_CONST_BSTR(s_sstrEmpty, L"");
- STDAPI ParseDesktopComponent(HWND hwndOwner, LPWSTR wszURL, COMPONENT *pInfo);
- WCHAR wUnicodeBOM = 0xfeff; // Little endian unicode Byte Order Mark.First byte:0xff, Second byte: 0xfe.
- CReadFileObj::CReadFileObj(LPCTSTR lpszFileName)
- {
- //Open the file
- if((_hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,
- NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, 0)) != INVALID_HANDLE_VALUE)
- {
- WCHAR wBOM;
- DWORD dwBytesRead = 0;
- if((ReadFile(_hFile, (LPVOID)&wBOM, sizeof(WCHAR), &dwBytesRead, NULL)) &&
- (dwBytesRead == sizeof(WCHAR)))
- {
- if(wBOM == wUnicodeBOM)
- _iCharset = UNICODE_HTML_CHARSET;
- else
- {
- //Note: Anything other than the little endian unicode file is treated as ansi.
- _iCharset = ANSI_HTML_CHARSET;
- SetFilePointer(_hFile, 0L, NULL, FILE_BEGIN); //Seek to the begining of the file
- }
- }
- }
- }
- CReadFileObj::~CReadFileObj()
- {
- if(_hFile != INVALID_HANDLE_VALUE)
- {
- CloseHandle(_hFile);
- _hFile = NULL;
- }
- }
- //
- // This will read and if necessary convert between ANSI and UNICODE
- //
- //
- // NOTE: The uiCharsToRead must be atleast one less than the size of the buffer (lpwszBuff)
- // because one null may be written at the end of the buffer by SHAnsiToUnicode().
- //
- HRESULT CReadFileObj::FileReadAndConvertChars(int iDestCharset, LPWSTR lpwszBuff, UINT uiCharsToRead, UINT *puiCharsActuallyRead, UINT *puiCharsConverted)
- {
- HRESULT hres = S_OK;
- DWORD dwCharsRead = 0;
- DWORD dwTotalCharsConverted = 0;
- if(_hFile != INVALID_HANDLE_VALUE)
- {
- if(_iCharset == UNICODE_HTML_CHARSET)
- {
- if(iDestCharset == UNICODE_HTML_CHARSET)
- {
- hres = FileReadCharsW(lpwszBuff, uiCharsToRead, (UINT *)&dwCharsRead);
- dwTotalCharsConverted = dwCharsRead;
- }
- else
- {
- //Destination is ansi; Read the UNICODE source and convert to ANSI.
- WCHAR wszBuf[INTERNET_MAX_URL_LENGTH + 1]; //Temp buffer to read the UNICODE chars into.
- LPSTR lpszBuff = (LPSTR)lpwszBuff;
- DWORD dwTotalCharsToRead = (DWORD)uiCharsToRead;
- while(dwTotalCharsToRead)
- {
- DWORD dwCount;
- DWORD dwActuallyRead;
- // - 1 to give room for a null character at the end.
- dwCount = min(dwTotalCharsToRead, (ARRAYSIZE(wszBuf) - 1));
- if(ReadFile(_hFile, (LPSTR)wszBuf, dwCount*sizeof(WCHAR), &dwActuallyRead, NULL))
- {
- DWORD dwConverted;
- dwActuallyRead = dwActuallyRead/sizeof(WCHAR);
- //Null terminate the source buffer.
- wszBuf[dwActuallyRead] = L''; //UNICODE null terminate the source.
- //Convert what we just read.
- dwConverted = SHUnicodeToAnsi(wszBuf, lpszBuff, dwActuallyRead+1); //+1 for null termination
- //Update the count & stuff.
- lpszBuff += dwConverted - 1; //Subtract the null.
- dwTotalCharsToRead -= dwActuallyRead;
- dwCharsRead += dwActuallyRead;
- dwTotalCharsConverted += dwConverted - 1; //Subtract the null.
- if(dwActuallyRead < dwCount)
- break; //We have reached the end of file.
- }
- else
- {
- hres = E_FAIL;
- break;
- }
- }
- }
- }
- else
- {
- //Source file is ANSI. Check the Destination.
- if(iDestCharset == ANSI_HTML_CHARSET)
- {
- //Destination is ANSI too! Cool! No need for conversion!
- hres = FileReadCharsA((LPSTR)lpwszBuff, uiCharsToRead, (UINT *)&dwCharsRead);
- dwTotalCharsConverted = dwCharsRead;
- }
- else
- {
- //Destination is UNICODE! Read the ansi and convert it to UNICODE!
- char szBuf[INTERNET_MAX_URL_LENGTH + 1]; //Temp buffer to read the ansi chars into.
- DWORD dwTotalCharsToRead = (DWORD)uiCharsToRead;
- while(dwTotalCharsToRead)
- {
- DWORD dwCount;
- DWORD dwActuallyRead;
- // - 1 to give room for a null character at the end.
- dwCount = min(dwTotalCharsToRead, (ARRAYSIZE(szBuf) - 1));
- if(ReadFile(_hFile, (LPSTR)szBuf, dwCount, &dwActuallyRead, NULL))
- {
- DWORD dwConverted;
- //Null terminate the source buffer.
- szBuf[dwActuallyRead] = ''; //ANSI null terminate the source.
- //Convert what we just read.
- dwConverted = SHAnsiToUnicode(szBuf, lpwszBuff, dwActuallyRead+1); //+1 for null termination
- //Update the count & stuff.
- lpwszBuff += dwConverted - 1; //Subtract the null.
- dwTotalCharsToRead -= dwActuallyRead;
- dwCharsRead += dwActuallyRead;
- dwTotalCharsConverted += dwConverted - 1; //Subtract the null.
- if(dwActuallyRead < dwCount)
- break; //We have reached the end of file.
- }
- else
- {
- hres = E_FAIL;
- break;
- }
- } //while
- }
- }
- }
- else
- hres = E_FAIL; //The file handle is bad.
- *puiCharsActuallyRead = (UINT)dwCharsRead;
- *puiCharsConverted = (UINT)dwTotalCharsConverted;
- return hres;
- }
- HRESULT CReadFileObj::FileReadCharsA(LPSTR lpszBuff, UINT uiCharsToRead, UINT *puiCharsActuallyRead)
- {
- HRESULT hres = E_FAIL;
- DWORD dwCharsRead = 0;
- if ((_hFile != INVALID_HANDLE_VALUE) &&
- (_iCharset == ANSI_HTML_CHARSET) &&
- ReadFile(_hFile, (LPVOID)lpszBuff, (DWORD)(uiCharsToRead), &dwCharsRead, NULL))
- {
- dwCharsRead = dwCharsRead; //get the number of wchars read.
- hres = S_OK;
- }
- *puiCharsActuallyRead = (UINT)dwCharsRead;
- return hres;
- }
- HRESULT CReadFileObj::FileReadCharsW(LPWSTR lpwszBuff, UINT uiCharsToRead, UINT *puiCharsActuallyRead)
- {
- HRESULT hres = E_FAIL;
- DWORD dwCharsRead = 0;
- if ((_hFile != INVALID_HANDLE_VALUE) &&
- (_iCharset == UNICODE_HTML_CHARSET) &&
- ReadFile(_hFile, (LPVOID)lpwszBuff, (DWORD)(uiCharsToRead*sizeof(WCHAR)), &dwCharsRead, NULL))
- {
- dwCharsRead = dwCharsRead/sizeof(WCHAR); //get the number of wchars read.
- hres = S_OK;
- }
- *puiCharsActuallyRead = (UINT)dwCharsRead;
- return hres;
- }
- HRESULT CReadFileObj::FileSeekChars(LONG lCharOffset, DWORD dwOrigin)
- {
- HRESULT hres = E_FAIL;
- if(_hFile != INVALID_HANDLE_VALUE)
- {
- if(SetFilePointer(_hFile,
- lCharOffset*((_iCharset == UNICODE_HTML_CHARSET) ? sizeof(WCHAR) : sizeof(char)),
- NULL,
- dwOrigin) != INVALID_SET_FILE_POINTER)
- hres = S_OK;
- }
- return hres;
- }
- HRESULT CReadFileObj::FileGetCurCharOffset(LONG *plCharOffset)
- {
- HRESULT hres = E_FAIL;
- DWORD dwByteOffset = 0;
- *plCharOffset = 0;
- if(_hFile != INVALID_HANDLE_VALUE)
- {
- if((dwByteOffset = SetFilePointer(_hFile,
- 0L,
- NULL,
- FILE_CURRENT)) != INVALID_SET_FILE_POINTER)
- {
- *plCharOffset = dwByteOffset/((_iCharset == UNICODE_HTML_CHARSET) ? sizeof(WCHAR) : sizeof(char));
- hres = S_OK;
- }
- }
- return hres;
- }
- int GetIntFromReg(HKEY hKey,
- LPCTSTR lpszSubkey,
- LPCTSTR lpszNameValue,
- int iDefault)
- {
- TCHAR szValue[20];
- DWORD dwSizeofValueBuff = SIZEOF(szValue);
- int iRetValue = iDefault;
- DWORD dwType;
- if ((SHGetValue(hKey, lpszSubkey, lpszNameValue, &dwType,(LPBYTE)szValue,
- &dwSizeofValueBuff) == ERROR_SUCCESS) && dwSizeofValueBuff)
- {
- if (dwType == REG_SZ)
- {
- iRetValue = (int)StrToInt(szValue);
- }
- }
- return iRetValue;
- }
- BOOL GetStringFromReg(HKEY hkey,
- LPCTSTR lpszSubkey,
- LPCTSTR lpszValueName,
- LPCTSTR lpszDefault,
- LPTSTR lpszValue,
- DWORD cchSizeofValueBuff)
- {
- BOOL fRet = FALSE;
- DWORD dwType;
- cchSizeofValueBuff *= sizeof(TCHAR);
- if (SHGetValue(hkey, lpszSubkey, lpszValueName, &dwType, lpszValue, &cchSizeofValueBuff) == ERROR_SUCCESS)
- {
- fRet = TRUE;
- }
- //
- // On failure use the default string.
- //
- if (!fRet && lpszDefault)
- {
- lstrcpy(lpszValue, lpszDefault);
- }
- return fRet;
- }
- void GetWallpaperFileTime(LPCTSTR pszWallpaper, LPFILETIME lpftFileTime)
- {
- HANDLE hFile;
- BOOL fRet = FALSE;
- if((hFile = CreateFile(pszWallpaper, GENERIC_READ, FILE_SHARE_READ,
- NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, 0)) != INVALID_HANDLE_VALUE)
- {
- fRet = GetFileTime(hFile, NULL, NULL, lpftFileTime);
- CloseHandle(hFile);
- }
- if (!fRet)
- ZeroMemory(lpftFileTime, SIZEOF(FILETIME));
- // no return value
- }
- BOOL HasWallpaperReallyChanged(LPCTSTR pszRegKey, LPTSTR pszOldWallpaper, LPTSTR pszBackupWallpaper, DWORD dwOldWallpaperStyle, DWORD dwNewWallpaperStyle)
- {
- // we default to TRUE here.
- if ((dwOldWallpaperStyle == dwNewWallpaperStyle)
- && (0 == lstrcmpi(pszOldWallpaper, pszBackupWallpaper)))
- {
- // The wallpaper filename and style hasn't changed.
- // But, the content of this file could have changed.
- // See if the content has changed by looking at the
- // last-written date and time stamp on this file.
- FILETIME ftOld, ftBack;
- DWORD dwType, cbBack = SIZEOF(ftBack);
- // if either of these fail, then they will
- // remain Zero so the compare will
- // be successful.
- GetWallpaperFileTime(pszOldWallpaper, &ftOld);
- if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, pszRegKey, c_szWallpaperTime, &dwType, &ftBack, &cbBack))
- ZeroMemory(&ftBack, SIZEOF(ftBack));
- //Get the last written time of the backup wallpaper from registry
- if (ftOld.dwLowDateTime == ftBack.dwLowDateTime
- && (ftOld.dwHighDateTime == ftBack.dwHighDateTime))
- // everything is the same!
- return FALSE;
- }
- return TRUE;
- }
- //-------------------------------------------------------------------------------------------------------------//
- // Function: ReadWallpaperStyleFromReg()
- //
- // This function reads the "TileWallpaper" and the "WallpaperStyle" from the given location
- // in the registry.
- //
- //-------------------------------------------------------------------------------------------------------------//
- void ReadWallpaperStyleFromReg(LPCTSTR pszRegKey, DWORD *pdwWallpaperStyle, BOOL fIgnorePlatforms)
- {
- //Do not read "Stretch" bits for older platforms.
- if(fIgnorePlatforms || g_bRunOnMemphis || g_bRunOnNT5)
- *pdwWallpaperStyle = GetIntFromReg(HKEY_CURRENT_USER, pszRegKey, c_szWallpaperStyle, WPSTYLE_CENTER);
- else
- *pdwWallpaperStyle = WPSTYLE_CENTER;
- if (GetIntFromReg(HKEY_CURRENT_USER, pszRegKey, c_szTileWall, WPSTYLE_TILE))
- {
- //
- // "Tile" overrides the "Stretch" style.
- //
- *pdwWallpaperStyle = WPSTYLE_TILE;
- }
- // else, STRETCH or CENTER.
- }
- BOOL CActiveDesktop::_IsDisplayInSafeMode(void)
- {
- WCHAR wszDisplay[MAX_PATH];
- DWORD dwcch = MAX_PATH;
- return (SUCCEEDED(GetScheme(wszDisplay, &dwcch, SCHEME_GLOBAL | SCHEME_DISPLAY))
- && (0 == StrCmpW(wszDisplay, REG_DESKCOMP_SAFEMODE_SUFFIX_L)));
- }
- BOOL ReadPolicyForWallpaper(LPTSTR lpszPolicyForWallpaper, DWORD dwSizeofBuff)
- {
- TCHAR szWallpaperName[MAX_PATH];
- DWORD dwType;
- if(!lpszPolicyForWallpaper)
- {
- lpszPolicyForWallpaper = szWallpaperName;
- dwSizeofBuff = ARRAYSIZE(szWallpaperName);
- }
- if((SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_WP_POLICY, c_szWallpaper, &dwType,(LPBYTE)lpszPolicyForWallpaper,
- &dwSizeofBuff) == ERROR_SUCCESS) && dwSizeofBuff)
- return TRUE; //Policy is there!
- else
- return FALSE; //No policy is set!
- }
- BOOL ReadPolicyForWPStyle(LPDWORD lpdwStyle)
- {
- DWORD dwStyle;
- DWORD dwType;
- TCHAR szValue[20];
- DWORD dwSizeofValueBuff = ARRAYSIZE(szValue);
- BOOL fRet = FALSE;
- // The caller can passin a NULL, if they are not interested in the actual value and they just
- // want to know if this policy is set or not.
- if(!lpdwStyle)
- lpdwStyle = &dwStyle;
- if ((SHGetValue(HKEY_CURRENT_USER, REGSTR_PATH_WP_POLICY, c_szWallpaperStyle, &dwType,(LPBYTE)szValue,
- &dwSizeofValueBuff) == ERROR_SUCCESS) && dwSizeofValueBuff)
- {
- if(dwType == REG_SZ)
- {
- *lpdwStyle = (DWORD)StrToInt(szValue);
- fRet = TRUE;
- }
- }
- return fRet;
- }
- void CActiveDesktop::_ReadWallpaper(BOOL fActiveDesktop)
- {
- ENTERPROC(2, "DS ReadWallpaper()");
- TCHAR lpszDeskcomp[MAX_PATH];
- GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_GENERAL, _pszScheme);
- _fPolicyForWPName = ReadPolicyForWallpaper(_szSelectedWallpaper, ARRAYSIZE(_szSelectedWallpaper));
- _fPolicyForWPStyle = ReadPolicyForWPStyle(&_wpo.dwStyle);
- //
- // Read in the wallpaper and style from the appropriate registry location.
- //
- LPCTSTR pszRegKey;
- if (fActiveDesktop)
- {
- pszRegKey = (LPCTSTR)lpszDeskcomp;
- TCHAR szOldWallpaper[MAX_PATH];
- DWORD dwOldWallpaperStyle;
- // Read the Wallpaper from the Old location.
- GetStringFromReg(HKEY_CURRENT_USER, c_szRegStrDesktop, c_szWallpaper, c_szNULL, szOldWallpaper, ARRAYSIZE(szOldWallpaper));
- // Read wallpaper style from the old location.
- ReadWallpaperStyleFromReg((LPCTSTR)c_szRegStrDesktop, &dwOldWallpaperStyle, FALSE);
- // Read the wallpaper from the new location too!
- if((!_fPolicyForWPName) || (_IsDisplayInSafeMode()))
- {
- if (!GetStringFromReg(HKEY_CURRENT_USER, pszRegKey, c_szWallpaper, szOldWallpaper, _szSelectedWallpaper, ARRAYSIZE(_szSelectedWallpaper)))
- {
- pszRegKey = c_szRegStrDesktop;
- }
- }
- //Read wallpaper style from the new location too!
- if(!_fPolicyForWPStyle)
- ReadWallpaperStyleFromReg(pszRegKey, &_wpo.dwStyle, FALSE);
- //If there is a Safe mode scheme here do NOT attempt to change wallpaper
- if((!_IsDisplayInSafeMode()) && (!_fPolicyForWPName))
- {
- //Read what is stored as "Backup" wallpaper.
- GetStringFromReg(HKEY_CURRENT_USER, pszRegKey, c_szBackupWallpaper, szOldWallpaper, _szBackupWallpaper, ARRAYSIZE(_szBackupWallpaper));
- //See if the Old wallpaper is differnet from the backed up wallpaper
- if(HasWallpaperReallyChanged(pszRegKey, szOldWallpaper, _szBackupWallpaper, dwOldWallpaperStyle, _wpo.dwStyle))
- {
- //They are different. This means that some other app has changed the "Old" wallpaper
- //after the last time we backed it up in the registry.
- // Make this wallpaper as the Selected wallpaper!
- #ifdef WE_WANT_DEFAULT_WALLPAPER
- // The following hack is needed only if we want default wallpapers. For example, when
- // we port shell code to Win2000 millenium, we may want a default wallpaper in which case,
- // we need to enable the following hack and also in the deskcls.cpp file.
- //
- // This is a kinda hack, but the best possible solution right now. The scenario is as follows.
- // The Memphis setup guys replace what the user specifies as the wallpaper in the old location
- // and restore it after setup is complete. But, SetDefaultWallpaper() gets called bet. these
- // two times and we are supposed to take a decision on whether to set the default htm wallpaper or not,
- // depending on what the user had set before the installation. The solution is to delay making
- // this decision until after the setup guys have restored the user's wallpaper. We do this in
- // CActiveDesktop::_ReadWallpaper(). We specify that SetDefaultWallpaper() was called by setting
- // the backup wallpaper in the new location to the default wallpaper.
- TCHAR szDefaultWallpaper[MAX_PATH];
- GetDefaultWallpaper(szDefaultWallpaper, SIZECHARS(szDefaultWallpaper));
- if(lstrcmp(_szBackupWallpaper, szDefaultWallpaper) == 0
- && (!szOldWallpaper[0] || lstrcmp(szOldWallpaper, g_szNone) == 0))
- {
- lstrcpy(_szSelectedWallpaper, szDefaultWallpaper);
- }
- else
- {
- lstrcpy(_szSelectedWallpaper, szOldWallpaper);
- }
- #else // WE_WANT_DEFAULT_WALLPAPER
- lstrcpy(_szSelectedWallpaper, szOldWallpaper);
- #endif // WE_WANT_DEFAULT_WALLPAPER
- _wpo.dwStyle = dwOldWallpaperStyle;
- _fWallpaperDirty = TRUE;
- _fWallpaperChangedDuringInit = TRUE;
- }
- }
- //Make a backup of the "Old" wallpaper
- lstrcpy(_szBackupWallpaper, szOldWallpaper);
- }
- else
- {
- pszRegKey = c_szRegStrDesktop; //Get it from the old location!
- //Since active desktop is not available, read wallpaper from old location.
- if(!_fPolicyForWPName)
- GetStringFromReg(HKEY_CURRENT_USER, pszRegKey, c_szWallpaper, c_szNULL, _szSelectedWallpaper, ARRAYSIZE(_szSelectedWallpaper));
- //Make a backup of the "Old" wallpaper
- lstrcpy(_szBackupWallpaper, _szSelectedWallpaper);
- //Read the wallpaper style
- if(!_fPolicyForWPStyle)
- ReadWallpaperStyleFromReg(pszRegKey, &_wpo.dwStyle, TRUE);
- }
- EXITPROC(2, "DS ReadWallpaper! (_szSelectedWP=>%s<)", _szSelectedWallpaper);
- }
- void CActiveDesktop::_ReadPattern(void)
- {
- ENTERPROC(2, "DS ReadPattern()");
- GetStringFromReg(HKEY_CURRENT_USER, c_szRegStrDesktop, c_szPattern, c_szNULL, _szSelectedPattern, ARRAYSIZE(_szSelectedPattern));
- EXITPROC(2, "DS ReadPattern! (_szSelectedPattern=>%s<)", _szSelectedPattern);
- }
- void CActiveDesktop::_ReadComponent(HKEY hkey, LPCTSTR pszComp)
- {
- ENTERPROC(2, "DS ReadComponent(hk=%08X,pszComp=>%s<)", hkey, pszComp);
- HKEY hkeyComp;
- if (RegOpenKeyEx(hkey, pszComp, 0, KEY_READ, &hkeyComp) == ERROR_SUCCESS)
- {
- DWORD cbSize, dwType;
- COMPONENTA comp;
- comp.dwSize = sizeof(COMPONENTA);
- //
- // Read in the source string.
- //
- cbSize = SIZEOF(comp.szSource);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_SOURCE, NULL, &dwType, (LPBYTE)&comp.szSource, &cbSize) != ERROR_SUCCESS)
- {
- comp.szSource[0] = TEXT('');
- }
- //
- // Read in the SubscribedURL string.
- //
- cbSize = SIZEOF(comp.szSubscribedURL);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_SUBSCRIBED_URL, NULL, &dwType, (LPBYTE)&comp.szSubscribedURL, &cbSize) != ERROR_SUCCESS)
- {
- comp.szSubscribedURL[0] = TEXT('');
- }
- //
- // Read in the Friendly name string.
- //
- cbSize = SIZEOF(comp.szFriendlyName);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_NAME, NULL, &dwType, (LPBYTE)&comp.szFriendlyName, &cbSize) != ERROR_SUCCESS)
- {
- comp.szFriendlyName[0] = TEXT('');
- }
- //
- // Read in and parse the flags.
- //
- DWORD dwFlags;
- cbSize = SIZEOF(dwFlags);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_FLAGS, NULL, &dwType, (LPBYTE)&dwFlags, &cbSize) != ERROR_SUCCESS)
- {
- dwFlags = 0;
- }
- comp.iComponentType = dwFlags & COMP_TYPE;
- comp.fChecked = (dwFlags & COMP_SELECTED) != 0;
- comp.fNoScroll = (dwFlags & COMP_NOSCROLL) != 0;
- comp.fDirty = FALSE; //Reading it fresh from registry; Can't be dirty!
- //
- // Read in the location.
- //
- cbSize = SIZEOF(comp.cpPos);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_POSITION, NULL, &dwType, (LPBYTE)&comp.cpPos, &cbSize) != ERROR_SUCCESS)
- {
- ZeroMemory(&comp.cpPos, SIZEOF(comp.cpPos));
- }
- //
- // In IE4.x, we have a very huge positive number (0x7fffffff) as the COMPONENT_TOP;
- // As a result some component's z-index overflowed into the negative range (0x80000003)
- // To fix this, we halved the COMPONENT_TOP (0x3fffffff) and also check for negative z-index
- // values and covert them to postive values.
- if(comp.cpPos.izIndex < 0)
- comp.cpPos.izIndex = COMPONENT_TOP;
- //
- // Make sure the cpPos.dwSize is set to correct value
- //
- comp.cpPos.dwSize = sizeof(COMPPOS);
- //
- // Read in the current ItemState
- //
- cbSize = SIZEOF(comp.dwCurItemState);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_CURSTATE, NULL, &dwType, (LPBYTE)&comp.dwCurItemState, &cbSize) != ERROR_SUCCESS)
- {
- //If the item state is missing, we must be reading from IE4 machine.
- comp.dwCurItemState = IS_NORMAL;
- }
- //
- // Read in the Original state info.
- //
- cbSize = SIZEOF(comp.csiOriginal);
- if ((SHQueryValueEx(hkeyComp, REG_VAL_COMP_ORIGINALSTATEINFO, NULL, &dwType, (LPBYTE)&comp.csiOriginal, &cbSize) != ERROR_SUCCESS) ||
- (comp.csiOriginal.dwSize != SIZEOF(comp.csiOriginal)))
- {
- //If the item state is missing, we must be reading from IE4 machine.
- // Set the OriginalState to the default info.
- SetStateInfo(&comp.csiOriginal, &comp.cpPos, IS_NORMAL);
- comp.csiOriginal.dwHeight = comp.csiOriginal.dwWidth = COMPONENT_DEFAULT_WIDTH;
- }
- //
- // Read in the Restored state info.
- //
- cbSize = SIZEOF(comp.csiRestored);
- if (SHQueryValueEx(hkeyComp, REG_VAL_COMP_RESTOREDSTATEINFO, NULL, &dwType, (LPBYTE)&comp.csiRestored, &cbSize) != ERROR_SUCCESS)
- {
- //If the item state is missing, we must be reading from IE4 machine.
- // Set the restored State to the default info.
- SetStateInfo(&comp.csiRestored, &comp.cpPos, IS_NORMAL);
- }
- //
- // Add the component to the component list.
- //
- AddComponentPrivate(&comp, StrToInt(pszComp));
- //
- // Increment our counter so we know where to add any new
- // components after we're done.
- //
- _dwNextID++;
- RegCloseKey(hkeyComp);
- }
- EXITPROC(2, "DS ReadComponent!");
- }
- typedef struct _tagSortStruct {
- int ihdsaIndex;
- int izIndex;
- } SORTSTRUCT;
- int CALLBACK pfnComponentSort(LPVOID p1, LPVOID p2, LPARAM lParam)
- {
- SORTSTRUCT * pss1 = (SORTSTRUCT *)p1;
- SORTSTRUCT * pss2 = (SORTSTRUCT *)p2;
- if (pss1->izIndex > pss2->izIndex)
- return 1;
- if (pss1->izIndex < pss2->izIndex)
- return -1;
- return(0);
- }
- //
- // ModifyZIndex
- //
- // Little helper function to put the zindex of the windowed and windowless components
- // into correct buckets so that zorting will produce a correct order by zindex.
- //
- // If we don't do this then windowless components may end up zordering above windowed ones.
- //
- void ModifyZIndex(COMPONENTA * pcomp)
- {
- if (pcomp->cpPos.izIndex != COMPONENT_TOP) {
- if (!IsWindowLessComponent(pcomp))
- pcomp->cpPos.izIndex += COMPONENT_TOP_WINDOWLESS;
- }
- else
- {
- if (IsWindowLessComponent(pcomp))
- pcomp->cpPos.izIndex = COMPONENT_TOP_WINDOWLESS;
- }
- }
- //
- // SortAndRationalize
- //
- // SortAndRationalize will take an unsorted component list and sort it such that the components
- // come out in the correct z-index indicated order. It will also rebase the z-index values at
- // a known constant so that the z-index values will not grow endlessly. SortAndRationalize also
- // imposes windowed vs. windowless criteria to the zindex values such that windowless components
- // always zorder under windowed ones.
- //
- void CActiveDesktop::_SortAndRationalize(void)
- {
- int icComponents;
- HDPA hdpa;
- if (_hdsaComponent && ((icComponents = DSA_GetItemCount(_hdsaComponent)) > 1) && (hdpa = DPA_Create(0))) {
- COMPONENTA * pcomp;
- SORTSTRUCT * pss;
- int i, iCur = ZINDEX_START;
- BOOL fInsertFailed = FALSE;
- HDSA hdsaOld;
- // Go through each component and insert it's hdsa-index and zindex into the hdpa
- for (i = 0; i < icComponents; i++)
- {
- if (!(pss = (SORTSTRUCT *)LocalAlloc(LPTR, sizeof(SORTSTRUCT))))
- break;
- pcomp = (COMPONENTA *)DSA_GetItemPtr(_hdsaComponent, i);
- ModifyZIndex(pcomp);
- pss->ihdsaIndex = i;
- pss->izIndex = pcomp->cpPos.izIndex;
- if (DPA_AppendPtr(hdpa, (void FAR *)pss) == -1) {
- LocalFree((HANDLE)pss);
- break;
- }
- }
- // Sort the hdpa by zindex
- DPA_Sort(hdpa, pfnComponentSort, 0);
- // Save old values
- hdsaOld = _hdsaComponent;
- // Null out the old hdsa, so AddComponentPrivate will create a new one
- _hdsaComponent = NULL;
- // Now go through the sorted hdpa and update the component zindex with a ZINDEX_START based zindex, then
- // add the component to the new hdsa in sorted order.
- for (i = 0; i < icComponents; i++) {
- if (!(pss = (SORTSTRUCT *)DPA_GetPtr(hdpa, i)))
- break;
- // Get component and update it's zIndex and id
- pcomp = (COMPONENTA *)DSA_GetItemPtr(hdsaOld, pss->ihdsaIndex);
- pcomp->cpPos.izIndex = iCur;
- iCur += 2;
- // Free ptr
- LocalFree((HANDLE)pss);
- // Add to new hdsa in sorted order
- if (!fInsertFailed) {
- fInsertFailed = !AddComponentPrivate(pcomp, pcomp->dwID);
- }
- }
- // If we're completely successfull then destroy the old hdsa. Otherwise we need
- // to destroy the new one and restore the old one.
- if ((i == icComponents) && !fInsertFailed) {
- DSA_Destroy(hdsaOld);
- } else {
- if (_hdsaComponent)
- DSA_Destroy(_hdsaComponent);
- _hdsaComponent = hdsaOld;
- }
- DPA_Destroy(hdpa);
- }
- }
- void CActiveDesktop::_ReadComponents(BOOL fActiveDesktop)
- {
- ENTERPROC(2, "DS ReadComponents()");
- HKEY hkey;
- TCHAR lpszDeskcomp[MAX_PATH];
- GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_COMPONENTS, _pszScheme);
- if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszDeskcomp, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
- {
- DWORD cbSize, dwType;
- int i = 0;
- TCHAR lpszSubkey[MAX_PATH];
- //
- // Read in the general settings.
- //
- DWORD dwSettings;
- cbSize = SIZEOF(dwSettings);
- if (SHQueryValueEx(hkey, REG_VAL_COMP_SETTINGS, NULL, &dwType, (LPBYTE)&dwSettings, &cbSize) == ERROR_SUCCESS)
- {
- _co.fEnableComponents = (dwSettings & COMPSETTING_ENABLE) != 0;
- }
- _co.fActiveDesktop = fActiveDesktop;
- //
- // Read in all the desktop components
- //
- while (RegEnumKey(hkey, i, lpszSubkey, ARRAYSIZE(lpszSubkey)) == ERROR_SUCCESS)
- {
- _ReadComponent(hkey, lpszSubkey);
- i++;
- }
- _SortAndRationalize();
- RegCloseKey(hkey);
- }
- EXITPROC(2, "DS ReadComponents!");
- }
- void CActiveDesktop::_Initialize(void)
- {
- ENTERPROC(2, "DS Initialize()");
- if (!_fInitialized)
- {
- _fInitialized = TRUE;
- InitDeskHtmlGlobals();
- SHELLSTATE ss = {0};
- SHGetSetSettings(&ss, SSF_DESKTOPHTML, FALSE);
- BOOL fActiveDesktop = BOOLIFY(ss.fDesktopHTML);
- _co.dwSize = SIZEOF(_co);
- _wpo.dwSize = SIZEOF(_wpo);
- //
- // This per-user registry branch may not exist for this user. Or, even if
- // it does exist, it may have some stale info. So ensure that atlreast the
- // default components are there and that the html version is current for this
- // branch of the registry!
- // If everything is current, the following function does nothing!
- //
- CDeskHtmlProp_RegUnReg(TRUE); //TRUE => install.
- _ReadWallpaper(fActiveDesktop);
- _ReadPattern();
- _ReadComponents(fActiveDesktop);
- // If we are in safemode, the we can not use Dynamic Html to make updates because
- // updates involve complete change of background Html.
- if(_IsDisplayInSafeMode())
- _fUseDynamicHtml = FALSE;
- else
- _fUseDynamicHtml = TRUE; //Any component added after the initialization must go through dynamic html.
- _fDirty = FALSE;
- _fNeedBodyEnd = FALSE;
- }
- EXITPROC(2, "DS Initialize!");
- }
- void CActiveDesktop::_SaveWallpaper(void)
- {
- ENTERPROC(2, "DS SaveWallpaper");
- TCHAR lpszDeskcomp[MAX_PATH];
- BOOL fNormalWallpaper;
- GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_GENERAL, _pszScheme);
- //
- // Compute tiling string.
- //
- TCHAR szTiled[2];
- lstrcpy(szTiled, TEXT("0"));
- szTiled[0] = szTiled[0] + (TCHAR)(_wpo.dwStyle & WPSTYLE_TILE);
- //
- // Compute the Wallpaper styling string
- //
- TCHAR szWPStyle[2];
- lstrcpy(szWPStyle, TEXT("0"));
- //
- // NOTE: If WPSTYLE_TILE is set, we still want to say WallpaperStyle="0"; This won't hurt
- // because TileWallpaper="1" will over-ride this anyway.
- // The reason for this hack is that during memphis setup, they put a tiled wallpaper. Then we
- // write WallpaperStyle=1 and TileWallpaper=1 in new and old locations. Then, then change
- // the wallpaper and set TileWallpaper=0. Since the WallpaperStyle continues to be 1, they
- // get a tiled wallpaper finally. The following is to avoid this problem!
- //
- szWPStyle[0] = szWPStyle[0] + (TCHAR)(_wpo.dwStyle & WPSTYLE_STRETCH);
- //
- // Write out wallpaper settings in new active desktop area.
- //
- if(_fWallpaperDirty || _fWallpaperChangedDuringInit)
- {
- if(!_fPolicyForWPStyle)
- {
- SHSetValue(HKEY_CURRENT_USER, lpszDeskcomp,
- c_szTileWall, REG_SZ, (LPBYTE)szTiled, SIZEOF(TCHAR)*(lstrlen(szTiled)+1));
- }
- //
- // Note: We do not write the Wallpaper Style string for older systems because we do not
- // want to over-write what PlusPack writes. However, for newer Operating systems, we
- // want to write the WallpaperStyle also.
- //
- if((g_bRunOnMemphis || g_bRunOnNT5) && (!_fPolicyForWPStyle))
- {
- SHSetValue(HKEY_CURRENT_USER, lpszDeskcomp,
- c_szWallpaperStyle, REG_SZ, (LPBYTE)szWPStyle, SIZEOF(TCHAR)*(lstrlen(szWPStyle)+1));
- }
- if(!_fPolicyForWPName)
- SHRegSetPath(HKEY_CURRENT_USER, lpszDeskcomp, c_szWallpaper, _szSelectedWallpaper, 0);
- }
- if(fNormalWallpaper = IsNormalWallpaper(_szSelectedWallpaper))
- {
- lstrcpyn(_szBackupWallpaper, _szSelectedWallpaper, ARRAYSIZE(_szBackupWallpaper));
- }
- if(!_fPolicyForWPName)
- {
- FILETIME ft;
- GetWallpaperFileTime(_szBackupWallpaper, &ft);
- // Backup the "Old type" wallpaper's name here in the new location
- // sothat we can detect when this gets changed by some other app.
- SHRegSetPath(HKEY_CURRENT_USER, lpszDeskcomp, c_szBackupWallpaper, _szBackupWallpaper, 0);
- SHSetValue(HKEY_CURRENT_USER, lpszDeskcomp,
- c_szWallpaperTime, REG_BINARY, (LPBYTE)&ft,
- SIZEOF(ft));
- }
- //
- // Even if this wallpaper is not valid in normal desktop (i.e., even if it is not a .BMP),
- // write it out in normal desktop registry area.
- //
- if (_fWallpaperDirty)
- {
- if(!_fPolicyForWPStyle)
- {
- SHSetValue(HKEY_CURRENT_USER, c_szRegStrDesktop,
- c_szTileWall, REG_SZ, (LPBYTE)szTiled, SIZEOF(TCHAR)*(lstrlen(szTiled)+1));
- }
- //
- // Note: We do not write the Wallpaper Style string for older systems because we do not
- // want to over-write what PlusPack writes. However, for newer Operating systems, we
- // want to write the WallpaperStyle also.
- //
- if((g_bRunOnMemphis || g_bRunOnNT5) && (!_fPolicyForWPStyle))
- {
- SHSetValue(HKEY_CURRENT_USER, c_szRegStrDesktop,
- c_szWallpaperStyle, REG_SZ, (LPBYTE)szWPStyle, SIZEOF(TCHAR)*(lstrlen(szWPStyle)+1));
- }
- if(!_fPolicyForWPName)
- {
- SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,
- (fNormalWallpaper ? _szSelectedWallpaper : _szBackupWallpaper),
- SPIF_UPDATEINIFILE);
- }
- }
- EXITPROC(2, "DS SaveWallpaper");
- }
- void CActiveDesktop::_SaveComponent(HKEY hkey, int iIndex, COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS SaveComponent(hkey=%08X,iIndex=%d,pcomp=%08X)", hkey, iIndex, pcomp);
- TCHAR szSubKey[8];
- HKEY hkeySub;
- wsprintf(szSubKey, TEXT("%d"), iIndex);
- if (RegCreateKey(hkey, szSubKey, &hkeySub) == ERROR_SUCCESS)
- {
- pcomp->fDirty = FALSE; //Since we are saving in the registry, reset this!
- //
- // Write out the source string and Friendly name string.
- //
- RegSetValueEx(hkeySub, REG_VAL_COMP_SOURCE, 0, REG_SZ, (LPBYTE)pcomp->szSource, (lstrlen(pcomp->szSource)+1)*SIZEOF(TCHAR));
- RegSetValueEx(hkeySub, REG_VAL_COMP_SUBSCRIBED_URL, 0, REG_SZ, (LPBYTE)pcomp->szSubscribedURL, (lstrlen(pcomp->szSubscribedURL)+1)*SIZEOF(TCHAR));
- RegSetValueEx(hkeySub, REG_VAL_COMP_NAME, 0, REG_SZ, (LPBYTE)pcomp->szFriendlyName, (lstrlen(pcomp->szFriendlyName)+1)*SIZEOF(TCHAR));
- //
- // Compute and write out flags.
- //
- DWORD dwFlags = 0;
- dwFlags |= pcomp->iComponentType;
- if (pcomp->fChecked)
- {
- dwFlags |= COMP_SELECTED;
- }
- if (pcomp->fNoScroll)
- {
- dwFlags |= COMP_NOSCROLL;
- }
- RegSetValueEx(hkeySub, REG_VAL_COMP_FLAGS, 0, REG_DWORD, (LPBYTE)&dwFlags, SIZEOF(dwFlags));
- //
- // Write out the position.
- //
- RegSetValueEx(hkeySub, REG_VAL_COMP_POSITION, 0, REG_BINARY, (LPBYTE)&pcomp->cpPos, SIZEOF(pcomp->cpPos));
- // Write out the Current state
- RegSetValueEx(hkeySub, REG_VAL_COMP_CURSTATE, 0, REG_DWORD, (LPBYTE)&pcomp->dwCurItemState, SIZEOF(pcomp->dwCurItemState));
- // Write out the Original State Info
- RegSetValueEx(hkeySub, REG_VAL_COMP_ORIGINALSTATEINFO, 0, REG_BINARY, (LPBYTE)&pcomp->csiOriginal, SIZEOF(pcomp->csiOriginal));
- // Write out the Restored State Info
- RegSetValueEx(hkeySub, REG_VAL_COMP_RESTOREDSTATEINFO, 0, REG_BINARY, (LPBYTE)&pcomp->csiRestored, SIZEOF(pcomp->csiRestored));
- RegCloseKey(hkeySub);
- }
- EXITPROC(2, "DS SaveComponent!");
- }
- void CActiveDesktop::_SaveComponents(void)
- {
- ENTERPROC(2, "DS SaveComponents");
- DWORD dwType, dwFlags = 0, dwDataLength = SIZEOF(dwFlags);
- int i;
- TCHAR lpszDeskcomp[MAX_PATH];
- GetRegLocation(lpszDeskcomp, SIZECHARS(lpszDeskcomp), REG_DESKCOMP_COMPONENTS, _pszScheme);
- //
- // We need to preserve the old GENFLAGS, so read them now before we roach them.
- //
- SHGetValue(HKEY_CURRENT_USER, (LPCTSTR)lpszDeskcomp, REG_VAL_COMP_GENFLAGS, &dwType,
- (LPBYTE)(&dwFlags), &dwDataLength);
- //
- // Delete the entire registry key.
- //
- SHDeleteKey(HKEY_CURRENT_USER, lpszDeskcomp);
- //
- // Recreate the registry key.
- //
- HKEY hkey;
- if (RegCreateKey(HKEY_CURRENT_USER, lpszDeskcomp, &hkey) == ERROR_SUCCESS)
- {
- //
- // Write out the version number.
- //
- DWORD dw = CUR_DESKHTML_VERSION;
- RegSetValueEx(hkey, REG_VAL_COMP_VERSION, 0, REG_DWORD, (LPBYTE)(&dw), SIZEOF(dw));
- dw = CUR_DESKHTML_MINOR_VERSION;
- RegSetValueEx(hkey, REG_VAL_COMP_MINOR_VERSION, 0, REG_DWORD, (LPBYTE)(&dw), SIZEOF(dw));
- //
- // Write out the general settings.
- //
- DWORD dwSettings = 0;
- if (_co.fEnableComponents)
- {
- dwSettings |= COMPSETTING_ENABLE;
- }
- RegSetValueEx(hkey, REG_VAL_COMP_SETTINGS, 0, REG_DWORD, (LPBYTE)&dwSettings, SIZEOF(dwSettings));
- //
- // Write out the general flags
- //
- RegSetValueEx(hkey, REG_VAL_COMP_GENFLAGS, 0, REG_DWORD, (LPBYTE)&dwFlags, SIZEOF(dwFlags));
- if (_hdsaComponent)
- {
- //
- // Write out the settings for each component
- //
- for (i=0; i<DSA_GetItemCount(_hdsaComponent); i++)
- {
- COMPONENTA * pcomp;
- if (pcomp = (COMPONENTA *)DSA_GetItemPtr(_hdsaComponent, i))
- {
- pcomp->dwID = i;
- _SaveComponent(hkey, i, pcomp);
- }
- }
- }
- RegCloseKey(hkey);
- }
- EXITPROC(2, "DS SaveComponents");
- }
- void CActiveDesktop::_SavePattern(DWORD dwFlags)
- {
- ENTERPROC(2, "DS SavePattern()");
- if (_fPatternDirty && (dwFlags & SAVE_PATTERN_NAME))
- {
- //
- // Write out the pattern to the registry and INI files.
- //
- SystemParametersInfo(SPI_SETDESKPATTERN, 0, _szSelectedPattern, SPIF_UPDATEINIFILE);
- }
- if (IsValidPattern(_szSelectedPattern) && (dwFlags & GENERATE_PATTERN_FILE))
- {
- //
- // Write out the pattern as a BMP file for use in HTML.
- //
- TCHAR szBitmapFile[MAX_PATH];
- GetPerUserFileName(szBitmapFile, ARRAYSIZE(szBitmapFile), PATTERN_FILENAME);
- HANDLE hFileBitmap;
- hFileBitmap = CreateFile(szBitmapFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM, NULL);
- if (hFileBitmap != INVALID_HANDLE_VALUE)
- {
- DWORD cbWritten;
- BITMAPFILEHEADER bmfh = {0};
- bmfh.bfType = 0x4D42; // 'BM'
- bmfh.bfSize = SIZEOF(BITMAPFILEHEADER) + SIZEOF(BITMAPINFOHEADER) + 2*SIZEOF(RGBQUAD) + 8*SIZEOF(DWORD);
- bmfh.bfOffBits = SIZEOF(BITMAPFILEHEADER) + SIZEOF(BITMAPINFOHEADER) + 2*SIZEOF(RGBQUAD);
- WriteFile(hFileBitmap, &bmfh, SIZEOF(bmfh), &cbWritten, NULL);
- BITMAPINFOHEADER bmih = {0};
- bmih.biSize = SIZEOF(BITMAPINFOHEADER);
- bmih.biWidth = 8;
- bmih.biHeight = 8;
- bmih.biPlanes = 1;
- bmih.biBitCount = 1;
- bmih.biCompression = BI_RGB;
- WriteFile(hFileBitmap, &bmih, SIZEOF(bmih), &cbWritten, NULL);
- RGBQUAD argbTable[2] = {0};
- DWORD rgb;
- rgb = GetSysColor(COLOR_BACKGROUND);
- argbTable[0].rgbBlue = GetBValue(rgb);
- argbTable[0].rgbGreen = GetGValue(rgb);
- argbTable[0].rgbRed = GetRValue(rgb);
- rgb = GetSysColor(COLOR_WINDOWTEXT);
- argbTable[1].rgbBlue = GetBValue(rgb);
- argbTable[1].rgbGreen = GetGValue(rgb);
- argbTable[1].rgbRed = GetRValue(rgb);
- WriteFile(hFileBitmap, argbTable, SIZEOF(argbTable), &cbWritten, NULL);
- DWORD adwBits[8];
- PatternToDwords(_szSelectedPattern, adwBits);
- WriteFile(hFileBitmap, adwBits, SIZEOF(adwBits), &cbWritten, NULL);
- CloseHandle(hFileBitmap);
- }
- }
- EXITPROC(2, "DS SavePattern!");
- }
- void CActiveDesktop::_WriteHtmlFromString(LPCTSTR psz)
- {
- ENTERPROC(3, "DS WriteHtmlFromString(psz=>%s<)", psz);
- LPCWSTR pwsz;
- WCHAR szBuf[INTERNET_MAX_URL_LENGTH];
- UINT uiLen;
- int cch;
- #ifdef UNICODE
- if((_pStream == NULL) && (_iDestFileCharset == ANSI_HTML_CHARSET))
- {
- cch = SHUnicodeToAnsi(psz, (LPSTR)szBuf, ARRAYSIZE(szBuf));
- ASSERT(cch == lstrlenW((LPWSTR)psz)+1);
- pwsz = (LPCWSTR)szBuf;
- uiLen = lstrlenA((LPSTR)szBuf);
- }
- else
- {
- pwsz = psz;
- uiLen = lstrlenW(pwsz);
- }
- #else
- if((_pStream == NULL) && (_iDestFileCharset == ANSI_HTML_CHARSET))
- {
- pwsz = (LPWSTR)psz;
- uiLen = lstrlenA(psz);
- }
- else
- {
- cch = SHAnsiToUnicode(psz, szBuf, ARRAYSIZE(szBuf));
- ASSERT(cch == lstrlenA(psz)+1);
- pwsz = (LPCWSTR)szBuf;
- uiLen = lstrlenW(pwsz);
- }
- #endif
- UINT cbWritten;
- _WriteHtmlW(pwsz, uiLen, &cbWritten);
- EXITPROC(3, "DS WriteHtmlFromString!");
- }
- void CActiveDesktop::_WriteHtmlFromId(UINT uid)
- {
- ENTERPROC(3, "DS WriteHtmlFromId(uid=%d)", uid);
- TCHAR szBuf[INTERNET_MAX_URL_LENGTH];
- LoadString(HINST_THISDLL, uid, szBuf, ARRAYSIZE(szBuf));
- _WriteHtmlFromString(szBuf);
- EXITPROC(3, "DS WriteHtmlFromId!");
- }
- void CActiveDesktop::_WriteHtmlFromIdF(UINT uid, ...)
- {
- ENTERPROC(3, "DS WriteHtmlFromIdF(uid=%d,...)", uid);
- TCHAR szBufFmt[INTERNET_MAX_URL_LENGTH];
- TCHAR szBuf[INTERNET_MAX_URL_LENGTH];
- LoadString(HINST_THISDLL, uid, szBufFmt, ARRAYSIZE(szBufFmt));
- va_list arglist;
- va_start(arglist, uid);
- wvsprintf(szBuf, szBufFmt, arglist);
- va_end(arglist);
- _WriteHtmlFromString(szBuf);
- EXITPROC(3, "DS WriteHtmlFromIdF!");
- }
- void CActiveDesktop::_WriteHtmlFromFile(LPCTSTR pszContents)
- {
- ENTERPROC(3, "DS WriteHtmlFromFile(pszContents=>%s<)", pszContents);
- CReadFileObj *pReadFileObj = new CReadFileObj(pszContents);
- if (pReadFileObj)
- {
- if(pReadFileObj->_hFile != INVALID_HANDLE_VALUE)
- {
- WCHAR wcBuf[INTERNET_MAX_URL_LENGTH + 1];
- UINT uiCharCount = ARRAYSIZE(wcBuf) -1; //Leave room for null termination.
- UINT uiCharsRead;
- UINT uiCharsConverted;
- int iDestCharset = (_pStream ? UNICODE_HTML_CHARSET : _iDestFileCharset);
- while (SUCCEEDED(pReadFileObj->FileReadAndConvertChars(iDestCharset, wcBuf, uiCharCount, &uiCharsRead, &uiCharsConverted)) && uiCharsRead)
- {
- UINT cbWritten;
- _WriteHtmlW(wcBuf, uiCharsConverted, &cbWritten);
- if (uiCharsRead < uiCharCount)
- {
- break;
- }
- }
- }
- delete pReadFileObj;
- }
- EXITPROC(3, "DS WriteHtmlFromFile!");
- }
- void CActiveDesktop::_WriteHtmlFromReadFileObj(CReadFileObj *pFileObj, int iOffsetStart, int iOffsetEnd)
- {
- ENTERPROC(3, "DS WriteHtmlFromReadFileObj(pFileObj=%08X,iOffsetStart=%d,iOffsetEnd=%d)", pFileObj, iOffsetStart, iOffsetEnd);
- if (iOffsetStart != -1)
- {
- pFileObj->FileSeekChars(iOffsetStart, FILE_BEGIN);
- }
- else
- {
- ASSERT(iOffsetEnd == -1);
- iOffsetEnd = -1;
- }
- //Get the number of WIDECHARs to be written
- UINT cchWrite = (iOffsetEnd == -1) ? 0xFFFFFFFF : (iOffsetEnd - iOffsetStart);
- while (cchWrite)
- {
- WCHAR wcBuf[INTERNET_MAX_URL_LENGTH+1];
- //
- // Read a chunk.
- //
- UINT cchTryRead = min(cchWrite, (ARRAYSIZE(wcBuf) - 1));
- UINT cchActualRead;
- HRESULT hres;
- //Note: if we are reading ANSI, we still use the unicode buff; but cast it!
- if(_iDestFileCharset == ANSI_HTML_CHARSET)
- hres = pFileObj->FileReadCharsA((LPSTR)wcBuf, cchTryRead, &cchActualRead);
- else
- hres = pFileObj->FileReadCharsW(wcBuf, cchTryRead, &cchActualRead);
- if(SUCCEEDED(hres) && cchActualRead)
- {
- //
- // Write a chunk.
- //
- UINT cchWritten;
- _WriteHtmlW(wcBuf, cchActualRead, &cchWritten);
- if (cchActualRead < cchTryRead)
- {
- //
- // End of file, all done.
- //
- break;
- }
- cchWrite -= cchActualRead;
- }
- else
- {
- //
- // Error reading from file, all done.
- //
- break;
- }
- }
- EXITPROC(3, "DS WriteHtmlFromHfile!");
- }
- int CActiveDesktop::_ScanForTagA(CReadFileObj *pFileObj, int iOffsetStart, LPCSTR pszTag)
- {
- ENTERPROC(2, "DS ScanForTagA(pFileObj=%08X,iOffsetStart=%d,pszTagA=>%s<)",
- pFileObj, iOffsetStart, pszTag);
- int iRet = -1;
- BOOL fDoneReading = FALSE;
- int iOffset;
- DWORD cchTag = lstrlenA(pszTag);
- pFileObj->FileSeekChars(iOffsetStart, FILE_BEGIN);
- iOffset = iOffsetStart;
- DWORD cchBuf = 0;
- while (!fDoneReading)
- {
- char szBuf[INTERNET_MAX_URL_LENGTH+1];
- //
- // Fill in the buffer.
- //
- UINT cchTryRead = ARRAYSIZE(szBuf) - cchBuf - 1;
- UINT cchRead;
- if(SUCCEEDED(pFileObj->FileReadCharsA(&szBuf[cchBuf], cchTryRead, &cchRead)) && cchRead)
- {
- cchBuf += cchRead;
- //
- // Terminate the string.
- //
- szBuf[cchBuf] = '';
- //
- // Scan for the tag.
- //
- LPSTR pszTagInBuf = StrStrIA(szBuf, pszTag);
- if (pszTagInBuf)
- {
- //
- // Found the tag, compute the offset.
- //
- iRet = (int) (iOffset + pszTagInBuf - szBuf);
- fDoneReading = TRUE;
- }
- else if (cchRead < cchTryRead)
- {
- //
- // Ran out of file without finding tag.
- //
- fDoneReading = TRUE;
- }
- else
- {
- //
- // Compute how many bytes we want to throw away
- // from this buffer so we can read in more data.
- // We don't want to throw away all the bytes because
- // the tag we want may span two buffers.
- //
- DWORD cchSkip = cchBuf - cchTag;
- //
- // Advance the file offset.
- //
- iOffset += cchSkip;
- //
- // Reduce the buffer size.
- //
- cchBuf -= cchSkip;
- //
- // Move the kept bytes to the beginning of the buffer.
- //
- MoveMemory(szBuf, szBuf + cchSkip, cchBuf);
- }
- }
- else
- {
- fDoneReading = TRUE;
- }
- }
- EXITPROC(2, "DS ScanForTagA=%d", iRet);
- return iRet;
- }
- int CActiveDesktop::_ScanForTagW(CReadFileObj *pFileObj, int iOffsetStart, LPCWSTR pwszTag)
- {
- ENTERPROC(2, "DS ScanForTag(pFileObj=%08X,iOffsetStart=%d,pszTagA=>%s<)",
- pFileObj, iOffsetStart, pwszTag);
- int iRet = -1;
- BOOL fDoneReading = FALSE;
- int iOffset;
- DWORD cchTag = lstrlenW(pwszTag);
- pFileObj->FileSeekChars(iOffsetStart, FILE_BEGIN);
- iOffset = iOffsetStart;
- DWORD cchBuf = 0;
- while (!fDoneReading)
- {
- WCHAR wszBuf[INTERNET_MAX_URL_LENGTH+1];
- //
- // Fill in the buffer.
- //
- UINT cchTryRead = ARRAYSIZE(wszBuf) - cchBuf - 1;
- UINT cchRead;
- if(SUCCEEDED(pFileObj->FileReadCharsW(&wszBuf[cchBuf], cchTryRead, &cchRead)) && cchRead)
- {
- cchBuf += cchRead;
- //
- // Terminate the string.
- //
- wszBuf[cchBuf] = L'';
- //
- // Scan for the tag.
- //
- LPWSTR pwszTagInBuf = StrStrIW(wszBuf, pwszTag);
- if (pwszTagInBuf)
- {
- //
- // Found the tag, compute the offset.
- //
- iRet = (int) (iOffset + pwszTagInBuf - wszBuf);
- fDoneReading = TRUE;
- }
- else if (cchRead < cchTryRead)
- {
- //
- // Ran out of file without finding tag.
- //
- fDoneReading = TRUE;
- }
- else
- {
- //
- // Compute how many bytes we want to throw away
- // from this buffer so we can read in more data.
- // We don't want to throw away all the bytes because
- // the tag we want may span two buffers.
- //
- DWORD cchSkip = cchBuf - cchTag;
- //
- // Advance the file offset.
- //
- iOffset += cchSkip;
- //
- // Reduce the buffer size.
- //
- cchBuf -= cchSkip;
- //
- // Move the kept bytes to the beginning of the buffer.
- //
- MoveMemory(wszBuf, wszBuf + cchSkip, cchBuf*sizeof(WCHAR));
- }
- }
- else
- {
- fDoneReading = TRUE;
- }
- }
- EXITPROC(2, "DS ScanForTag=%d", iRet);
- return iRet;
- }
- int CActiveDesktop::_ScanTagEntriesA(CReadFileObj *pReadFileObj, int iOffsetStart, TAGENTRYA *pte, int cte)
- {
- ENTERPROC(2, "DS ScanTagEntriesA(pReadFileObj=%08X,iOffsetStart=%d,pte=%08X,cte=%d)",
- pReadFileObj, iOffsetStart, pte, cte);
- int iRet = -1;
- int i;
- for (i=0; i<cte; i++,pte++)
- {
- iRet = _ScanForTagA(pReadFileObj, iOffsetStart, pte->pszTag);
- if (iRet != -1)
- {
- if (pte->fSkipPast)
- {
- iRet += lstrlenA(pte->pszTag);
- }
- break;
- }
- }
- EXITPROC(2, "DS ScanTagEntriesA=%d", iRet);
- return iRet;
- }
- int CActiveDesktop::_ScanTagEntriesW(CReadFileObj *pReadFileObj, int iOffsetStart, TAGENTRYW *pte, int cte)
- {
- ENTERPROC(2, "DS ScanTagEntriesW(pReadFileObj=%08X,iOffsetStart=%d,pte=%08X,cte=%d)",
- pReadFileObj, iOffsetStart, pte, cte);
- int iRet = -1;
- int i;
- for (i=0; i<cte; i++,pte++)
- {
- iRet = _ScanForTagW(pReadFileObj, iOffsetStart, pte->pwszTag);
- if (iRet != -1)
- {
- if (pte->fSkipPast)
- {
- iRet += lstrlenW(pte->pwszTag);
- }
- break;
- }
- }
- EXITPROC(2, "DS ScanTagEntriesW=%d", iRet);
- return iRet;
- }
- void CActiveDesktop::_ParseAnsiInputHtmlFile( LPTSTR szSelectedWallpaper, int *piOffsetBase, int *piOffsetComp)
- {
- //
- // Figure out where to insert the base href tag.
- //
- int iOffsetBase = 0, iBaseTagStart;
- BOOL fUseBaseHref;
- LONG lOffsetDueToBOM = 0; //Character Offset due to the Byte Order Mark.
- //1 for UNICODE and 0 for ANSI files.
- // 98/11/11 #248047 vtan: This code looks for a <BASE HREF=...> tag.
- // It used to use a scan for "<BASE" and assume that this was the
- // desired tag. HTML allows a "<BASEFONT>" tag which was being
- // mistaken for a "<BASE HREF=...>" tag. The code now looks for the
- // same string but looks at the character following the "<BASE" to
- // see if it's a white-space character.
- fUseBaseHref = TRUE;
- _pReadFileObjHtmlBkgd->FileGetCurCharOffset(&lOffsetDueToBOM);
- iOffsetBase = (int)lOffsetDueToBOM;
- iBaseTagStart = _ScanForTagA(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, "<BASE");
- if (iBaseTagStart != -1)
- {
- UINT uiCountChars, uiTryToRead;
- char szBaseTagBuffer[6+1]; // allow for "<BASEx" plus a NULL.
- _pReadFileObjHtmlBkgd->FileSeekChars(iBaseTagStart, FILE_BEGIN);
- uiTryToRead = ARRAYSIZE(szBaseTagBuffer) - 1;
- if(SUCCEEDED(_pReadFileObjHtmlBkgd->FileReadCharsA(szBaseTagBuffer, uiTryToRead, &uiCountChars)) && uiCountChars)
- {
- char ch;
- ch = szBaseTagBuffer[5];
- fUseBaseHref = ((ch != ' ') &&
- (ch != 'r') &&
- (ch != 'n') && // this covers the UNIX line break scheme
- (ch != 't'));
- }
- }
- if (fUseBaseHref)
- {
- TAGENTRYA rgteBase[] = {
- { "<HEAD>", TRUE, },
- { "<BODY", FALSE, },
- { "<HTML>", TRUE, },
- };
- iOffsetBase = _ScanTagEntriesA(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, rgteBase, ARRAYSIZE(rgteBase));
- if (iOffsetBase == -1)
- {
- iOffsetBase = (int)lOffsetDueToBOM;
- }
- }
- //
- // Figure out where to insert the components.
- //
- TAGENTRYA rgteComponents[] = {
- { "</BODY>", FALSE, },
- { "</HTML>", FALSE, },
- };
- int iOffsetComponents = _ScanTagEntriesA(_pReadFileObjHtmlBkgd, iOffsetBase, rgteComponents, ARRAYSIZE(rgteComponents));
- //
- // Write out the initial HTML up to the <HEAD> tag.
- //
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, iOffsetBase);
- //
- // Write out the base tag.
- //
- if (fUseBaseHref)
- {
- //BASE tag must point to the base "URL". So, don't strip out the filename.
- _WriteHtmlFromIdF(IDS_BASE_TAG, szSelectedWallpaper);
- }
- // Figure out where to insert the DIV clause
- TAGENTRYA rgteBodyStart[] = {
- { "<BODY", FALSE, },
- };
- int iOffsetBodyStart = _ScanTagEntriesA(_pReadFileObjHtmlBkgd, iOffsetBase, rgteBodyStart, ARRAYSIZE(rgteBodyStart));
- // Write out HTML until after the <BODY ......>
- if (iOffsetBodyStart == -1)
- { // the <BODY> tag is not found, so we need to insert it.
- // Copy over stuff until </HEAD>
- TAGENTRYA rgteHeadEnd[] = {
- { "</HEAD>", TRUE, },
- };
- int iOffsetHeadEnd = _ScanTagEntriesA(_pReadFileObjHtmlBkgd, iOffsetBase, rgteHeadEnd, ARRAYSIZE(rgteHeadEnd));
- if(iOffsetHeadEnd != -1)
- {
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, iOffsetBase, iOffsetHeadEnd);
- iOffsetBase = iOffsetHeadEnd;
- }
- _WriteHtmlFromIdF(IDS_BODY_CENTER_WP2); // "<BODY>"
- _fNeedBodyEnd = TRUE;
- }
- else
- {
- TAGENTRYA rgteBodyEnd[] = {
- { ">", TRUE, },
- };
- int iOffsetBodyEnd = _ScanTagEntriesA(_pReadFileObjHtmlBkgd, iOffsetBodyStart, rgteBodyEnd, ARRAYSIZE(rgteBodyEnd));
- if (iOffsetBodyEnd == -1)
- { // An error in the HTML.
- iOffsetBodyEnd = iOffsetBodyStart; // BUGBUG: We need a better recovery idea.
- }
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, iOffsetBase, iOffsetBodyEnd);
- iOffsetBase = iOffsetBodyEnd;
- }
- *piOffsetBase = iOffsetBase;
- *piOffsetComp = iOffsetComponents;
- }
- void CActiveDesktop::_GenerateHtmlHeader(void)
- {
- ENTERPROC(2, "DS GenerateHtmlHeader()");
- EnumMonitorsArea ema;
- GetMonitorSettings(&ema);
- RECT rcViewAreas[LV_MAX_WORKAREAS]; // WorkArea minus toolbar/tray areas
- int nViewAreas = ARRAYSIZE(rcViewAreas);
- // Get the ViewAreas
- if (!GetViewAreas(rcViewAreas, &nViewAreas))
- {
- nViewAreas = 0;
- }
- //Assume that the final Deskstat.htt that we generate is going to be in UNICODE.
- //This will change to ANSI only if the background html wallpaper is ANSI (determined later)
- _iDestFileCharset = UNICODE_HTML_CHARSET;
- //
- // Write out the background and color.
- //
- TCHAR szSelectedWallpaper[INTERNET_MAX_URL_LENGTH];
- // If the wallpaper does not have a directory specified (this may happen if other apps. change this value),
- // we have to figure it out.
- GetWallpaperWithPath(_szSelectedWallpaper, szSelectedWallpaper, ARRAYSIZE(szSelectedWallpaper));
- BOOL fValidWallpaper = GetFileAttributes(szSelectedWallpaper) != 0xFFFFFFFF;
- if (_fSingleItem || IsWallpaperPicture(szSelectedWallpaper) || !fValidWallpaper)
- {
- //
- // Write the BOM for UNICODE
- //
- if(_hFileHtml)
- {
- DWORD cbWritten;
- WriteFile(_hFileHtml, (LPCSTR)&wUnicodeBOM, sizeof(wUnicodeBOM), &cbWritten, NULL);
- }
- // To account for the vagaries of the desktop browser (it's TopLeft starts from the TopLeft
- // of the Desktop ViewArea instead of the TopLeft of the monitor, as might be expected)
- // which happens only in the case of one active monitor systems, we add the width of the
- // tray/toolbars to the co-ordinates of the DIV section of each monitor's wallpaper.
- int iLeft, iTop;
- if(nViewAreas == 1)
- {
- iLeft = rcViewAreas[0].left - ema.rcVirtualMonitor.left;
- iTop = rcViewAreas[0].top - ema.rcVirtualMonitor.top;
- }
- else
- {
- iLeft = 0;
- iTop = 0;
- }
- //
- // Write out the standard header.
- //
- UINT i;
- for (i=IDS_COMMENT_BEGIN; i<IDS_BODY_BEGIN; i++)
- {
- _WriteHtmlFromIdF(i);
- }
- //
- // Write out the body tag, with background bitmap.
- //
- DWORD rgbDesk;
- rgbDesk = GetSysColor(COLOR_DESKTOP);
- TCHAR szBitmapFile[MAX_PATH];
- GetPerUserFileName(szBitmapFile, ARRAYSIZE(szBitmapFile), PATTERN_FILENAME);
- if (!_fSingleItem && _szSelectedWallpaper[0] && fValidWallpaper)
- {
- TCHAR szWallpaperUrl[INTERNET_MAX_URL_LENGTH];
- DWORD cch = ARRAYSIZE(szWallpaperUrl);
- UrlCreateFromPath(szSelectedWallpaper, szWallpaperUrl, &cch, URL_INTERNAL_PATH);
- switch (_wpo.dwStyle)
- {
- case WPSTYLE_TILE:
- //
- // Ignore the pattern, tile the wallpaper as background.
- //
- _WriteHtmlFromIdF(IDS_BODY_BEGIN2, szWallpaperUrl, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- break;
- case WPSTYLE_CENTER:
- if (IsValidPattern(_szSelectedPattern))
- {
- //
- // Tile the pattern as the main background.
- //
- _WriteHtmlFromIdF(IDS_BODY_BEGIN2, szBitmapFile, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- if(_fBackgroundHtml) // We are generating the HTML for preview
- {
- _WriteHtmlFromIdF(IDS_BODY_PATTERN_AND_WP, szWallpaperUrl);
- }
- else
- {
- //
- // Write out a DIV section for a centered, untiled wallpaper.
- //
- // write it out for each monitor.
- for(int i = 0; i < ema.iMonitors; i++)
- {
- _WriteHtmlFromIdF(IDS_BODY_PATTERN_AND_WP2,
- ema.rcMonitor[i].left - ema.rcVirtualMonitor.left - iLeft,
- ema.rcMonitor[i].top - ema.rcVirtualMonitor.top - iTop,
- ema.rcMonitor[i].right - ema.rcMonitor[i].left,
- ema.rcMonitor[i].bottom - ema.rcMonitor[i].top,
- szWallpaperUrl);
- }
- }
- }
- else
- {
- //
- // Write out a non-tiled, centered wallpaper as background.
- //
- if(_fBackgroundHtml) // We are generating the HTML for preview
- {
- _WriteHtmlFromIdF(IDS_BODY_CENTER_WP, szWallpaperUrl, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- }
- else
- {
- _WriteHtmlFromIdF(IDS_BODY_CENTER_WP2, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- // write it out for each monitor.
- for(int i = 0; i < ema.iMonitors; i++)
- {
- _WriteHtmlFromIdF(IDS_BODY_PATTERN_AND_WP2,
- ema.rcMonitor[i].left - ema.rcVirtualMonitor.left - iLeft,
- ema.rcMonitor[i].top - ema.rcVirtualMonitor.top - iTop,
- ema.rcMonitor[i].right - ema.rcMonitor[i].left,
- ema.rcMonitor[i].bottom - ema.rcMonitor[i].top,
- szWallpaperUrl);
- }
- }
- }
- break;
- case WPSTYLE_STRETCH:
- //
- // Ignore the pattern, create a DIV section of the wallpaper
- // stretched to 100% of the screen.
- //
- _WriteHtmlFromIdF(IDS_BODY_BEGIN2, c_szNULL, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- if(_fBackgroundHtml) // We are generating the HTML for preview
- {
- _WriteHtmlFromIdF(IDS_STRETCH_WALLPAPER, szWallpaperUrl);
- }
- else
- {
- // stretch it for each monitor.
- for(int i = 0; i < ema.iMonitors; i++)
- {
- _WriteHtmlFromIdF(IDS_DIV_START3, ema.rcMonitor[i].left - ema.rcVirtualMonitor.left - iLeft,
- ema.rcMonitor[i].top - ema.rcVirtualMonitor.top - iTop,
- ema.rcMonitor[i].right - ema.rcMonitor[i].left,
- ema.rcMonitor[i].bottom - ema.rcMonitor[i].top);
- _WriteHtmlFromIdF(IDS_STRETCH_WALLPAPER, szWallpaperUrl);
- _WriteHtmlFromId(IDS_DIV_END);
- }
- }
- break;
- }
- }
- else
- {
- //
- // Ignore the wallpaper, generate either a tiled pattern
- // or solid color background.
- //
- _WriteHtmlFromIdF(IDS_BODY_BEGIN2, !_fSingleItem && IsValidPattern(_szSelectedPattern) ? szBitmapFile : c_szNULL, GetRValue(rgbDesk), GetGValue(rgbDesk), GetBValue(rgbDesk));
- }
- }
- else
- {
- if ((_pReadFileObjHtmlBkgd = new CReadFileObj(szSelectedWallpaper)) &&
- (_pReadFileObjHtmlBkgd->_hFile != INVALID_HANDLE_VALUE))
- {
- //The final Desktop.htt will be in ANSI only if the source html file is also in ansi.
- //So, get the type from the selected wallpaper object.
- _iDestFileCharset = _pReadFileObjHtmlBkgd->_iCharset;
- //
- // Write the BOM for UNICODE
- //
- if(_hFileHtml && (_iDestFileCharset == UNICODE_HTML_CHARSET))
- {
- DWORD cbWritten;
- WriteFile(_hFileHtml, (LPCSTR)&wUnicodeBOM, sizeof(wUnicodeBOM), &cbWritten, NULL);
- }
- //
- // Figure out where to insert the base href tag.
- //
- int iOffsetBase = 0;
- int iOffsetComponents;
- // 98/11/11 #248047 vtan: This code looks for a <BASE HREF=...> tag.
- // It used to use a scan for "<BASE" and assume that this was the
- // desired tag. HTML allows a "<BASEFONT>" tag which was being
- // mistaken for a "<BASE HREF=...>" tag. The code now looks for the
- // same string but looks at the character following the "<BASE" to
- // see if it's a white-space character.
- if(_iDestFileCharset == ANSI_HTML_CHARSET)
- {
- //The following function parses the ANSI input html file and finds various offsets
- _ParseAnsiInputHtmlFile(szSelectedWallpaper, &iOffsetBase, &iOffsetComponents);
- }
- else
- {
- //The following code parses the UNICODE input html wallpaper file.
- int iBaseTagStart;
- BOOL fUseBaseHref;
- LONG lOffsetDueToBOM = 0; //Character Offset due to the Byte Order Mark.
- //1 for UNICODE and 0 for ANSI files.
- fUseBaseHref = TRUE;
- _pReadFileObjHtmlBkgd->FileGetCurCharOffset(&lOffsetDueToBOM);
- iOffsetBase = (int)lOffsetDueToBOM;
- iBaseTagStart = _ScanForTagW(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, L"<BASE");
- if (iBaseTagStart != -1)
- {
- UINT uiCountChars, uiTryToRead;
- WCHAR wszBaseTagBuffer[6+1]; // allow for "<BASEx" plus a NULL.
- _pReadFileObjHtmlBkgd->FileSeekChars(iBaseTagStart, FILE_BEGIN);
- uiTryToRead = ARRAYSIZE(wszBaseTagBuffer) - 1;
- if(SUCCEEDED(_pReadFileObjHtmlBkgd->FileReadCharsW(wszBaseTagBuffer, uiTryToRead, &uiCountChars)) && uiCountChars)
- {
- WCHAR wc;
- wc = wszBaseTagBuffer[5];
- fUseBaseHref = ((wc != L' ') &&
- (wc != L'r') &&
- (wc != L'n') && // this covers the UNIX line break scheme
- (wc != L't'));
- }
- }
- if (fUseBaseHref)
- {
- TAGENTRYW rgteBase[] = {
- { L"<HEAD>", TRUE, },
- { L"<BODY", FALSE, },
- { L"<HTML>", TRUE, },
- };
- iOffsetBase = _ScanTagEntriesW(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, rgteBase, ARRAYSIZE(rgteBase));
- if (iOffsetBase == -1)
- {
- iOffsetBase = (int)lOffsetDueToBOM;
- }
- }
- //
- // Figure out where to insert the components.
- //
- TAGENTRYW rgteComponents[] = {
- { L"</BODY>", FALSE, },
- { L"</HTML>", FALSE, },
- };
- iOffsetComponents = _ScanTagEntriesW(_pReadFileObjHtmlBkgd, iOffsetBase, rgteComponents, ARRAYSIZE(rgteComponents));
- //
- // Write out the initial HTML up to the <HEAD> tag.
- //
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, (int)lOffsetDueToBOM, iOffsetBase);
- //
- // Write out the base tag.
- //
- if (fUseBaseHref)
- {
- //BASE tag must point to the base "URL". So, don't strip out the filename.
- _WriteHtmlFromIdF(IDS_BASE_TAG, szSelectedWallpaper);
- }
- // Figure out where to insert the DIV clause
- TAGENTRYW rgteBodyStart[] = {
- { L"<BODY", FALSE, },
- };
- int iOffsetBodyStart = _ScanTagEntriesW(_pReadFileObjHtmlBkgd, iOffsetBase, rgteBodyStart, ARRAYSIZE(rgteBodyStart));
- // Write out HTML until after the <BODY ......>
- if (iOffsetBodyStart == -1)
- { // the <BODY> tag is not found, so we need to insert it.
- // Copy over stuff until </HEAD>
- TAGENTRYW rgteHeadEnd[] = {
- { L"</HEAD>", TRUE, },
- };
- int iOffsetHeadEnd = _ScanTagEntriesW(_pReadFileObjHtmlBkgd, iOffsetBase, rgteHeadEnd, ARRAYSIZE(rgteHeadEnd));
- if(iOffsetHeadEnd != -1)
- {
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, iOffsetBase, iOffsetHeadEnd);
- iOffsetBase = iOffsetHeadEnd;
- }
- _WriteHtmlFromIdF(IDS_BODY_CENTER_WP2); // "<BODY>"
- _fNeedBodyEnd = TRUE;
- }
- else
- {
- TAGENTRYW rgteBodyEnd[] = {
- { L">", TRUE, },
- };
- int iOffsetBodyEnd = _ScanTagEntriesW(_pReadFileObjHtmlBkgd, iOffsetBodyStart, rgteBodyEnd, ARRAYSIZE(rgteBodyEnd));
- if (iOffsetBodyEnd == -1)
- { // An error in the HTML.
- iOffsetBodyEnd = iOffsetBodyStart; // BUGBUG: We need a better recovery idea.
- }
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, iOffsetBase, iOffsetBodyEnd);
- iOffsetBase = iOffsetBodyEnd;
- }
- }
- // Insert the DIV clause
- if(ema.iMonitors > 1)
- {
- int iIndexPrimaryMonitor;
- HMONITOR hMonitorPrimary;
- MONITORINFO monitorInfo;
- // 99/03/23 #275429 vtan: We used GetViewAreas() to fill in rcViewAreas above.
- // The code here used to assume that [0] ALWAYS referred to the primary monitor.
- // This isn't the case if the monitor settings are changed without a restart.
- // In order to compensate for this and always render the wallpaper into the
- // primary monitor, a search is performed to find a (left, top) that matches
- // one of the work areas and this is used as the primary monitor. If none can
- // be found then default to the old algorithm.
- hMonitorPrimary = GetPrimaryMonitor();
- monitorInfo.cbSize = sizeof(monitorInfo);
- TBOOL(GetMonitorInfo(hMonitorPrimary, &monitorInfo));
- iIndexPrimaryMonitor = -1;
- for (int i = 0; (iIndexPrimaryMonitor < 0) && (i < nViewAreas); ++i)
- {
- if ((monitorInfo.rcWork.left == rcViewAreas[i].left) && (monitorInfo.rcWork.top == rcViewAreas[i].top))
- {
- iIndexPrimaryMonitor = i;
- }
- }
- if (iIndexPrimaryMonitor < 0)
- iIndexPrimaryMonitor = 0;
- if ((nViewAreas <= 0) || (rcViewAreas[iIndexPrimaryMonitor].right == rcViewAreas[iIndexPrimaryMonitor].left))
- // The second case could occur on bootup
- {
- // Some error occured when getting the ViewAreas. Recover from the error by using the workarea.
- // Get the workarea of the primary monitor, since HTML wallpapers are displayed only there.
- GetMonitorWorkArea(hMonitorPrimary, &rcViewAreas[iIndexPrimaryMonitor]);
- }
- _WriteHtmlFromIdF(IDS_DIV_START3,
- rcViewAreas[iIndexPrimaryMonitor].left - ema.rcVirtualMonitor.left,
- rcViewAreas[iIndexPrimaryMonitor].top - ema.rcVirtualMonitor.top,
- rcViewAreas[iIndexPrimaryMonitor].right - rcViewAreas[iIndexPrimaryMonitor].left,
- rcViewAreas[iIndexPrimaryMonitor].bottom - rcViewAreas[iIndexPrimaryMonitor].top);
- }
- //
- // Write out HTML from after <HEAD> tag to just before </BODY> tag.
- //
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, iOffsetBase, iOffsetComponents);
- if(ema.iMonitors > 1)
- {
- _WriteHtmlFromId(IDS_DIV_END);
- }
- }
- else
- {
- if(_pReadFileObjHtmlBkgd)
- delete _pReadFileObjHtmlBkgd;
- _pReadFileObjHtmlBkgd = NULL;
- }
- }
- EXITPROC(2, "DS GenerateHtmlHeader!");
- }
- void CActiveDesktop::_WriteResizeable(COMPONENTA *pcomp)
- {
- TCHAR szResizeable[3];
- szResizeable[0] = TEXT('');
- //If Resize is set, then the comp is resizeable in both X and Y directions!
- if(pcomp->cpPos.fCanResize)
- lstrcat(szResizeable, TEXT("XY"));
- else
- {
- if(pcomp->cpPos.fCanResizeX)
- lstrcat(szResizeable, TEXT("X"));
- if(pcomp->cpPos.fCanResizeY)
- lstrcat(szResizeable, TEXT("Y"));
- }
- _WriteHtmlFromIdF(IDS_RESIZEABLE, szResizeable);
- }
- void CActiveDesktop::_WriteHtmlW(LPCWSTR wcBuf, UINT cchToWrite, UINT *pcchWritten)
- {
- ULONG cchWritten = 0;
- UINT uiSize;
- if(_pStream)
- {
- uiSize = sizeof(WCHAR);
- _pStream->Write((LPVOID)wcBuf, cchToWrite * uiSize, &cchWritten);
- }
- else
- {
- ASSERT(_hFileHtml);
- uiSize = (_iDestFileCharset == ANSI_HTML_CHARSET) ? sizeof(char) : sizeof(WCHAR);
- WriteFile(_hFileHtml, (LPCVOID)wcBuf, cchToWrite * uiSize, &cchWritten, NULL);
- }
- *pcchWritten = (UINT)(cchWritten/uiSize); //Convert to number of chars.
- }
- void CActiveDesktop::_GenerateHtmlPicture(COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS GenerateHtmlPicture(pcomp=%08X)");
- //
- // Write out the image src HTML.
- //
- TCHAR szUrl[INTERNET_MAX_URL_LENGTH];
- DWORD cch=ARRAYSIZE(szUrl);
- if (FAILED(UrlCreateFromPath(pcomp->szSource, szUrl, &cch, 0)))
- {
- lstrcpy(szUrl, pcomp->szSource);
- }
- _WriteHtmlFromIdF(IDS_IMAGE_BEGIN2, pcomp->dwID, szUrl);
- //
- // Write out whether this image is resizeable or not!
- //
- _WriteResizeable(pcomp);
- //
- // Write out the URL that must be used for subscription purposes.
- //
- _WriteHtmlFromIdF(IDS_SUBSCRIBEDURL, pcomp->szSubscribedURL);
- //
- // Write out the image location HTML.
- //
- if ((pcomp->cpPos.dwWidth == COMPONENT_DEFAULT_WIDTH) &&
- (pcomp->cpPos.dwHeight == COMPONENT_DEFAULT_HEIGHT))
- {
- _WriteHtmlFromIdF(IDS_IMAGE_LOCATION, _fSingleItem ? 0 : pcomp->cpPos.iLeft, _fSingleItem ? 0 : pcomp->cpPos.iTop, pcomp->cpPos.izIndex);
- }
- else
- {
- _WriteHtmlFromIdF(IDS_IMAGE_SIZE, _fSingleItem ? 0 : pcomp->cpPos.iLeft, _fSingleItem ? 0 : pcomp->cpPos.iTop,
- pcomp->cpPos.dwWidth, pcomp->cpPos.dwHeight, pcomp->cpPos.izIndex);
- }
- EXITPROC(2, "DS GenerateHtmlPicture!");
- }
- void CActiveDesktop::_GenerateHtmlDoc(COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS GenerateHtmlDoc(pcomp=%08X)");
- TCHAR szUrl[INTERNET_MAX_URL_LENGTH];
- DWORD dwSize = ARRAYSIZE(szUrl);
- LPTSTR lpszUrl = szUrl;
- if(FAILED(UrlCreateFromPath(pcomp->szSource, szUrl, &dwSize, 0)))
- lpszUrl = pcomp->szSource;
- //
- // Write out the DIV header HTML.
- //
- _WriteHtmlFromIdF(IDS_DIV_START2, pcomp->dwID, lpszUrl);
- //
- // Write out whether this component is resizeable or not!
- //
- _WriteResizeable(pcomp);
- //
- // Write out the DIV location HTML.
- //
- _WriteHtmlFromIdF(IDS_DIV_SIZE, pcomp->cpPos.dwHeight, _fSingleItem ? 0 : pcomp->cpPos.iLeft,
- _fSingleItem ? 0 : pcomp->cpPos.iTop, pcomp->cpPos.dwWidth, pcomp->cpPos.izIndex);
- //
- // Extract the doc contents directly into the HTML.
- //
- _WriteHtmlFromFile(pcomp->szSource);
- //
- // Close the DIV section.
- //
- _WriteHtmlFromId(IDS_DIV_END);
- EXITPROC(2, "DS GenerateHtmlDoc!");
- }
- void CActiveDesktop::_GenerateHtmlSite(COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS GenerateHtmlSite(pcomp=%08X)");
- //
- // Write out the frame src HTML.
- //
- TCHAR szUrl[INTERNET_MAX_URL_LENGTH];
- DWORD cch=ARRAYSIZE(szUrl);
- if (FAILED(UrlCreateFromPath(pcomp->szSource, szUrl, &cch, 0)))
- {
- lstrcpy(szUrl, pcomp->szSource);
- }
- DWORD currentURLLength, maximumURLLength;
- TCHAR *pURL, formatBuffer[0x0100];
- // 98/09/29 #211384 vtan: There is a limitation in wvsprintf.
- // It only allows 2048 bytes in its buffer. If the URL is
- // longer than 1024 characters less the IDS_IFRAME_BEGIN2
- // string length less the component ID less "scrolling=no"
- // if the component cannot be scrolled then the URL string
- // will not be correctly inserted into the IDS_IFRAME_BEGIN2
- // string and there will be a missing end-quote and trident
- // will fail to render desktop.htt correctly.
- // To correct against this the followING limits the length of
- // the URL to this maximum and truncates any characters
- // beyond the limit so that the IDS_IFRAME_BEGIN2 string
- // contains its end-quote and trident does not barf.
- // The above condition is a boundary condition and this
- // check is quick so that the calculations that follow do
- // not have to be executed repeatedly.
- currentURLLength = lstrlen(szUrl);
- if (currentURLLength > 768) // a hard-coded limit
- {
- maximumURLLength = 1024; // wvsprintf limit
- LoadString(HINST_THISDLL, IDS_IFRAME_BEGIN2, formatBuffer, ARRAYSIZE(formatBuffer));
- maximumURLLength -= lstrlen(formatBuffer); // IDS_IFRAME_BEGIN2
- maximumURLLength -= 16; // pcomp->dwID
- maximumURLLength -= lstrlen(TEXT("scrolling=no")); // pcomp->fNoScroll
- if (currentURLLength > maximumURLLength)
- szUrl[maximumURLLength] = static_cast<TCHAR>('');
- }
- _WriteHtmlFromIdF(IDS_IFRAME_BEGIN2, pcomp->dwID, szUrl, pcomp->fNoScroll ? TEXT("scrolling=no") : c_szNULL);
- //
- // Write out whether this Component is resizeable or not!
- //
- _WriteResizeable(pcomp);
- // 98/09/29 #211384 vtan: See above.
- currentURLLength = lstrlen(pcomp->szSubscribedURL);
- if (currentURLLength > 768)
- {
- lstrcpy(szUrl, pcomp->szSubscribedURL);
- maximumURLLength = 1024;
- LoadString(HINST_THISDLL, IDS_SUBSCRIBEDURL, formatBuffer, ARRAYSIZE(formatBuffer));
- maximumURLLength -= lstrlen(formatBuffer); // IDS_SUBSCRIBEDURL
- if (currentURLLength > maximumURLLength)
- szUrl[maximumURLLength] = static_cast<TCHAR>('');
- pURL = szUrl;
- }
- else
- pURL = pcomp->szSubscribedURL;
- //
- // Write out the URL that must be used for subscription purposes.
- //
- _WriteHtmlFromIdF(IDS_SUBSCRIBEDURL, pURL);
- //
- // Write out the frame location HTML.
- //
- _WriteHtmlFromIdF(IDS_IFRAME_SIZE, _fSingleItem ? 0 : pcomp->cpPos.iLeft, _fSingleItem ? 0 : pcomp->cpPos.iTop,
- pcomp->cpPos.dwWidth, pcomp->cpPos.dwHeight, pcomp->cpPos.izIndex);
- EXITPROC(2, "DS GenerateHtmlSite!");
- }
- void CActiveDesktop::_GenerateHtmlControl(COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS GenerateHtmlControl(pcomp=%08X)");
- ASSERT(pcomp);
- // Did the Administrator restrict "Channel UI"?
- if (SHRestricted2W(REST_NoChannelUI, NULL, 0))
- {
- TCHAR szChannelOCGUID[GUIDSTR_MAX];
- SHStringFromGUID(CLSID_ChannelOC, szChannelOCGUID, ARRAYSIZE(szChannelOCGUID));
- if (!StrCmpNI(pcomp->szSource, &(szChannelOCGUID[1]), lstrlen(pcomp->szSource)-3))
- {
- // Yes, so we need to hide the Channel Desktop Component.
- // Return here before we generate it.
- return;
- }
- }
- //
- // Write out the control HTML.
- //
- // First the control header
- _WriteHtmlFromIdF(IDS_CONTROL_1, pcomp->dwID);
- // then the size
- _WriteHtmlFromIdF(IDS_CONTROL_2, pcomp->cpPos.dwHeight, _fSingleItem ? 0 : pcomp->cpPos.iLeft,
- _fSingleItem ? 0 : pcomp->cpPos.iTop, pcomp->cpPos.dwWidth, pcomp->cpPos.izIndex);
- //
- // Write out whether this Control is resizeable or not!
- //
- _WriteResizeable(pcomp);
- // Finally the rest of the control
- _WriteHtmlFromIdF(IDS_CONTROL_3, pcomp->szSource);
- EXITPROC(2, "DS GenerateHtmlControl!");
- }
- void CActiveDesktop::_GenerateHtmlComponent(COMPONENTA *pcomp)
- {
- ENTERPROC(2, "DS GenerateHtmlComponent(pcomp=%08X)");
- switch(pcomp->iComponentType)
- {
- case COMP_TYPE_PICTURE:
- _GenerateHtmlPicture(pcomp);
- break;
- case COMP_TYPE_HTMLDOC:
- _GenerateHtmlDoc(pcomp);
- break;
- case COMP_TYPE_WEBSITE:
- _GenerateHtmlSite(pcomp);
- break;
- case COMP_TYPE_CONTROL:
- _GenerateHtmlControl(pcomp);
- break;
- }
- EXITPROC(2, "DS GenerateHtmlComponent!");
- }
- void CActiveDesktop::_GenerateHtmlFooter(void)
- {
- ENTERPROC(2, "DS GenerateHtmlFooter()");
- //
- // Write out the deskmovr object.
- //
- if (!_fNoDeskMovr)
- {
- TCHAR szDeskMovrFile[MAX_PATH];
- GetWindowsDirectory(szDeskMovrFile, ARRAYSIZE(szDeskMovrFile));
- lstrcat(szDeskMovrFile, DESKMOVR_FILENAME);
- _WriteHtmlFromFile(szDeskMovrFile);
- }
- //
- // Write out the concluding HTML tags.
- //
- if (_pReadFileObjHtmlBkgd)
- {
- if(_fNeedBodyEnd)
- { // We had introduced the <BODY> tag by ourselves.
- _WriteHtmlFromId(IDS_BODY_END2);
- _fNeedBodyEnd = FALSE;
- }
- _WriteHtmlFromReadFileObj(_pReadFileObjHtmlBkgd, -1, -1);
- delete _pReadFileObjHtmlBkgd; //Close the file and cleanup!
- _pReadFileObjHtmlBkgd = NULL;
- }
- else
- {
- _WriteHtmlFromId(IDS_BODY_END);
- }
- EXITPROC(2, "DS GenerateHtmlFooter!");
- }
- void CActiveDesktop::_GenerateHtml(void)
- {
- ENTERPROC(2, "DS GenerateHtml()");
- TCHAR szHtmlFile[MAX_PATH];
- //
- // Compute the filename.
- //
- szHtmlFile[0] = TEXT('');
- GetPerUserFileName(szHtmlFile, ARRAYSIZE(szHtmlFile), DESKTOPHTML_FILENAME);
- //
- // Recreate the file.
- //
- _hFileHtml = CreateFile(szHtmlFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM, NULL);
- if (_hFileHtml != INVALID_HANDLE_VALUE)
- {
- _GenerateHtmlHeader();
- if (_co.fEnableComponents && _hdsaComponent && DSA_GetItemCount(_hdsaComponent) && !SHRestricted(REST_NODESKCOMP))
- {
- int i;
- for (i=0; i<DSA_GetItemCount(_hdsaComponent); i++)
- {
- COMPONENTA comp;
- comp.dwSize = sizeof(COMPONENTA);
- if ((DSA_GetItem(_hdsaComponent, i, &comp) != -1) && (comp.fChecked))
- {
- _GenerateHtmlComponent(&comp);
- }
- }
- }
- _GenerateHtmlFooter();
- CloseHandle(_hFileHtml);
- SetDesktopFlags(COMPONENTS_DIRTY, 0);
- }
- else
- {
- // 99/05/19 #340772 vtan: If unable to open desktop.htt it's probably
- // in use by another process or task (perhaps trident is trying to
- // render it). In this case mark it dirty so that it will get recreated
- // - yet again but this time with more current data.
- SetDesktopFlags(COMPONENTS_DIRTY, COMPONENTS_DIRTY);
- }
- EXITPROC(2, "DS GenerateHtml!");
- }
- HRESULT CActiveDesktop::GenerateDesktopItemHtml(LPCWSTR pwszFileName, COMPONENT *pcomp, DWORD dwReserved)
- {
- HRESULT hres = E_FAIL;
- ENTERPROC(2, "DS GenerateComponentHtml(pcomp=%08X)", pcomp);
- LPTSTR pszFileName;
- //Check for the input parameters
- if(!pwszFileName || (pcomp && (pcomp->dwSize != SIZEOF(*pcomp)) && (pcomp->dwSize != SIZEOF(IE4COMPONENT))))
- return E_INVALIDARG;
- ASSERT(!dwReserved); // These should be 0
- #ifndef UNICODE
- CHAR szFileName[MAX_PATH];
- SHUnicodeToAnsi(pwszFileName, szFileName, ARRAYSIZE(szFileName));
- pszFileName = szFileName;
- #else
- pszFileName = (LPTSTR)pwszFileName;
- #endif
- //
- // Create the file.
- //
- _hFileHtml = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL, NULL);
- if (_hFileHtml != INVALID_HANDLE_VALUE)
- {
- _fNoDeskMovr = TRUE;
- _fBackgroundHtml = TRUE;
- //Check if we need to add a component
- if(pcomp)
- {
- COMPONENTA CompA;
- CompA.dwSize = sizeof(CompA);
- WideCompToMultiComp(pcomp, &CompA);
- _fSingleItem = TRUE;
- _GenerateHtmlHeader();
- _GenerateHtmlComponent(&CompA);
- _GenerateHtmlFooter();
- _fSingleItem = FALSE;
- }
- else
- {
- //generate just the header and the footer with proper
- // wallpaper and pattern info!
- _GenerateHtmlHeader();
- _GenerateHtmlFooter();
- }
- _fBackgroundHtml = FALSE;
- _fNoDeskMovr = FALSE;
- CloseHandle(_hFileHtml);
- hres = S_OK;
- }
- _hFileHtml = NULL;
- EXITPROC(2, "DS GenerateComponentHtml=%d", hres);
- return hres;
- }
- //
- // AddUrl
- //
- //
- HRESULT CActiveDesktop::AddUrl(HWND hwnd, LPCWSTR pszSourceW, LPCOMPONENT pcomp, DWORD dwFlags)
- {
- LPTSTR pszExt;
- HRESULT fOkay = TRUE;
- BOOL fExtIsCdf,fPathIsUrl;
- BOOL fSubscribed = FALSE;
- COMPONENT compLocal;
- COMPONENTA compA;
- TCHAR szSource[INTERNET_MAX_URL_LENGTH];
- // 98/08/28 vtan #202777: The following if statement sanitizes parameters
- // passed to AddUrl(). The statements following the "||" are executed
- // despite the for pcomp against NULL. This causes an access violation
- // and an exception to be thrown.
- #if 0
- //Check for the input parameters.
- if(!pszSourceW || (pcomp &&
- ((pcomp->dwSize != SIZEOF(*pcomp)) && (pcomp->dwSize != SIZEOF(IE4COMPONENT))) ||
- ((pcomp->dwSize == SIZEOF(*pcomp)) && !VALIDATESTATE(pcomp->dwCurItemState))))
- return E_INVALIDARG;
- #else
- // The following performs the same comparison but is spread into three
- // separate comparisons. As performance is not a critical issue here
- // but correctness is this makes the tests clear and understandable.
- // The invalid conditions are described.
- // Validate input parameters. Invalid parameters are:
- // 1) NULL pszSourceW
- // 2) pcomp->dwSize for a COMPONENT struct but invalid pcomp->dwCurItemState
- // 3) pcomp->dwSize is not for a COMPONENT struct nor for a IE4COMPONENT struct
- if (pszSourceW == NULL)
- return(E_INVALIDARG);
- if (pcomp != NULL)
- {
- if ((pcomp->dwSize == sizeof(*pcomp)) && !VALIDATESTATE(pcomp->dwCurItemState))
- return(E_INVALIDARG);
- if ((pcomp->dwSize != sizeof(*pcomp)) && (pcomp->dwSize != sizeof(IE4COMPONENT)))
- return(E_INVALIDARG);
- }
- #endif
- // Catch folks that call our API's to add components and prevent them from doing
- // so if the restriction is in place.
- if (SHIsRestricted(NULL, REST_NOADDDESKCOMP))
- return E_ACCESSDENIED;
- if (!pcomp)
- {
- pcomp = &compLocal;
- pcomp->dwSize = sizeof(compLocal);
- pcomp->dwCurItemState = IS_NORMAL;
- }
- // Attempt to come up with a reasonable window handle if none is passed in. ParseDesktopComponent
- // will fail to attempt to create a subscription if a NULL window handle is passed in.
- if (!hwnd)
- hwnd = GetLastActivePopup(GetActiveWindow());
- compA.dwSize = sizeof(compA);
- compA.dwCurItemState = (pcomp->dwSize != SIZEOF(IE4COMPONENT)) ? pcomp->dwCurItemState : IS_NORMAL;
- g_pActiveDesk = this;
- SHUnicodeToTChar(pszSourceW, szSource, ARRAYSIZE(szSource));
- pszExt = PathFindExtension(szSource);
- fExtIsCdf = lstrcmpi(pszExt, TEXT(".CDF")) == 0;
- fPathIsUrl = PathIsURL(szSource) && !UrlIsFileUrl(szSource);
- if (FindComponent(szSource))
- {
- if (dwFlags & ADDURL_SILENT)
- {
- lstrcpy(compA.szSource, szSource);
- MultiCompToWideComp(&compA, pcomp);
- RemoveDesktopItem(pcomp, 0);
- }
- else
- {
- // This is a long string. So,...
- TCHAR szMsg[512];
- TCHAR szMsg2[256];
- TCHAR szTitle[128];
- LoadString(HINST_THISDLL, IDS_COMP_EXISTS, szMsg, ARRAYSIZE(szMsg));
- LoadString(HINST_THISDLL, IDS_COMP_EXISTS_2, szMsg2, ARRAYSIZE(szMsg2));
- lstrcat(szMsg, szMsg2);
- LoadString(HINST_THISDLL, IDS_COMP_TITLE, szTitle, ARRAYSIZE(szTitle));
- MessageBox(hwnd, szMsg, szTitle, MB_OK);
- fOkay = FALSE;
- }
- }
- if (fOkay && CheckForExistingSubscription(szSource))
- {
- if ((dwFlags & ADDURL_SILENT) ||
- (ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE(IDS_COMP_SUBSCRIBED),
- MAKEINTRESOURCE(IDS_COMP_TITLE), MB_YESNO) == IDYES))
- {
- DeleteFromSubscriptionList(szSource);
- }
- else
- {
- fOkay = FALSE;
- }
- }
- if (fOkay)
- {
- if (fPathIsUrl || fExtIsCdf)
- {
- WCHAR szUrlW[INTERNET_MAX_URL_LENGTH];
- SHTCharToUnicode(szSource, szUrlW, ARRAYSIZE(szUrlW));
- HRESULT hr;
- IProgressDialog * pProgressDlg = NULL;
- DECLAREWAITCURSOR;
- // 98/12/16 vtan #250938: Cannot add new components that are not
- // local with ICW run to completion. Tell the user and launch ICW.
- if (!IsICWCompleted())
- {
- if ((dwFlags & ADDURL_SILENT) == 0)
- {
- ShellMessageBox(HINST_THISDLL, hwnd, MAKEINTRESOURCE(IDS_COMP_ICW_ADD), MAKEINTRESOURCE(IDS_COMP_ICW_TITLE), MB_OK);
- LaunchICW();
- }
- fOkay = FALSE;
- }
- else
- {
- SetWaitCursor();
- // ParseDesktopComponent can hang for a long time, we need some sort of progress
- // UI up before we call it.
- if (!(dwFlags & ADDURL_SILENT) && !fExtIsCdf)
- {
- if (pProgressDlg = CProgressDialog_CreateInstance(IDS_COMP_TITLE, IDA_ISEARCH, g_hinst))
- {
- WCHAR szConnectingW[80];
- TCHAR szConnecting[80];
- LoadString(HINST_THISDLL, IDS_CONNECTING, szConnecting, ARRAYSIZE(szConnecting));
- SHTCharToUnicode(szConnecting, szConnectingW, ARRAYSIZE(szConnectingW));
- pProgressDlg->SetLine(1, szConnectingW, FALSE, NULL);
- pProgressDlg->SetLine(2, szUrlW, TRUE, NULL);
- pProgressDlg->StartProgressDialog(hwnd, NULL, PROGDLG_AUTOTIME | PROGDLG_NOPROGRESSBAR, NULL);
- }
- }
- hr = ParseDesktopComponent(hwnd, szUrlW, pcomp);