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

📄 function.cpp

📁 1.MyIE开源工程协议 MyIE开源工程遵循GNU通用公共许可证GPL(GNU General Public License)开发,任何人都可以永久免费安装使用,在你下载和使用MyIE源代码前,请
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	char num[10];
	CString filename = LNG_FILE;
	//
	int i;
	CString str;
	//write information
	DeleteFile(filename);
	_FileWriteBuffer(filename,STR_NOTICE);
	::WritePrivateProfileSection("Information", NULL, filename);
	::WritePrivateProfileString("Information", "Language", "", filename);
	::WritePrivateProfileString("Information", "Translator", "", filename);
	
	//write general string
	_FileAppendBuffer(filename,"\r\n");
	::WritePrivateProfileSection("StringGeneral", NULL, filename);
	::WritePrivateProfileString("StringGeneral", "1", "&OK", filename);
	::WritePrivateProfileString("StringGeneral", "2", "&Cancel", filename);
	
	//string table
	_FileAppendBuffer(filename,"\r\n");
	::WritePrivateProfileSection("StringTable", NULL, filename);
	for (i=105;i<61400;i++)
	{
		if (i>=59136 && i<=59141)
			continue;
		LOADSTR(str ,i);
		if (str.GetLength() && str!=" " && str!="0")
		{
			itoa(i,num,10);
			if (str.Find('\r')>=0)
				str.Replace("\r","\\r");
			if (str.Find('\n')>=0)
				str.Replace("\n","\\n");
			::WritePrivateProfileString("StringTable", num, str, filename);
		}
	}
}

#define IS_NUM(x)			(x>='0' && x<='9')
#define IS_NAME(strText)	\
	(	(strText.Left(4)=="List" && IS_NUM(strText.GetAt(4))) ||	\
		(strText.Left(4)=="Tree" && IS_NUM(strText.GetAt(4))) ||	\
		(strText.Left(4)=="Spin" && IS_NUM(strText.GetAt(4))) ||	\
		(strText.Left(4)=="Slider" && IS_NUM(strText.GetAt(6))) ||	\
		(strText.Left(3)=="Tab" && IS_NUM(strText.GetAt(3)))  )

void _WriteDlgString(CWnd *pDlg, CString strDomain)
{
	char num[10];	
	CString filename = LNG_FILE;
	//
	int id;
	CWnd *pWnd=NULL;
	CString strText;

	_FileAppendBuffer(filename,"\r\n");
	::WritePrivateProfileSection(strDomain, NULL, filename);
	pDlg->GetWindowText(strText);
	if (strText.GetLength())
		::WritePrivateProfileString(strDomain, "Caption", strText, filename);
	//
	pWnd = pDlg->GetNextDlgGroupItem(NULL);
	while(pWnd)
	{
		pWnd->GetWindowText(strText);
		if (strText.GetLength() && strText!="..." && strText!="0" && !IS_NAME(strText))
		{
			id = pWnd->GetDlgCtrlID();
			if (id>10 && id<65535)
			{
				if (strText.Find('\r')>=0)
					strText.Replace("\r","\\r");
				if (strText.Find('\n')>=0)
					strText.Replace("\n","\\n");
				itoa(id,num,10);
				::WritePrivateProfileString(strDomain, num, strText, filename);
			}
		}
		pWnd = pWnd->GetNextWindow();
	}
}

void _WriteDlgComboBox(CWnd *pDlg, CString strDomain)
{
	char num[10];	
	CString filename = LNG_FILE;
	//
	int id;
	CWnd *pWnd=NULL;
	CString strText;

	//::WritePrivateProfileSection(strDomain, NULL, filename);
	//pDlg->GetWindowText(strText);
	//if (strText.GetLength())
	//	::WritePrivateProfileString(strDomain, "Caption", strText, filename);
	//
	pWnd = pDlg->GetNextDlgGroupItem(NULL);
	while(pWnd)
	{
		id = pWnd->GetDlgCtrlID();
		if (id>10 && id<65535)
		{
			CString str;
			strText.Empty();
			CComboBox *pCb = (CComboBox *)pWnd;
			int count = pCb->GetCount();
			if (count)
			{
				for (int i=0; i<count; i++)
				{
					pCb->GetLBText(i,str);
					strText += "\\n";
					strText += str;
				}
				if (strText.GetLength())
				{
					id = pWnd->GetDlgCtrlID();
					itoa(id,num,10);
					::WritePrivateProfileString(strDomain, num, strText, filename);
				}
			}
		}
		pWnd = pWnd->GetNextWindow();
	}
}

void _WriteMenuString(CMenu *pMenu, CString strDomain)
{
	char num[10];
	char buf[MAX_INI];
	CString filename = LNG_FILE;
	//
	CMenu *pSubMenu;
	int value,j,nID;
	UINT i=0,itemCount,state;
	static char aIndex[5];
	static char nIndex=_NULL;
	char key[10]="";
	CString strName;
	
	nIndex++;
	if (nIndex==0)
	{
		_FileAppendBuffer(filename,"\r\n");
		::WritePrivateProfileSection(strDomain, NULL, filename);
	}
	//
	itemCount = pMenu->GetMenuItemCount();
	for(i=0;i<itemCount;i++)
	{
		state=pMenu->GetMenuState(i,MF_BYPOSITION);
		if(state&MF_POPUP)
		{	
			aIndex[nIndex] = i;
			aIndex[nIndex+1] = _NULL;
			j=0;
			key[0]=0;
			while( (value=aIndex[j++]) != _NULL)
			{
				strcat(key,"X");
				itoa(value, num, 10);
				strcat(key,num);
			}
			pMenu->GetMenuString( i, buf, countof(buf)-1, MF_BYPOSITION);
			strName = buf;
			strName.Replace("\t","\\t");
			if (strName.GetLength())
				::WritePrivateProfileString(strDomain, key, strName, filename);

			pSubMenu = pMenu->GetSubMenu(i);
			if (pSubMenu)
				_WriteMenuString(pSubMenu,strDomain);
		}
		else if(state&MF_SEPARATOR)
			;
		else
		{
			nID = pMenu->GetMenuItemID(i);
			itoa(nID,num,10);
			pMenu->GetMenuString( i, buf, countof(buf)-1, MF_BYPOSITION);
			CString strName;
			strName = buf;
			strName.Replace("\t","\\t");
			::WritePrivateProfileString(strDomain, num, strName, filename);
		}
	}
	nIndex--;
	if (nIndex>-1)
		aIndex[nIndex] = _NULL;
}

void _WriteAllMenuString()
{
	CMenu menu;
	//
	menu.LoadMenu(IDR_MAINFRAME);
	_WriteMenuString(&menu, "MenuMain");
	//
	menu.LoadMenu(IDR_DRAG_IMG);
	_WriteMenuString(menu.GetSubMenu(0), "MenuDragImage");
	//
	menu.LoadMenu(IDR_DRAG_LINK);
	_WriteMenuString(menu.GetSubMenu(0), "MenuDragLink");
	//
	menu.LoadMenu(IDR_DRAG_TEXT);
	_WriteMenuString(menu.GetSubMenu(0), "MenuDragText");
	//
	menu.LoadMenu(IDR_RFAV_FOLDER);
	_WriteMenuString(menu.GetSubMenu(0), "MenuFavFolder");
	//
	menu.LoadMenu(IDR_RFAV_URL);
	_WriteMenuString(menu.GetSubMenu(0), "MenuFavUrl");
	//
	menu.LoadMenu(IDR_RTAB);
	_WriteMenuString(menu.GetSubMenu(0), "MenuTab");
	//
	menu.LoadMenu(IDR_TRAYMENU);
	_WriteMenuString(menu.GetSubMenu(0), "MenuTray");
}

#endif //_WRITE_LNG_FILE_

//##############################################################
void _InitLanguageFile(LPCSTR lpFileName)
{
	FREENULL(g_strLngBuf);

	if (!theApp.m_bUseLngFile)
		return;
	g_strLngBuf = _FileGetBuffer(lpFileName);
	if (g_strLngBuf == NULL)
	{
		theApp.m_bUseLngFile = FALSE;
	}
}

DWORD _GetPrivateProfileString(
    LPCSTR lpAppName,
    LPCSTR lpKeyName,
    LPCSTR lpDefault,
    LPSTR lpReturnedString,
    DWORD nSize,
    LPCSTR lpFileName
    )
{
	char strTemp[50];
	char *p1,*p2;
	sprintf(strTemp,"[%s]",lpAppName);
	p1 = strstr(g_strLngBuf,strTemp);
	if (p1)
	{
		p1 += strlen(strTemp);
		p2 = strstr(p1,"]\r");
		sprintf(strTemp,"\r\n%s=",lpKeyName);
		p1 = strstr(p1,strTemp);
		if ( p1 && 
			(!p2 || (p2 && p1<p2))
			)
		{
			p1 += strlen(strTemp);
			p2 = strchr(p1,'\r');
			if (p2)
			{
				int len = min( (DWORD)(p2-p1), nSize);
				STRNCPY(lpReturnedString, p1, len);
				return len;
			}
		}
	}
	if (lpDefault)
	{
		strcpy(lpReturnedString, lpDefault);
		return strlen(lpDefault);
	}
	else
	{
		*lpReturnedString = 0;
		return 0;
	}
}

void _LoadString(CString &str, UINT id)
{
	char num[10];
	char buf[MAX_INI];

	itoa(id,num,10);
	if (_GetPrivateProfileString("StringTable", num, NULL, buf, MAX_INI, theApp.m_strLngFile))
	{
		str = buf;
		if (str.Find("\\r")>=0)
			str.Replace("\\r","\r");
		if (str.Find("\\n")>=0)
			str.Replace("\\n","\n");
	}
	else
		str.LoadString(id);
}

void _LoadDlgString(CWnd *pDlg, CString strDomain)
{
	char num[10];
	char buf[MAX_INI];
	//
	int id;
	CWnd *pWnd=NULL;
	CString strText;
	DWORD r;
	
	if (_GetPrivateProfileString(strDomain, "Caption", NULL, buf, MAX_INI, theApp.m_strLngFile))
		pDlg->SetWindowText(buf);
	//
	pWnd = pDlg->GetNextDlgGroupItem(NULL);
	while(pWnd)
	{
		id = pWnd->GetDlgCtrlID();
		itoa(id,num,10);
		if (id<10)
		{
			if (_GetPrivateProfileString("StringGeneral", num, NULL, buf, MAX_INI, theApp.m_strLngFile))
				pWnd->SetWindowText(buf);
		}
		else
		{
			if (r = _GetPrivateProfileString(strDomain, num, NULL, buf, MAX_INI, theApp.m_strLngFile))
			{
				if (*buf=='\\' && *(buf+1)=='n')//combo box
				{
					char str[MAX_INI];
					char *pos1,*pos2;
					int i=0,len;
					CComboBox *pCb = (CComboBox *)pWnd;
					int nCurSel = pCb->GetCurSel();
					pCb->ResetContent();
					pos1 = buf + 2;
					while (1)
					{
						pos2 = strstr(pos1,"\\n");
						if (!pos2)
							pos2 = buf + r;
						len = pos2 - pos1;
						STRNCPY(str,pos1,len);
						pCb->InsertString(i,str);
						i++;
						pos1 = pos2+2;
						if (pos1>=buf+r)
							break;
					}
					pCb->SetCurSel(nCurSel);
				}
				else if ( strstr(buf,"\\r") || strstr(buf,"\\n"))
				{
					CString str=buf;
					str.Replace("\\r","\r");
					str.Replace("\\n","\n");
					pWnd->SetWindowText(str);
				}
				else
					pWnd->SetWindowText(buf);
			}
		}
		pWnd = pWnd->GetNextWindow();
	}
}

void _GetMenuItemString(CString &strName, int nID)
{
	if (nID==0)
	{
		LOADSTR(strName,IDS_NONE);
		return ;
	}
	CMenu * pMenu = pmf->GetMenu();
	//
	MENUITEMINFO mii; 
	CMenuData* pmd;
	if(pMenu!=NULL)
	{
		mii.fMask = MIIM_DATA|MIIM_TYPE;    // get the state of the menu item
		mii.dwTypeData = NULL;
		mii.cch = 0;
		mii.dwItemData = NULL;
		mii.cbSize = sizeof(mii);
		pMenu->GetMenuItemInfo(nID, &mii, FALSE); 
		pmd = (CMenuData*)(mii.dwItemData);
		if(mii.fType & MFT_OWNERDRAW && pmd!=NULL)
			strName = pmd->m_szMenuText;
		else
			strName = "";
	}
	strName.Remove('&');
	int pos = strName.Find('\t');
	if (pos>=0)
		strName = strName.Left(pos);
}

void _LoadMenuString2ComboBox(CMenu *pMenu, CComboBox *pCb)
{
	char num[10];
	char buf[MAX_INI];
	//
	CMenu *pSubMenu;
	int value,j,nID;
	UINT i=0,itemCount,state;
	char key[10]="";
	CString strName,strPop;
	static int index=0;
	static char aIndex[5];
	static char nIndex=_NULL;
	static CString strIndex[5];
	BOOL r = TRUE;
	BOOL bNeedReadRes = TRUE;
	//
	if (pMenu == pmf->GetMenu())
	{
		CString strItem;
		LOADSTR(strItem,IDS_NONE);
		pCb->InsertString(0,strItem);
		index=1;
	}
	//
	nIndex++;
	//
	itemCount = pMenu->GetMenuItemCount();
	for(i=0;i<itemCount;i++)
	{
		state=pMenu->GetMenuState(i,MF_BYPOSITION);
		if(state&MF_POPUP)
		{
			bNeedReadRes = TRUE;
			aIndex[nIndex] = i;
			aIndex[nIndex+1] = _NULL;
			if (theApp.m_bUseLngFile)
			{	
				j=0;
				key[0]=0;
				while( (value=aIndex[j++]) != _NULL)
				{
					strcat(key,"X");
					itoa(value, num, 10);
					strcat(key,num);
				}
				r = _GetPrivateProfileString("MenuMain", key, NULL, buf, MAX_INI, theApp.m_strLngFile);
				if (r)
					bNeedReadRes = FALSE;
			}
			//read string from res
			if (bNeedReadRes)
				pMenu->GetMenuString( i, buf, countof(buf)-1, MF_BYPOSITION);//::GetMenuString(hSubMenu, i, name, countof(name)-1, MF_BYPOSITION);
			//
			{
				CString strName;
				strName = buf;
				strName.Replace("\\t","\t");
				strName.Remove('&');
				int pos = strName.Find('\t');
				if (pos>=0)
					strName = strName.Left(pos);
				if (strName.GetLength())
					strIndex[nIndex] = strName;
			}
			//
			pSubMenu = pMenu->GetSubMenu(i);
			if (pSubMenu)
				_LoadMenuString2ComboBox(pSubMenu, pCb);
		}
		else if(state&MF_SEPARATOR)
			;
		else
		{
			nID = pMenu->GetMenuItemID(i);
			//undo close
			if (nID>=B_UNDO && nID<=B_UNDO+MAX_UNDO)
				goto _myexit;
			//add url to this fav
			if (nID>=B_ADDTO_FAV && nID<=E_ADDTO_FAV)
				goto _myexit;
			//search
			if (nID>=B_SEARCH && nID<=E_SEARCH)
				goto _myexit;
			//
			CString strPop;
			strPop.Empty();
			j=0;
			while(strIndex[j].GetLength())
			{
				strPop += strIndex[j];
				strPop += " \\ ";
				j++;
			}
			_GetMenuItemString(strName,nID);
			strName = strPop + strName;
			if (strName.GetLength())
			{
				pCb->InsertString(index,strName);
				pCb->SetItemData(index,nID);
				index++;
			}
		}
	}
_myexit:
	nIndex--;
	if (nIndex>-1)
	{
		aIndex[nIndex] = _NULL;
		strIndex[nIndex] = "";
	}
}

void _LoadMenuString(CMenu *pMenu, CString strDomain)
{

⌨️ 快捷键说明

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