001
26.12.2002, 20:08 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo Flo, hmm... Könnte über die Registry laufen ?gruebel?
C++: |
void CTestDlg::OnButton1() { LOGFONT lf; CString FontFileName; lstrcpy(lf.lfFaceName, _T("Courier New")); FontFileName = GetFontFileName(lf); TRACE("%s\n",FontFileName); }
CString GetFontFileName(LOGFONT lplf) { CString FontFace = ""; CString LogFace = lplf.lfFaceName; CString FileName = "";
//OPEN REGISTRY KEYS HKEY hKey = NULL; LONG lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ, &hKey); if (lRes == ERROR_SUCCESS){ lRes = RegOpenKeyEx(hKey, "Microsoft", 0, KEY_READ, &hKey); if (lRes == ERROR_SUCCESS){ lRes = RegOpenKeyEx(hKey, "Windows NT" /*Win9x "Windows"*/, 0, KEY_READ, &hKey); if (lRes == ERROR_SUCCESS){ lRes = RegOpenKeyEx(hKey, "CurrentVersion", 0, KEY_READ, &hKey); if (lRes == ERROR_SUCCESS){ lRes = RegOpenKeyEx(hKey, "Fonts", 0, KEY_READ, &hKey); if (lRes == ERROR_SUCCESS){ char cName[256]; DWORD index = 0; DWORD cbName = 256; DWORD type; unsigned char cData[256]; DWORD cbData = 256; while(RegEnumValue(hKey, index, cName, &cbName, NULL, &type, cData, &cbData) == ERROR_SUCCESS){ index++; cbName = 256; cbData = 256; FontFace = CalculateFontNameFromRegValue(cName); CString message; if(FontFace== LogFace){ FileName = cData; return FileName; } } index = 0; cbName = 256; cbData = 256; while(RegEnumValue(hKey, index, (char*)LPCTSTR(cName), &cbName, NULL, &type, cData, &cbData) == ERROR_SUCCESS){ index++; cbName = 256; cbData = 256; FontFace = CalculateFontNameFromRegValue(cName); CString message; if(FontFace.Left(LogFace.GetLength()) == LogFace){ FileName = cData; return FileName; } } } } } } } FileName = ""; return FileName; }
CString CalculateFontNameFromRegValue(CString regname) { CString newname; int loc = regname.Find('(', 0); if(loc!=-1){ newname = regname.Left(loc); newname.TrimRight(); } return newname; }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 26.12.2002 um 20:40 Uhr von Uwe editiert. |