⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwnd.cpp

📁 Smartphone手机阅读软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		}

		if (m_BookListNo == 0)
			ShowBookList();

		if ((m_BookListNo != 0) && (m_ListCtrl.GetItemCount() > ItemNo))
			m_ListCtrl.SelectItem(ItemNo);

		//set last pos
		int Last = CloseWnd->m_LastPagePos;
		if ( Last != -1)
			SetLastPos(BookPath, Last, TRUE);

		else
			SetLastPos(BookPath, 0, TRUE);
	}
	else
	{
		m_BookWnd.m_FullScreenFlag = FALSE;
		m_BookWnd.m_bFormat = m_FullBookWnd.m_bFormat;
		m_BookWnd.m_BookMark = m_FullBookWnd.m_BookMark;
		m_BookWnd.m_BookPath = m_FullBookWnd.m_BookPath;
		m_BookWnd.m_FavorFlag = m_FullBookWnd.m_FavorFlag;
		m_BookWnd.m_LastPagePos = m_FullBookWnd.m_ShowBuf.m_nStartLine;
		m_BookWnd.m_MainWnd = m_hWnd;
		for (int i = 0 ; i < 7 ; i ++)
			m_BookWnd.m_Setting[i] = m_FullBookWnd.m_Setting[i];

		if (m_BookListNo == 3)
		{
			if (m_BookWnd.m_FavorFlag)
				m_BookWnd.EnableDelFavorite(MF_GRAYED,MF_ENABLED);
			else
				m_BookWnd.EnableDelFavorite(MF_GRAYED,MF_GRAYED);
		}
		else
		{
			if (m_BookWnd.m_FavorFlag)
			{
				m_BookWnd.EnableDelFavorite(MF_GRAYED,MF_GRAYED);
			}
			else
			{
				m_BookWnd.EnableDelFavorite(MF_ENABLED,MF_GRAYED);
			}
		}		
		m_BookWnd.ShowBook();						
	}
	if (m_FocusFlag)
	{
		::SetFocus(m_ListCtrl);
		m_FocusFlag = FALSE;
	}
	
	if (m_BookList[m_BookListNo].GetCount() == 0)
	{
		EnableMenuItem(m_hMenu,IDM_DELFROM,MF_GRAYED);
		EnableMenuItem(m_hMenu,IDM_ADDTO,MF_GRAYED);
	}

	return 0;
}

CString CMainWnd::GetSpecStr(CString TotalStr,LPCTSTR FindStr,BOOL RightFlag)
{
	int Pos = 0, LastPos = 0;
	CString LastStr;
	LastStr.Empty();
	
	while (1)
	{
		Pos = TotalStr.Find(FindStr,LastPos + 1);
		if (Pos == -1)
			break;
		LastPos = Pos;
	} 
	if (RightFlag)
		LastStr = TotalStr.Mid(LastPos + 1);
	else
		LastStr = TotalStr.Left(LastPos);
	return LastStr;
}

BOOL CMainWnd::DelFromRegistry(int ListNo)
{
    HKEY hKey; 	
	CString SubKeys,BookKeys;
	SubKeys = SUBKEY;
	if (ListNo == 0)
		SubKeys += RECENTBOOKKEY;
	else
		SubKeys += FAVORITEBOOKKEY;

	int ListLength = 0;
	DWORD cbData;
	if(ERROR_SUCCESS == RegOpenKeyEx(ROOTKEY, SUBKEY, 0, 0, &hKey))
	{   
		if (ListNo == 0)
		{
			if(ERROR_SUCCESS != RegQueryValueEx(hKey,RECENTBOOKKEY, NULL, NULL, (LPBYTE)&ListLength, &cbData))
			{
				RegCloseKey(hKey);
				return FALSE;
			}
			else
				RegDeleteValue(hKey, RECENTBOOKKEY);
		}
		else
		{
			if(ERROR_SUCCESS != RegQueryValueEx(hKey,FAVORITEBOOKKEY, NULL, NULL, (LPBYTE)&ListLength, &cbData))
			{
				RegCloseKey(hKey);
				return FALSE;
			}
			else
				RegDeleteValue(hKey, FAVORITEBOOKKEY);
		}
	}
	else
		return FALSE;
	RegCloseKey(hKey);

	CString GetPath;
	GetPath = L"";

	for (int i = 0; i < ListLength ; i++)
	{
		BookKeys.Format(_T("%s%d"),SubKeys,i);
		if(ERROR_SUCCESS == RegOpenKeyEx(ROOTKEY, BookKeys, 0, 0, &hKey))
		{			
			RegCloseKey(hKey);
			RegDeleteKey(ROOTKEY,BookKeys);			
		}
	}
	return TRUE;
}

int CMainWnd::GetLastPos(LPCTSTR BookPath, int& KeyNo) 
{
	HKEY hKey;
	CString SubKey , BookKey;
	SubKey = SUBKEY;
	SubKey += LASTPOSKEY;
	int i = 0;
	DWORD cbData = 0;
	int LastPos = 0;
	CString GetPath;
	TCHAR Buf[255];
	BOOL FindFlag = FALSE;
	while (1)
	{
		GetPath = L"";
		BookKey.Format(_T("%s%d"),SubKey,i);
		if (RegOpenKeyEx(ROOTKEY,BookKey,0,0,&hKey) == ERROR_SUCCESS)
		{
			cbData = 255 * sizeof(TCHAR);
			memset(Buf, 0 , sizeof(Buf));
			if (RegQueryValueEx(hKey,_T("BookPath"),0,NULL,(LPBYTE)Buf,&cbData) == ERROR_SUCCESS)
			{
				GetPath = Buf;
				if (GetPath.Find(BookPath) != -1)
				{
					cbData = sizeof(int);
					if (RegQueryValueEx(hKey,_T("LastPos"),0,NULL,(LPBYTE)&LastPos,&cbData) == ERROR_SUCCESS)
					{
						FindFlag = TRUE;
						KeyNo = i;
						RegCloseKey(hKey);
						break;
					}
					else
					{
						RegCloseKey(hKey);
						break;
					}
				}
			}
			RegCloseKey(hKey);
		}
		else
		{
			break;
		}
		i++;
	}

	if (!FindFlag)
		return -1;
	else
		return LastPos;
}

BOOL CMainWnd::SetLastPos(LPCTSTR BookPath, int Pos, BOOL SetFlag)
{
	HKEY hKey;
	int i = 0;
	DWORD cbData = 0;
	DWORD dwDisposition;
	CString SubKey,BookKey;
	SubKey = SUBKEY;
	SubKey += LASTPOSKEY;
	int KeyNo = 0;
	int GetPos = GetLastPos(BookPath, KeyNo);
	if (( GetPos == -1) && (SetFlag))
	{
		while (1)
		{
			BookKey.Format(_T("%s%d"),SubKey,i);
			if (RegOpenKeyEx(ROOTKEY, BookKey, 0, 0 ,&hKey) == ERROR_SUCCESS)
				RegCloseKey(hKey);
			else
			{
				if (RegCreateKeyEx(ROOTKEY,BookKey,0,NULL,0,0,NULL,&hKey,&dwDisposition) == ERROR_SUCCESS)
				{
					cbData = wcslen(BookPath) * sizeof(WCHAR) + 1;
					if (RegSetValueEx(hKey, _T("BookPath"), 0 ,REG_SZ,(const BYTE *)BookPath,cbData) != ERROR_SUCCESS)
					{
						RegCloseKey(hKey);
						return FALSE;
					}
					cbData = sizeof(int);
					if (RegSetValueEx(hKey, _T("LastPos"), 0 ,REG_DWORD,(const BYTE *)&Pos,cbData) != ERROR_SUCCESS)
					{
						RegCloseKey(hKey);
						return FALSE;
					}
					RegCloseKey(hKey);
					return TRUE;
				}
				else
					return FALSE;
			}
			i++;
		}
	}
	else
	{		
		BookKey.Format(_T("%s%d"),SubKey,KeyNo);
		if (RegOpenKeyEx(ROOTKEY, BookKey, 0, 0 ,&hKey) == ERROR_SUCCESS)
		{
			if (!SetFlag)
			{
				RegCloseKey(hKey);
				if (RegDeleteKey(ROOTKEY,BookKey) != ERROR_SUCCESS)
				{
					cbData = sizeof(int);
					if (RegSetValueEx(hKey, _T("LastPos"), 0 ,REG_DWORD,(LPBYTE)&Pos,cbData) != ERROR_SUCCESS)
					{
						RegCloseKey(hKey);
						return FALSE;
					}
				}
				return TRUE;
			}
			cbData = sizeof(int);
			if (RegSetValueEx(hKey, _T("LastPos"), 0 ,REG_DWORD,(LPBYTE)&Pos,cbData) != ERROR_SUCCESS)
			{
				RegCloseKey(hKey);
				return FALSE;
			}
			
			RegCloseKey(hKey);
			return TRUE;
		}
	}
	
	return TRUE;

}
LRESULT CMainWnd::OnFullScreen(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CRect rc(0,0,176,220);
	m_FullBookWnd.m_FullScreenFlag = TRUE;
	if (!m_FullBookWnd.IsWindow())
	{
		//create window
		m_FullBookWnd.Create(NULL,rc,L" ",WS_VISIBLE);	
	}
	else
	{
		m_FullBookWnd.SetWindowText(L" ");
		m_FullBookWnd.ShowWindow(SW_SHOW);
	}
	
	m_FullBookWnd.MoveMenuBar(FALSE);

	m_FullBookWnd.m_bFormat = m_BookWnd.m_bFormat;
	m_FullBookWnd.m_BookMark = m_BookWnd.m_BookMark;
	m_FullBookWnd.m_BookPath = m_BookWnd.m_BookPath;
	m_FullBookWnd.m_FavorFlag = m_BookWnd.m_FavorFlag;
	m_FullBookWnd.m_LastPagePos = m_BookWnd.m_ShowBuf.m_nStartLine;
	m_FullBookWnd.m_MainWnd = m_hWnd;
	for (int i = 0 ; i < 7 ; i ++)
		m_FullBookWnd.m_Setting[i] = m_BookWnd.m_Setting[i];


	if (m_BookListNo == 3)
	{
		if (m_FullBookWnd.m_FavorFlag)
			m_FullBookWnd.EnableDelFavorite(MF_GRAYED,MF_ENABLED);
		else
			m_FullBookWnd.EnableDelFavorite(MF_GRAYED,MF_GRAYED);
	}
	else
	{
		if (m_FullBookWnd.m_FavorFlag)
		{
			m_FullBookWnd.EnableDelFavorite(MF_GRAYED,MF_GRAYED);
		}
		else
		{
			m_FullBookWnd.EnableDelFavorite(MF_ENABLED,MF_GRAYED);
		}
	}

	m_FullBookWnd.ShowBook();	
	return 0;
}

void CMainWnd::GetSettings()
{
	HKEY hKey;
	DWORD cbData = 0;
	CString SubKey,BookKey;
	SubKey = SUBKEY;
	SubKey += SETTINGKEY;
	if (RegOpenKeyEx(ROOTKEY, SubKey, 0, 0 ,&hKey) != ERROR_SUCCESS)
		return;
	int Setting = 0;
	int SettingNum[7];
	SettingNum[0] = 1;
	SettingNum[1] = 3;
	SettingNum[2] = 4;
	SettingNum[3] = 16;
	SettingNum[4] = 16;
	SettingNum[5] = 3;	
	SettingNum[6] = 2;

	for (int i = 0; i < 7 ; i++)
	{
		BookKey.Format(_T("%s%d"),SETTINGKEY,i);		
		cbData = sizeof(int);
		if (RegQueryValueEx(hKey, BookKey , NULL ,NULL,(LPBYTE)&Setting,&cbData) != ERROR_SUCCESS)
		{
			RegCloseKey(hKey);
			return ;
		}
		if ((Setting >= 0 ) && (Setting < SettingNum[i]))
			m_Setting[i] = Setting;
	}
	RegCloseKey(hKey);	
}

void CMainWnd::InputSettings()
{
	HKEY hKey;
	int cbData = 0;
	DWORD dwDisposition;
	CString SubKey,BookKey;
	SubKey = SUBKEY;
	SubKey += SETTINGKEY;
	if (RegOpenKeyEx(ROOTKEY, SubKey, 0, 0 ,&hKey) != ERROR_SUCCESS)
	{
		if (RegCreateKeyEx(ROOTKEY,SubKey,0,NULL,0,0,NULL,&hKey,&dwDisposition) != ERROR_SUCCESS)
			return;
	}
	for (int i = 0; i < 7 ; i++)
	{
		BookKey.Format(_T("%s%d"),SETTINGKEY,i);		
		cbData = sizeof(int);
		int Setting = m_Setting[i];
		if (RegSetValueEx(hKey, BookKey , 0 ,REG_DWORD,(LPBYTE)&Setting,cbData) != ERROR_SUCCESS)
		{
			RegCloseKey(hKey);
			return ;
		}
	}
	RegCloseKey(hKey);
}
LRESULT CMainWnd::OnActivatePreInstance(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	m_FocusFlag = TRUE;
	const DWORD dwThreadid = ::GetWindowThreadProcessId( m_hWnd , NULL ) ;	
	HWND  hWndFind =  GetDesktopWindow();
	TCHAR szClsName[256],szWinTitle[256];
	CString sAppName;
	sAppName.LoadString(IDS_APPNAME);
	BOOL MsgFlag = FALSE;

	//先关闭所有的MessageBox
	while((hWndFind = ::GetWindow(hWndFind, GW_HWNDNEXT)) != NULL)
	{		
		if(::GetWindowThreadProcessId(hWndFind,NULL) == dwThreadid &&
			hWndFind != g_hWndLast && 
			hWndFind != m_hWnd) 
		{
			::GetClassName(hWndFind,szClsName,256);
			::GetWindowText(hWndFind,szWinTitle,256);
			if(_tcscmp(szClsName,_T("Dialog")) == 0 && 
				_tcscmp(szWinTitle,sAppName) == 0)
			{
				//::PostMessage(hWndFind,WM_QUIT,IDCANCEL,0);
				::SetForegroundWindow(hWndFind);
				::UpdateWindow(hWndFind);
				MsgFlag = TRUE;
				break;
			}
		}
	}
	if (!MsgFlag)
	{
		//如果程序有其他对话框,激活
		if(g_hWndLast)
		{   
			::SetForegroundWindow(g_hWndLast);		
		}
		else//否则激活程序的主窗体
		{
			::SetForegroundWindow(m_hWnd);
		}	
	}
	return 0;
}

BOOL CMainWnd::FindStorage()
{
	// Search handle for storage cards.
	HANDLE hFlashCard;  
	// Structure for storing storage
	WIN32_FIND_DATA *lpwfdFlashCardTmp; 
    // card information temporarily.
	lpwfdFlashCardTmp = (WIN32_FIND_DATA *) LocalAlloc (LPTR, 10 * sizeof (WIN32_FIND_DATA));
	// Failed allocate memory return;
	if (lpwfdFlashCardTmp == NULL)      
		return FALSE;
	
	//init the string array
	for(int j = 0; j < 2 ;j++)
		m_Storage[j].Empty();
	//Find all flash card and add their name to string array
	hFlashCard = FindFirstFlashCard(&lpwfdFlashCardTmp [0]);
	
	if(hFlashCard == INVALID_HANDLE_VALUE)
		return FALSE;		
	int i = 0;
	CString CheckStr(lpwfdFlashCardTmp->cFileName);
	if ((CheckStr.Find(L"SD") != -1) || (CheckStr.Find(L"MMC") != -1))
		m_Storage[i++] = CString(L"\\") + lpwfdFlashCardTmp->cFileName;
	
	while(FindNextFlashCard(hFlashCard,&lpwfdFlashCardTmp[0]))
	{
		CheckStr.Format(lpwfdFlashCardTmp->cFileName);
		if ((CheckStr.Find(L"SD") != -1) || (CheckStr.Find(L"MMC") != -1))
			m_Storage[i++] = CString(L"\\") +lpwfdFlashCardTmp->cFileName;
	}	
	return TRUE;
}

BOOL CMainWnd::IfFavorites(LPCTSTR BookPath)
{
	CString FavorStr;
	FavorStr = L"";
	POSITION FavorPos;
	for (int t = 0 ; t < m_BookList[3].GetCount() ; t++)
	{
		FavorPos = m_BookList[3].FindIndex(t);
		FavorStr = m_BookList[3].GetAt(FavorPos).BookPath;
		if (FavorStr.Find(BookPath) != -1)
			return TRUE;
	}	
	return FALSE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -