www.pudn.com > Process_Mo18292312142004.rar > Settings.cpp


 
/******************************************************* 
 
   This file is part of Process Monitor. 
	 
   Copyright (c) 2004 by Michel van Kerkhof, ( michel000@planet.nl  http://home.wxs.nl/~wijk0550/ )            
   For more information consult the Readme file.        
                                                                                                                                                                    
   This program is free software; you can redistribute it      
   and/or modify it under the terms of the GNU          
   General Public License as published by the Free      
   Software Foundation; either version 2 of the         
   License, or (at your option) any later version.      
                                                        
   This program is distributed in the hope that it will        
   be useful, but WITHOUT ANY WARRANTY; without         
   even the implied warranty of  MERCHANTABILITY        
   or FITNESS FOR A PARTICULAR PURPOSE.  See the        
   GNU General Public License for more details.         
                                                        
   You should have received a copy of the GNU           
   General Public License along with this program;  
   if not, write to: 
   the Free Software Foundation, Inc.,         
   59 Temple Place,                                     
   Suite 330, Boston,                                   
   MA  02111-1307  USA                                  
                                                        
******************************************************* 
 
   If you like my work and you have a job for me please contact me at: michel000@planet.nl 
   
*******************************************************/ 
 
 
 
#include "includes.h" 
 
const char szRegSettingsKey[] = "Software\\Process Monitor"; 
const char szRegSettingsValue[] = "Settings"; 
 
 
/* 
  Save settings to registry 
  Settings are in SETTINGS struct.  
*/ 
 
int CWindow::SaveSettings() 
{ 
	HKEY hKey; 
	long lRet; 
	DWORD dwCreation; 
 
	try { 
		GetWindowRect(hMain,&Settings.WinRect); 
 
		lRet=RegCreateKeyEx( 
			HKEY_CURRENT_USER, 
			szRegSettingsKey, 
			0, 
			NULL, 
			REG_OPTION_NON_VOLATILE, 
			KEY_ALL_ACCESS, 
			NULL, 
			&hKey, 
			&dwCreation 
		); 
 
		if (lRet != ERROR_SUCCESS) throw(0); 
 
		lRet=RegSetValueEx(hKey, 
					szRegSettingsValue, 
					0, 
					REG_BINARY, 
					(LPBYTE)&Settings, 
					sizeof(Settings) 
		); 
 
		RegCloseKey(hKey); 
 
		if (lRet != ERROR_SUCCESS) throw(0); 
 
		throw(1); 
 
	} 
	catch(int iError) 
	{ 
		return iError; 
	} 
 
	return 0; 
} 
 
/* 
	Load settings from registry if its the first time we run load default settings 
*/ 
bool CWindow::LoadSettings() 
{ 
	HKEY hKey; 
	long lRet; 
	DWORD	dwType, 
			dwSize; 
 
	try { 
 
		lRet=RegOpenKeyEx(HKEY_CURRENT_USER,szRegSettingsKey,0,KEY_ALL_ACCESS,&hKey); 
 
		if (lRet != ERROR_SUCCESS) throw(0); //key doesnt exists or we dont have access to it 
 
		dwSize=sizeof(Settings); 
 
		lRet=RegQueryValueEx( 
					hKey, 
					szRegSettingsValue, 
					NULL, 
					&dwType, 
					(LPBYTE)&Settings, 
					&dwSize 
					); 
 
		RegCloseKey(hKey); 
 
		if (lRet != ERROR_SUCCESS) throw(0); 
 
		//check if the data is valid 
 
		if (Settings.SubListViewOption < IDM_SHOW_EXTRA_INFO &&  
			Settings.SubListViewOption > IDM_HANDLES_INFO) throw(0); 
 
		if (Settings.UpdateSpeedOption < IDM_SPEED_500 || Settings.UpdateSpeedOption > IDM_SPEED_5000) throw(0); 
 
		if (Settings.dSplitter < 0.1 || Settings.dSplitter >= 1) throw(0); 
 
		if (Settings.WinRect.left < -10 || Settings.WinRect.right-Settings.WinRect.left < 80) throw(0); 
		if (Settings.WinRect.top < -10 || Settings.WinRect.bottom-Settings.WinRect.top < 60) throw(0); 
		throw(1); 
	} 
	catch(int iError) 
	{ 
 
		if (iError == 0) { 
			RECT dr; 
 
			//get size of working area  
			SystemParametersInfo(SPI_GETWORKAREA,0,&dr,0); 
 
			//could not get settings set to default 
			Settings.SubListViewOption=EXTRA_INFO; 
			Settings.UpdateSpeedOption=IDM_SPEED_1000; 
			Settings.dSplitter=0.6; 
			Settings.WinRect.left=(dr.right-dr.left-DEFAULT_WINSIZE_X) / 2; 
			Settings.WinRect.top=(dr.bottom-dr.top-DEFAULT_WINSIZE_Y) / 2;  
			Settings.WinRect.right=DEFAULT_WINSIZE_X; 
			Settings.WinRect.bottom=DEFAULT_WINSIZE_Y; 
			Settings.bHideWhenMinimized=false; 
		} 
	} 
 
	return 0; 
 
} 
 
 
void CWindow::SetSpeed(int iItem) 
{ 
	HMENU hMenu=GetSubMenu(GetMenu(hMain), 1); 
 
	if (iItem) { 
		SetItemState(hMenu,Settings.UpdateSpeedOption,false); 
 
		Settings.UpdateSpeedOption=iItem; 
		KillTimer(hMain,ID_PROC_TIMER);	 
	} 
 
	SetItemState(hMenu,Settings.UpdateSpeedOption,true); 
 
	switch(Settings.UpdateSpeedOption) 
	{ 
	case IDM_SPEED_500: 
		iUpdateSpeed=500; 
		break; 
	case IDM_SPEED_1000: 
		iUpdateSpeed=1000; 
		break; 
	case IDM_SPEED_2000: 
		iUpdateSpeed=2000; 
		break; 
	case IDM_SPEED_5000: 
		iUpdateSpeed=5000; 
		break; 
	} 
	SetTimer(hMain,ID_PROC_TIMER,iUpdateSpeed,NULL);		 
}