Beispiel #1
0
BOOL SetLanguageSpecifigHandles(LPCWSTR szAppPath)
{
	CRegKey RegKey;
	CStringW LangFile;
	if (RegKey.OpenKey(HKCU,g_szRegKey,
		CRegKey::openExist|CRegKey::samRead)==ERROR_SUCCESS)
	{
		RegKey.QueryValue(L"Language",LangFile);
		RegKey.CloseKey();
	}
	if (LangFile.IsEmpty())
		LangFile=L"lan_en.dll";

	CStringW Path(szAppPath,LastCharIndex(szAppPath,L'\\')+1);
	
	HINSTANCE hLib=FileSystem::LoadLibrary(Path+LangFile);
	if (hLib==NULL)
	{
		hLib=FileSystem::LoadLibrary(Path+"lan_en.dll");

		if (hLib==NULL)
		{
			fwprintf(stderr,L"Cannot load language file '%s'\n",(LPCWSTR)Path);
			return FALSE;
		}

		fwprintf(stderr,L"Cannot load language file '%s', using 'lan_en.dll'\n",(LPCWSTR)LangFile);
	}

	SetResourceHandle(hLib,LanguageSpecificResource);
	return TRUE;
}
Beispiel #2
0
BOOL ShellFunctions::RunRegistryCommand(HKEY hKey,LPCWSTR szFile)
{
	if (!IsUnicodeSystem())
		return RunRegistryCommand(hKey,W2A(szFile));


	PROCESS_INFORMATION pi;
	STARTUPINFOW si;
	CRegKey CommandKey;
	CStringW ExecuteStr;
	CStringW CommandLine;
	int i;

	if (CommandKey.OpenKey(hKey,"command",CRegKey::openExist|CRegKey::samAll)!=ERROR_SUCCESS)
		return FALSE;
	if (CommandKey.QueryValue(L"",ExecuteStr)<2)
		return FALSE;
	i=ExecuteStr.FindFirst(L'%');
	while (i!=-1)
	{
		if (ExecuteStr[i+1]==L'1')
		{
			CommandLine.Copy(ExecuteStr,i);
			CommandLine<<szFile;
			CommandLine<<((LPCWSTR)ExecuteStr+i+2);
			break;
		}
		i=ExecuteStr.FindNext(L'%',i);
	}
	if (i==-1)
		CommandLine=ExecuteStr;
	if (!ExpandEnvironmentStringsW(CommandLine,ExecuteStr.GetBuffer(1000),1000))
		ExecuteStr.Swap(CommandLine);
	si.cb=sizeof(STARTUPINFOW);
	si.lpReserved=NULL;
	si.cbReserved2=0;
	si.lpReserved2=NULL;
	si.lpDesktop=NULL;
	si.lpTitle=NULL;
	si.dwFlags=STARTF_USESHOWWINDOW;
	si.wShowWindow=SW_SHOWDEFAULT;
	if (!CreateProcessW(NULL,ExecuteStr.GetBuffer(),NULL,
		NULL,FALSE,CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS,
		NULL,NULL,&si,&pi))
	{
		CommandKey.CloseKey();
		return FALSE;
	}
	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
	CommandKey.CloseKey();
	return TRUE;
}
BOOL CListCtrl::SaveColumnsState(HKEY hRootKey,LPCSTR lpKey,LPCSTR lpSubKey) const
{
	CRegKey RegKey;
	if (lpKey==NULL)
		RegKey.m_hKey=hRootKey;
	else if (RegKey.OpenKey(hRootKey,lpKey,CRegKey::createNew|CRegKey::samAll)!=ERROR_SUCCESS)
		return FALSE;
	LVCOLUMN lc;
	fMemSet(&lc,0,sizeof(LVCOLUMN));
	lc.mask=LVCF_WIDTH;
	
	int nColumns=GetColumnCount();
	if (nColumns==0)
	{
		if (lpKey==NULL)
			RegKey.m_hKey=NULL;
		return FALSE;
	}
	
	int* pData=new int[1+2*nColumns];
	if (pData==NULL)
	{
		if (lpKey==NULL)
			RegKey.m_hKey=NULL;
		return FALSE;
	}
	pData[0]=nColumns;
	

	for (int i=0;i<nColumns;i++)
	{
		if (::SendMessage(m_hWnd,LVM_GETCOLUMN,i,LPARAM(&lc)))
			pData[1+i]=lc.cx;
		else
			pData[1+i]=100;
	}
	
	if (!::SendMessage(m_hWnd,LVM_GETCOLUMNORDERARRAY,nColumns,LPARAM(pData+1+nColumns)))
	{
		for (int i=0;i<nColumns;i++)
			pData[1+nColumns+i]=i;
	}

	BOOL bRet=RegKey.SetValue(lpSubKey,(LPSTR)pData,sizeof(int)*(1+2*nColumns),REG_BINARY)==ERROR_SUCCESS;
	RegKey.CloseKey();
	delete[] pData;
	if (lpKey==NULL)
		RegKey.m_hKey=NULL;
	return bRet;
}
Beispiel #4
0
BOOL CWnd::SavePosition(HKEY hRootKey,LPCSTR lpKey,LPCSTR lpSubKey) const
{
	CRegKey RegKey;
	if (lpKey==NULL)
		RegKey.m_hKey=hRootKey;
	else if (RegKey.OpenKey(hRootKey,lpKey,CRegKey::createNew|CRegKey::samAll)!=ERROR_SUCCESS)
		return FALSE;
	
	WINDOWPLACEMENT wp;
	wp.length=sizeof(WINDOWPLACEMENT);
	GetWindowPlacement(&wp);
	
	BOOL bRet=RegKey.SetValue(lpSubKey,LPSTR(&wp),sizeof(WINDOWPLACEMENT),REG_BINARY)==ERROR_SUCCESS;

	if (lpKey==NULL)
		RegKey.m_hKey=NULL;
	return bRet;
}
BOOL CListCtrl::LoadColumnsState(HKEY hRootKey,LPCSTR lpKey,LPCSTR lpSubKey)
{
	CRegKey RegKey;
	if (lpKey==NULL)
		RegKey.m_hKey=hRootKey;
	else if (RegKey.OpenKey(hRootKey,lpKey,CRegKey::openExist|CRegKey::samRead)!=ERROR_SUCCESS)
		return FALSE;
	DWORD nDataLength=RegKey.QueryValueLength(lpSubKey);
	if (nDataLength<4)
	{
		if (lpKey==NULL)
			RegKey.m_hKey=NULL;
		return FALSE;
	}
	int* pData=(int*)new BYTE[nDataLength];
	DWORD dwRet=RegKey.QueryValue(lpSubKey,(LPSTR)pData,nDataLength);
	if (lpKey==NULL)
		RegKey.m_hKey=NULL;
	if (dwRet<nDataLength)
	{
		delete[] (BYTE*)pData;
		return FALSE;
	}

	if ((pData[0]*2+1)*sizeof(int)!=nDataLength)
	{
		delete[] (BYTE*)pData;
		return FALSE;
	}
	BOOL nOrderOK=FALSE;
	for (int i=0;i<pData[0];i++)
	{
		SetColumnWidth(i,pData[1+i]);
		if (pData[1+pData[0]+i]!=0)
			nOrderOK=TRUE;
	}	
	if (nOrderOK)
		SetColumnOrderArray(pData[0],pData+1+pData[0]);
	delete[] (BYTE*)pData;
	return TRUE;
}
Beispiel #6
0
BOOL GetIMAPIBurningDevices(CArray<LPWSTR>& aDevicePaths)
{
	CRegKey RegKey;
	if (RegKey.OpenKey(HKCR,"IMAPI.MSDiscMasterObj\\CLSID",CRegKey::defRead)!=ERROR_SUCCESS)
		return FALSE;

	WCHAR szCLSID[50];
	if (RegKey.QueryValue(L"",szCLSID,50)==0)
		return FALSE;

	CLSID clsid;
	if (CLSIDFromString(szCLSID,&clsid)!=NO_ERROR)
		return FALSE;

	
	HRESULT hRes;
	IDiscMaster* pdm;
	hRes=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,IID_IDiscMaster,(void**)&pdm);
	if (FAILED(hRes))
		return FALSE;

	hRes=pdm->Open();
	if (FAILED(hRes))
	{
		pdm->Release();
		return FALSE;
	}

	IEnumDiscRecorders* pedr;
	hRes=pdm->EnumDiscRecorders(&pedr);
	if (SUCCEEDED(hRes))
	{
		IDiscRecorder* pdr;
		DWORD dwReturned;
		while ((hRes=pedr->Next(1,&pdr,&dwReturned))==S_OK)
		{
			BSTR bPath;
			hRes=pdr->GetPath(&bPath);
			if (SUCCEEDED(bPath))
			{
				if (bPath[0]=='\\')
				{
					WCHAR szName[MAX_PATH];
					WCHAR szTemp[MAX_PATH]=L"";
					WCHAR drive[]=L" :";
					GetLogicalDriveStringsW(MAX_PATH,szTemp);

					LPWSTR pPtr=szTemp;
					while (*pPtr!='\0')
					{
						*drive=*pPtr;
						if (QueryDosDeviceW(drive, szName,MAX_PATH))
						{
							if (wcscmp(szName,bPath)==0)
								aDevicePaths.Add(alloccopy(pPtr));
						}

						pPtr+=istrlenw(pPtr)+1;
					}
				}
				else
					aDevicePaths.Add(alloccopy(bPath));
			}

			pdr->Release();
		}
		pedr->Release();
	}


	pdm->Close();
	pdm->Release();

	return TRUE;
}
Beispiel #7
0
BOOL CWnd::LoadPosition(HKEY hRootKey,LPCSTR lpKey,LPCSTR lpSubKey,DWORD fFlags)
{
	CRegKey RegKey;
	if (lpKey==NULL)
		RegKey.m_hKey=hRootKey;
	else if (RegKey.OpenKey(hRootKey,lpKey,CRegKey::openExist|CRegKey::samRead)!=ERROR_SUCCESS)
		return FALSE;
	
	WINDOWPLACEMENT wp;
    DWORD nRet=RegKey.QueryValue(lpSubKey,LPSTR(&wp),sizeof(WINDOWPLACEMENT));
	if (nRet==sizeof(WINDOWPLACEMENT) && wp.length==sizeof(WINDOWPLACEMENT))
	{
		switch (wp.showCmd)
		{
		case SW_MAXIMIZE:
			{
				if (fFlags&fgOnlySpecifiedPosition)
				{
					if (fFlags&fgAllowMaximized)
						ShowWindow(swMaximize);
					if (lpKey==NULL)
						RegKey.m_hKey=NULL;
					return TRUE;
				}


				// If tray on left or on top, adjust position such that it won't go over the tray
				HWND hShellTrayWnd=FindWindow("Shell_TrayWnd",NULL); // Whole tray window
				if (hShellTrayWnd!=NULL)
				{
					CRect rcWindowRect,rcTrayRect;
					GetWindowRect(&rcWindowRect);
					::GetWindowRect(hShellTrayWnd,&rcTrayRect);
					int nFullScreenCX=GetSystemMetrics(SM_CXFULLSCREEN);
						
					if (rcTrayRect.top<4 && rcTrayRect.left<4)
					{
						if (rcTrayRect.right>=nFullScreenCX) // Tray top
						{
							wp.rcNormalPosition.top+=rcTrayRect.Height();
							wp.rcNormalPosition.bottom+=rcTrayRect.Height();
						}
						else // Tray on left
						{
							wp.rcNormalPosition.left+=rcTrayRect.Width();
							wp.rcNormalPosition.right+=rcTrayRect.Width();
						}
					} 
				}


				SetWindowPos(HWND_TOP,wp.rcNormalPosition.left,wp.rcNormalPosition.top,
					wp.rcNormalPosition.right-wp.rcNormalPosition.left,wp.rcNormalPosition.bottom-wp.rcNormalPosition.top,
					SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOREDRAW);
				if (fFlags&fgOnlyNormalPosition)
				{
					if (lpKey==NULL)
						RegKey.m_hKey=NULL;
					return TRUE;
				}



				if (!(fFlags&fgAllowMaximized))
					wp.showCmd=SW_SHOWNORMAL;
				break;
			}
		case SW_SHOWMINIMIZED:
		case SW_MINIMIZE:
			if (fFlags&fgOnlySpecifiedPosition)
			{
				if (wp.flags&WPF_RESTORETOMAXIMIZED)
				{
					if (fFlags&fgAllowMaximized)
						ShowWindow(swMaximize);
				}
				else if (fFlags&fgAllowMinimized)
					ShowWindow(swMinimize);
				else
				{
					wp.showCmd=SW_SHOWNORMAL;
					break;
				}
				
				if (lpKey==NULL)
					RegKey.m_hKey=NULL;
                return TRUE;
			}

			
			SetWindowPos(HWND_TOP,wp.rcNormalPosition.left,wp.rcNormalPosition.top,
				wp.rcNormalPosition.right-wp.rcNormalPosition.left,wp.rcNormalPosition.bottom-wp.rcNormalPosition.top,
				SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOREDRAW);

			if (fFlags&fgOnlyNormalPosition)
			{
				if (lpKey==NULL)
					RegKey.m_hKey=NULL;
                return TRUE;
			}
			
				
			if (!(fFlags&fgAllowMinimized))
				wp.showCmd=wp.flags&WPF_RESTORETOMAXIMIZED?SW_SHOWMAXIMIZED:SW_SHOWNORMAL;
			break;
		case SW_HIDE:
			if (fFlags&fgOnlySpecifiedPosition)
			{
				if (fFlags&fgAllowHide)
					ShowWindow(swHide);
				if (lpKey==NULL)
					RegKey.m_hKey=NULL;
                return TRUE;
			}
			SetWindowPos(HWND_TOP,wp.rcNormalPosition.left,wp.rcNormalPosition.top,
				wp.rcNormalPosition.right-wp.rcNormalPosition.left,wp.rcNormalPosition.bottom-wp.rcNormalPosition.top,
				SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOREDRAW);
			if (fFlags&fgOnlyNormalPosition)
			{
				if (lpKey==NULL)
					RegKey.m_hKey=NULL;
                return TRUE;
			}
			if (!(fFlags&fgAllowHide))
				wp.showCmd=SW_SHOWNORMAL;
			break;
		default:
			wp.showCmd=SW_SHOWNORMAL;
			break;
		}
	}	
	else
	{
		if (lpKey==NULL)
			RegKey.m_hKey=NULL;
		return FALSE;
	}

	if (fFlags&fgNoSize)
	{
		WINDOWPLACEMENT wpCurrent;
		wpCurrent.length=sizeof(WINDOWPLACEMENT);
		GetWindowPlacement(&wpCurrent);
		wp.rcNormalPosition.right=wp.rcNormalPosition.left+
			(wpCurrent.rcNormalPosition.right-wpCurrent.rcNormalPosition.left);
		wp.rcNormalPosition.bottom=wp.rcNormalPosition.top+
			(wpCurrent.rcNormalPosition.bottom-wpCurrent.rcNormalPosition.top);
	}

	SetWindowPlacement(&wp);
	if (lpKey==NULL)
		RegKey.m_hKey=NULL;
	return TRUE;
}
Beispiel #8
0
BOOL SystemInfo(LPSYSTEMINFO info)
{
#ifdef WIN32
	OSVERSIONINFO ver;
	info->is32BIT=TRUE;
	ver.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx(&ver);
	switch(ver.dwPlatformId)
	{
		case VER_PLATFORM_WIN32s:
			info->System=osWin32S;
			break;
		case VER_PLATFORM_WIN32_WINDOWS:
			info->System=osWin95;
			break;
		case VER_PLATFORM_WIN32_NT:
			info->System=osWinNT;
			break;
	}
	info->hiWINVer=ver.dwMajorVersion;
	info->loWINVer=ver.dwMinorVersion;
    info->hiOSVer=0;
    info->loOSVer=0;
	info->hiIEVer=0;
	info->loIEVer=0;
	CRegKey Key;
	if (Key.OpenKey(HKLM,"SOFTWARE\\Microsoft\\Internet Explorer",CRegKey::openExist|CRegKey::samRead)==NOERROR)
	{
		CString Version;
		if (Key.QueryValue("Version",Version))
		{
			int hi=Version.FindFirst('.');
			int lo=Version.FindNext('.',hi);
			info->hiIEVer=atoi(Version.Left(hi));
			info->loIEVer=atoi(Version.Mid(hi,lo));
		}
		return FALSE;
	}	
	return TRUE;
#else
    WORD _ax=0;
    __asm__("
      movw $0x1600,%%ax\n
      int $0x2f\n
      movw %%ax,%0"
      :"=g" (_ax)
      :
      : "memory","ax","bx","cx","dx"
    );
    info->hiWINVer=LOBYTE(_ax);
    info->loWINVer=HIBYTE(_ax);
    __asm__("
      movw $0x3000,%%ax\n
      int $0x21\n
      movw %%ax,%0"
      :"=g" (_ax)
      :
      : "memory","ax","bx","cx","dx"
    );
    info->hiOSVer=LOBYTE(_ax);
    info->loOSVer=HIBYTE(_ax);
    info->hiIEVer=0;
    info->loIEVer=0;
    info->is32BIT=FALSE;
    info->System=osDOS;
    return TRUE;
#endif
}
Beispiel #9
0
BOOL CALLBACK CSubAction::EnumExplorerChilds(HWND hWnd,LPARAM lParam)
{
	char szClass[100]="";
	GetClassName(hWnd,szClass,100);

	if (strcmp(szClass,"ComboBoxEx32")!=0)
		return TRUE;

	if (::SendMessageW(hWnd,WM_GETTEXT,MAX_PATH,lParam)==0)
		return TRUE;
	
	if (FileSystem::IsDirectory((LPCWSTR)lParam))
		return FALSE; // Path is OK

	// Check wheter lParam is Desktop
	LPITEMIDLIST idl;
	SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOP,&idl);
	SHFILEINFOW fi;
	if (ShellFunctions::GetFileInfo(idl,0,&fi,SHGFI_DISPLAYNAME))
	{
		if (wcscmp(fi.szDisplayName,(LPCWSTR)lParam)==0)
		{
			((LPWSTR)lParam)[0]=L'2';
			((LPWSTR)lParam)[1]=L'\0';
			CoTaskMemFree(idl);
			return FALSE;
		}
	
		CoTaskMemFree(idl);		
	}

	// Check wheter lParam is My Computer
	SHGetSpecialFolderLocation(NULL,CSIDL_DRIVES,&idl);
	if (ShellFunctions::GetFileInfo(idl,0,&fi,SHGFI_DISPLAYNAME))
	{
		if (wcscmp(fi.szDisplayName,(LPCWSTR)lParam)==0)
		{
			((LPWSTR)lParam)[0]=L'4';
			((LPWSTR)lParam)[1]=L'\0';
			CoTaskMemFree(idl);
			return FALSE;
		}
	
		CoTaskMemFree(idl);		
	}

	// Check wheter lParam is My Documents
	CRegKey RegKey;
	if (RegKey.OpenKey(HKCU,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",CRegKey::openExist|CRegKey::samRead)==ERROR_SUCCESS)
	{
		WCHAR temp[MAX_PATH];
		RegKey.QueryValue(L"Personal",temp,MAX_PATH);
		RegKey.CloseKey();

		if	(FileSystem::IsDirectory(temp))
		{
			if (ShellFunctions::GetFileInfo(temp,0,&fi,SHGFI_DISPLAYNAME))
			{
				if (wcscmp(fi.szDisplayName,(LPCWSTR)lParam)==0)
				{
					((LPWSTR)lParam)[0]=L'3';
					((LPWSTR)lParam)[1]=L'\0';
			
					return FALSE;
				}
			}
		}
	}

	((LPWSTR)lParam)[0]='\0';
	return TRUE;
}
Beispiel #10
-1
BOOL CCpuUsage::EnablePerformaceCounters(BOOL bEnable)
{
	if (m_nPlatform!= WIN2K_XP)
		return TRUE;

	CRegKey regKey;
	if (regKey.OpenKey(HKLM, "SYSTEM\\CurrentControlSet\\Services\\PerfOS\\Performance",CRegKey::defWrite) != ERROR_SUCCESS)
		return FALSE;

	regKey.SetValue("Disable Performance Counters",(DWORD)!bEnable);
	regKey.CloseKey();

	if (regKey.OpenKey(HKLM, "SYSTEM\\CurrentControlSet\\Services\\PerfProc\\Performance",CRegKey::defWrite) != ERROR_SUCCESS)
		return FALSE;

	regKey.SetValue("Disable Performance Counters",(DWORD)!bEnable);
	regKey.CloseKey();

	return TRUE;
}