Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1545 lines
41 KiB

  1. /**************************************************/
  2. /* */
  3. /* */
  4. /* Registry Process */
  5. /* (Dialog) */
  6. /* */
  7. /* */
  8. /* Copyright (c) 1997-1999 Microsoft Corporation. */
  9. /**************************************************/
  10. #include "stdafx.h"
  11. #include "eudcedit.h"
  12. #include "assocdlg.h"
  13. #include "registry.h"
  14. #include "ttfstruc.h"
  15. #include "extfunc.h"
  16. #include "util.h"
  17. #include "gagedlg.h"
  18. #define STRSAFE_LIB
  19. #include <strsafe.h>
  20. #define LSPACE 2
  21. #define RSPACE 2
  22. #define LCSPACE 17
  23. #define NUMITEM 3
  24. #define DBCSCHK 0
  25. #define EUDCCHK 1
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30. SELECTEUDC SelectEUDC;
  31. static HDC hDC;
  32. static HWND hWnd;
  33. static HICON tIcon;
  34. static HGLOBAL hMem;
  35. static int nTypeFace, nIdx, CheckFlg;
  36. static TCHAR FontName[LF_FACESIZE];
  37. static LPASSOCIATIONREG lpAssociationReg;
  38. static int CheckTTF( LOGFONT);
  39. static BOOL CheckCharSet( int CharSet);
  40. static BOOL IsEUDCTTF( TCHAR *ttffile);
  41. static BOOL CheckFileName( LPTSTR FileStr);
  42. static int CALLBACK EnumFontFamProc(
  43. ENUMLOGFONT FAR*, NEWTEXTMETRIC FAR*, int, LPARAM);
  44. static int CALLBACK EnumFontNumber(
  45. ENUMLOGFONT FAR*, NEWTEXTMETRIC FAR*, int, LPARAM);
  46. extern BOOL SetCountryInfo( UINT LocalCP);
  47. /****************************************/
  48. /* */
  49. /* Constructor */
  50. /* */
  51. /****************************************/
  52. CAssocDlg::CAssocDlg(
  53. CWnd* pParent) : CDialog(CAssocDlg::IDD, pParent)
  54. {
  55. m_pParent = pParent;
  56. //{{AFX_DATA_INIT(CAssocDlg)
  57. //}}AFX_DATA_INIT
  58. }
  59. /****************************************/
  60. /* */
  61. /* MESSAGE "WM_INITDIALOG" */
  62. /* */
  63. /****************************************/
  64. BOOL
  65. CAssocDlg::OnInitDialog()
  66. {
  67. CString DlgTtl;
  68. long WindowStyle;
  69. CDialog::OnInitDialog();
  70. WindowStyle = GetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE);
  71. WindowStyle |= WS_EX_CONTEXTHELP;
  72. SetWindowLong( this->GetSafeHwnd(), GWL_EXSTYLE, WindowStyle);
  73. DlgTtl.LoadString( IDS_ASSOCIATE_DLGTITLE);
  74. this->SetWindowText( DlgTtl);
  75. // Set Dialog subclass
  76. m_RegListBox.SubclassDlgItem( IDC_REGISTLIST, this);
  77. m_RegListBox.EnableScrollBar( SB_VERT, ESB_DISABLE_BOTH);
  78. CheckFlg = EUDCCHK;
  79. this->SendDlgItemMessage( IDC_RADIO_SYSTEM, BM_SETCHECK, (WPARAM)1, 0);
  80. hMem = NULL;
  81. if( !SetAssociationFontType()){
  82. this->MessageBox( NotMemMsg, NotMemTtl, MB_OK |
  83. MB_ICONHAND | MB_SYSTEMMODAL);
  84. return FALSE;
  85. }
  86. tIcon = AfxGetApp()->LoadIcon( IDI_TRUETYPE);
  87. return TRUE;
  88. }
  89. /****************************************/
  90. /* */
  91. /* Set TTF and WIFE font */
  92. /* */
  93. /****************************************/
  94. BOOL
  95. CAssocDlg::SetAssociationFontType()
  96. {
  97. LPASSOCIATIONREG lpAssociationRegTmp;
  98. int aFontCount[] = {0,0,0};
  99. int StartIdx = 0;
  100. int sts;
  101. nTypeFace = nIdx = 0;
  102. hWnd = this->GetSafeHwnd();
  103. hDC = ::GetDC( hWnd);
  104. sts = EnumFontFamilies( hDC, NULL,
  105. (FONTENUMPROC)EnumFontNumber, (LPARAM)aFontCount);
  106. if( hMem != NULL){
  107. GlobalUnlock( hMem);
  108. GlobalFree( hMem);
  109. }
  110. hMem = GlobalAlloc(GHND, sizeof(ASSOCIATIONREG) * nTypeFace);
  111. if( hMem == NULL){
  112. ::ReleaseDC( hWnd, hDC);
  113. return FALSE;
  114. }
  115. lpAssociationReg = (LPASSOCIATIONREG)GlobalLock( hMem);
  116. lpAssociationRegTmp = lpAssociationReg;
  117. sts = EnumFontFamilies( hDC, NULL,
  118. (FONTENUMPROC)EnumFontFamProc, (LPARAM)aFontCount);
  119. ::ReleaseDC( hWnd, hDC);
  120. lpAssociationRegTmp = lpAssociationReg;
  121. for( int i = 0; i < nTypeFace; i++){
  122. sts = m_RegListBox.AddString(
  123. (LPCTSTR)lpAssociationRegTmp->szFaceName);
  124. m_RegListBox.SetItemData(sts, i);
  125. if( sts == LB_ERR || sts == LB_ERRSPACE){
  126. GlobalUnlock( hMem);
  127. GlobalFree( hMem);
  128. return FALSE;
  129. }
  130. if( !lstrcmp(lpAssociationRegTmp->szFaceName, SelectEUDC.m_Font)){
  131. StartIdx = i;
  132. }
  133. lpAssociationRegTmp++;
  134. }
  135. m_RegListBox.SetCurSel( StartIdx);
  136. return TRUE;
  137. }
  138. /****************************************/
  139. /* */
  140. /* Callback */
  141. /* */
  142. /****************************************/
  143. static int
  144. CALLBACK EnumFontNumber(
  145. ENUMLOGFONT FAR *lplf,
  146. NEWTEXTMETRIC FAR* lptm,
  147. int FontType,
  148. LPARAM lParam)
  149. {
  150. int sts;
  151. if (!lplf)
  152. {
  153. return 0;
  154. }
  155. if( FontType == TRUETYPE_FONTTYPE){
  156. sts = CheckTTF( lplf->elfLogFont);
  157. if( sts == 1 && CheckCharSet( lplf->elfLogFont.lfCharSet)){
  158. nTypeFace++;
  159. }else if( sts == -1){
  160. return 0;
  161. }else ;
  162. }else if( FontType == 0x8 && lplf->elfLogFont.lfFaceName[0] != '@' &&
  163. CheckCharSet( lplf->elfLogFont.lfCharSet)){
  164. nTypeFace++;
  165. }
  166. return 1;
  167. }
  168. /****************************************/
  169. /* */
  170. /* Callback */
  171. /* */
  172. /****************************************/
  173. static int
  174. CALLBACK EnumFontFamProc(
  175. ENUMLOGFONT FAR *lplf,
  176. NEWTEXTMETRIC FAR* lptm,
  177. int FontType,
  178. LPARAM lParam)
  179. {
  180. LPASSOCIATIONREG lpAssociationRegTmp;
  181. TCHAR FileTitle[MAX_PATH];
  182. TCHAR *FilePtr;
  183. int sts;
  184. TCHAR FileSbstName[LF_FACESIZE];
  185. HRESULT hresult;
  186. if (!lplf)
  187. {
  188. return 0;
  189. }
  190. if( FontType == TRUETYPE_FONTTYPE){
  191. sts = CheckTTF( lplf->elfLogFont);
  192. if( sts == 1 && CheckCharSet( lplf->elfLogFont.lfCharSet)){
  193. FindFontSubstitute(lplf->elfLogFont.lfFaceName, FileSbstName,ARRAYLEN(FileSbstName));
  194. lpAssociationRegTmp = lpAssociationReg + nIdx;
  195. //*STRSAFE* lstrcpy((TCHAR *)lpAssociationRegTmp->szFaceName,FileSbstName);
  196. hresult = StringCchCopy((TCHAR *)lpAssociationRegTmp->szFaceName , ARRAYLEN(lpAssociationRegTmp->szFaceName), FileSbstName);
  197. if (!SUCCEEDED(hresult))
  198. {
  199. return 0;
  200. }
  201. if(!InqTypeFace(lpAssociationRegTmp->szFaceName,
  202. lpAssociationRegTmp->szFileName,
  203. sizeof( lpAssociationRegTmp->szFileName)/sizeof(TCHAR))){
  204. GetStringRes(
  205. (TCHAR *)lpAssociationRegTmp->szFileName,
  206. IDS_NOTSELECT_STR, ARRAYLEN(lpAssociationRegTmp->szFileName));
  207. //*STRSAFE* lstrcpy( lpAssociationRegTmp->szFileTitle,lpAssociationRegTmp->szFileName);
  208. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), lpAssociationRegTmp->szFileName);
  209. if (!SUCCEEDED(hresult))
  210. {
  211. return 0;
  212. }
  213. }else{
  214. //*STRSAFE* lstrcpy(FileTitle,lpAssociationRegTmp->szFileName);
  215. hresult = StringCchCopy(FileTitle , ARRAYLEN(FileTitle), lpAssociationRegTmp->szFileName);
  216. if (!SUCCEEDED(hresult))
  217. {
  218. return 0;
  219. }
  220. if(( FilePtr=Mytcsrchr( FileTitle, '\\')) != NULL)
  221. FilePtr++;
  222. else{
  223. FilePtr = Mytcsrchr( FileTitle,':');
  224. if( FilePtr != NULL){
  225. FilePtr++;
  226. }else FilePtr = FileTitle;
  227. }
  228. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileTitle, FilePtr);
  229. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), FilePtr);
  230. if (!SUCCEEDED(hresult))
  231. {
  232. return 0;
  233. }
  234. }
  235. lpAssociationRegTmp->FontTypeFlg = TRUE;
  236. lpAssociationRegTmp->UpdateFlg = FALSE;
  237. nIdx++;
  238. }else if( sts == -1){
  239. return 0;
  240. }else ;
  241. }else if( FontType == 0x8 && lplf->elfLogFont.lfFaceName[0] != '@' &&
  242. CheckCharSet( lplf->elfLogFont.lfCharSet)){
  243. FindFontSubstitute(lplf->elfLogFont.lfFaceName, FileSbstName,ARRAYLEN(FileSbstName));
  244. lpAssociationRegTmp = lpAssociationReg + nIdx;
  245. //*STRSAFE* lstrcpy((TCHAR *)lpAssociationRegTmp->szFaceName, FileSbstName);
  246. hresult = StringCchCopy((TCHAR *)lpAssociationRegTmp->szFaceName , ARRAYLEN(lpAssociationRegTmp->szFaceName), FileSbstName);
  247. if (!SUCCEEDED(hresult))
  248. {
  249. return 0;
  250. }
  251. if( !InqTypeFace(lpAssociationRegTmp->szFaceName,
  252. lpAssociationRegTmp->szFileName,
  253. sizeof(lpAssociationRegTmp->szFileName)/sizeof(TCHAR))){
  254. GetStringRes((TCHAR *)lpAssociationRegTmp->szFileName,
  255. IDS_NOTSELECT_STR, ARRAYLEN(lpAssociationRegTmp->szFileName));
  256. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileTitle, lpAssociationRegTmp->szFileName);
  257. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), lpAssociationRegTmp->szFileName);
  258. if (!SUCCEEDED(hresult))
  259. {
  260. return 0;
  261. }
  262. }else{
  263. //*STRSAFE* lstrcpy(FileTitle, lpAssociationRegTmp->szFileName);
  264. hresult = StringCchCopy(FileTitle , ARRAYLEN(FileTitle), lpAssociationRegTmp->szFileName);
  265. if (!SUCCEEDED(hresult))
  266. {
  267. return 0;
  268. }
  269. if(( FilePtr=Mytcsrchr( FileTitle, '\\')) != NULL)
  270. FilePtr++;
  271. else{
  272. FilePtr = Mytcsrchr( FileTitle,':');
  273. if( FilePtr != NULL){
  274. FilePtr++;
  275. }else FilePtr = FileTitle;
  276. }
  277. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileTitle, FilePtr);
  278. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), FilePtr);
  279. if (!SUCCEEDED(hresult))
  280. {
  281. return 0;
  282. }
  283. }
  284. lpAssociationRegTmp->FontTypeFlg = FALSE;
  285. lpAssociationRegTmp->UpdateFlg = FALSE;
  286. nIdx++;
  287. }
  288. return 1;
  289. }
  290. /****************************************/
  291. /* */
  292. /* Check Character Set */
  293. /* */
  294. /****************************************/
  295. static BOOL
  296. CheckCharSet(
  297. int CharSet)
  298. {
  299. if( CountryInfo.CharacterSet != CharSet)
  300. return FALSE;
  301. else return TRUE;
  302. }
  303. /****************************************/
  304. /* */
  305. /* COMMAND "IDOK" */
  306. /* */
  307. /****************************************/
  308. void
  309. CAssocDlg::OnOK()
  310. {
  311. LPASSOCIATIONREG lpAssociationRegTmp;
  312. TCHAR FileList[MAX_PATH];
  313. TCHAR TTFPath[MAX_PATH];
  314. TCHAR BMPPath[MAX_PATH];
  315. TCHAR *FilePtr;
  316. HRESULT hresult;
  317. int nIndex = m_RegListBox.GetCurSel();
  318. if( nIndex == -1){
  319. OutputMessageBox( this->GetSafeHwnd(),
  320. IDS_ASSOCIATE_DLGTITLE,
  321. IDS_NOTSELTYPEFACE_MSG, TRUE);
  322. m_RegListBox.SetFocus();
  323. return;
  324. }
  325. // It delays 1 second to call EnabelEUDC(FALSE).
  326. DWORD dwStart = GetTickCount();
  327. // Stop if this has taken too long
  328. while (1)
  329. {
  330. if( GetTickCount() - dwStart >= 1000 )
  331. break;
  332. }
  333. EnableEUDC( FALSE);
  334. lpAssociationRegTmp = lpAssociationReg;
  335. GetStringRes( FileList, IDS_NOTSELECT_STR, ARRAYLEN(FileList));
  336. nIndex = (int)m_RegListBox.GetItemData(nIndex);
  337. for( int i = 0; i < nTypeFace; i++)
  338. {
  339. if( i == nIndex)
  340. {
  341. //
  342. // Treat as an error, if the eudc font file name is not
  343. // specified, yet.
  344. //
  345. if( !lstrcmp((LPCTSTR)lpAssociationRegTmp->szFileName,FileList) &&
  346. (CheckFlg == DBCSCHK))
  347. {
  348. this->SendMessage(WM_COMMAND, IDC_MODIFY, NULL);
  349. if( !lstrcmp((LPCTSTR)lpAssociationRegTmp->szFileName,FileList))
  350. {
  351. m_RegListBox.SetFocus();
  352. EnableEUDC(TRUE);
  353. return;
  354. }
  355. }
  356. //*STRSAFE* lstrcpy(SelectEUDC.m_Font, lpAssociationRegTmp->szFaceName);
  357. hresult = StringCchCopy(SelectEUDC.m_Font , ARRAYLEN(SelectEUDC.m_Font), lpAssociationRegTmp->szFaceName);
  358. if (!SUCCEEDED(hresult))
  359. {
  360. EnableEUDC(TRUE);
  361. return ;
  362. }
  363. //*STRSAFE* lstrcpy(SelectEUDC.m_File, lpAssociationRegTmp->szFileName);
  364. hresult = StringCchCopy(SelectEUDC.m_File , ARRAYLEN(SelectEUDC.m_File), lpAssociationRegTmp->szFileName);
  365. if (!SUCCEEDED(hresult))
  366. {
  367. EnableEUDC(TRUE);
  368. return ;
  369. }
  370. //*STRSAFE* lstrcpy(SelectEUDC.m_FileTitle, lpAssociationRegTmp->szFileTitle);
  371. hresult = StringCchCopy(SelectEUDC.m_FileTitle , ARRAYLEN(SelectEUDC.m_FileTitle), lpAssociationRegTmp->szFileTitle);
  372. if (!SUCCEEDED(hresult))
  373. {
  374. EnableEUDC(TRUE);
  375. return ;
  376. }
  377. SelectEUDC.m_FontTypeFlg = lpAssociationRegTmp->FontTypeFlg;
  378. }
  379. if(!lstrcmp((LPCTSTR)lpAssociationRegTmp->szFileName,FileList)){
  380. if (lpAssociationRegTmp->UpdateFlg)
  381. DeleteReg(lpAssociationRegTmp->szFaceName);
  382. lpAssociationRegTmp++;
  383. continue;
  384. }
  385. //*STRSAFE* lstrcpy( (LPTSTR)TTFPath, (LPCTSTR)lpAssociationRegTmp->szFileName);
  386. hresult = StringCchCopy((LPTSTR)TTFPath , ARRAYLEN(TTFPath), (LPCTSTR)lpAssociationRegTmp->szFileName);
  387. if (!SUCCEEDED(hresult))
  388. {
  389. EnableEUDC(TRUE);
  390. return ;
  391. }
  392. //*STRSAFE* lstrcpy( BMPPath, TTFPath);
  393. hresult = StringCchCopy(BMPPath , ARRAYLEN(BMPPath), TTFPath);
  394. if (!SUCCEEDED(hresult))
  395. {
  396. EnableEUDC(TRUE);
  397. return ;
  398. }
  399. if(( FilePtr = Mytcsrchr( BMPPath, '.')) != NULL)
  400. *FilePtr = '\0';
  401. //*STRSAFE* lstrcat( BMPPath, TEXT(".EUF"));
  402. hresult = StringCchCat(BMPPath , ARRAYLEN(BMPPath), TEXT(".EUF"));
  403. if (!SUCCEEDED(hresult))
  404. {
  405. EnableEUDC(TRUE);
  406. return ;
  407. }
  408. if( OExistTTF( TTFPath))
  409. {
  410. #if (WINVER >= 0x0500)
  411. if (IsWin95EUDCBmp(BMPPath))
  412. {
  413. if (!HandleImportWin95(TTFPath, BMPPath,nIndex ))
  414. {
  415. // EnableEUDC( TRUE);
  416. // return;
  417. }
  418. }
  419. #endif
  420. }
  421. if( !lpAssociationRegTmp->UpdateFlg){
  422. lpAssociationRegTmp++;
  423. continue;
  424. }
  425. if( !RegistTypeFace(
  426. lpAssociationRegTmp->szFaceName,
  427. lpAssociationRegTmp->szFileName))
  428. {
  429. EnableEUDC( TRUE);
  430. return;
  431. }
  432. lpAssociationRegTmp++;
  433. }
  434. EnableEUDC( TRUE);
  435. if( CheckFlg != DBCSCHK){
  436. if (!InitSystemFontAssoc())
  437. {
  438. return;
  439. }
  440. }
  441. GlobalUnlock( hMem);
  442. GlobalFree( hMem);
  443. EndDialog(IDOK);
  444. }
  445. BOOL
  446. CAssocDlg::InitSystemFontAssoc()
  447. {
  448. TCHAR DefaultFace[LF_FACESIZE];
  449. TCHAR DefaultFile[MAX_PATH];
  450. TCHAR TTFPath[MAX_PATH];
  451. TCHAR BMPPath[MAX_PATH];
  452. TCHAR *FilePtr;
  453. HRESULT hresult;
  454. GetStringRes(DefaultFace, IDS_SYSTEMEUDCFONT_STR, ARRAYLEN(DefaultFace));
  455. GetStringRes(DefaultFile, IDS_DEFAULTFILENAME, ARRAYLEN(DefaultFile));
  456. // if the registry data for SystemEUDC font is already there, just use that.
  457. if (!InqTypeFace(DefaultFace,TTFPath,MAX_PATH)) {
  458. GetSystemWindowsDirectory( TTFPath, MAX_PATH);
  459. #ifdef IN_FONTS_DIR // CAssocDlg::OnOK()
  460. //*STRSAFE* lstrcat( TTFPath, TEXT("\\FONTS\\"));
  461. hresult = StringCchCat(TTFPath , ARRAYLEN(TTFPath), TEXT("\\FONTS\\"));
  462. if (!SUCCEEDED(hresult))
  463. {
  464. return FALSE;
  465. }
  466. #else
  467. //*STRSAFE* lstrcat( TTFPath, TEXT("\\"));
  468. hresult = StringCchCat(TTFPath , ARRAYLEN(TTFPath), TEXT("\\"));
  469. if (!SUCCEEDED(hresult))
  470. {
  471. return FALSE;
  472. }
  473. #endif // IN_FONTS_DIR
  474. //*STRSAFE* lstrcat( TTFPath, DefaultFile);
  475. hresult = StringCchCat(TTFPath , ARRAYLEN(TTFPath), DefaultFile);
  476. if (!SUCCEEDED(hresult))
  477. {
  478. return FALSE;
  479. }
  480. }
  481. //*STRSAFE* lstrcpy( BMPPath, TTFPath);
  482. hresult = StringCchCopy(BMPPath , ARRAYLEN(BMPPath), TTFPath);
  483. if (!SUCCEEDED(hresult))
  484. {
  485. return FALSE;
  486. }
  487. if(( FilePtr = Mytcsrchr( BMPPath, '.')) != NULL)
  488. *FilePtr = '\0';
  489. //*STRSAFE* lstrcat( BMPPath, TEXT(".EUF"));
  490. hresult = StringCchCat(BMPPath , ARRAYLEN(BMPPath), TEXT(".EUF"));
  491. if (!SUCCEEDED(hresult))
  492. {
  493. return FALSE;
  494. }
  495. // It delays 1 second to call EnabelEUDC(FALSE).
  496. DWORD dwStart = GetTickCount();
  497. // Stop if this has taken too long
  498. while (1)
  499. {
  500. if( GetTickCount() - dwStart >= 1000 )
  501. break;
  502. }
  503. EnableEUDC( FALSE);
  504. if(OExistTTF( TTFPath))
  505. {
  506. #if (WINVER >= 0x0500)
  507. if (IsWin95EUDCBmp(BMPPath))
  508. {
  509. if (!HandleImportWin95(TTFPath, BMPPath, -1))
  510. {
  511. EnableEUDC( TRUE);
  512. return FALSE;
  513. }
  514. }
  515. #endif
  516. }
  517. SelectEUDC.m_FontTypeFlg = TRUE;
  518. //*STRSAFE* lstrcpy(SelectEUDC.m_Font,(const TCHAR *)DefaultFace);
  519. hresult = StringCchCopy(SelectEUDC.m_Font , ARRAYLEN(SelectEUDC.m_Font), (const TCHAR *)DefaultFace);
  520. if (!SUCCEEDED(hresult))
  521. {
  522. EnableEUDC( TRUE);
  523. return FALSE;
  524. }
  525. //*STRSAFE* lstrcpy(SelectEUDC.m_File,(const TCHAR *)TTFPath);
  526. hresult = StringCchCopy(SelectEUDC.m_File , ARRAYLEN(SelectEUDC.m_File), (const TCHAR *)TTFPath);
  527. if (!SUCCEEDED(hresult))
  528. {
  529. EnableEUDC( TRUE);
  530. return FALSE;
  531. }
  532. //*STRSAFE* lstrcpy(SelectEUDC.m_FileTitle,(const TCHAR *)DefaultFile);
  533. hresult = StringCchCopy(SelectEUDC.m_FileTitle , ARRAYLEN(SelectEUDC.m_FileTitle), (const TCHAR *)DefaultFile);
  534. if (!SUCCEEDED(hresult))
  535. {
  536. EnableEUDC( TRUE);
  537. return FALSE;
  538. }
  539. if( !RegistTypeFace(DefaultFace, TTFPath)){
  540. EnableEUDC( TRUE);
  541. return FALSE;
  542. }
  543. EnableEUDC( TRUE);
  544. return TRUE;
  545. }
  546. /****************************************/
  547. /* */
  548. /* MESSAGE "WM_DBLCLKS" */
  549. /* */
  550. /****************************************/
  551. void
  552. CAssocDlg::OnDblclkRegistlist()
  553. {
  554. this->SendMessage(WM_COMMAND, IDC_MODIFY, 0);
  555. }
  556. /****************************************/
  557. /* */
  558. /* COMMAND "IDCANCEL" */
  559. /* */
  560. /****************************************/
  561. void
  562. CAssocDlg::OnCancel()
  563. {
  564. GlobalUnlock( hMem);
  565. GlobalFree( hMem);
  566. EndDialog( IDCANCEL);
  567. }
  568. /****************************************/
  569. /* */
  570. /* COMMAND "Modify" */
  571. /* */
  572. /****************************************/
  573. void
  574. CAssocDlg::OnModify()
  575. {
  576. LPASSOCIATIONREG lpAssociationRegTmp;
  577. OPENFILENAME ofn;
  578. CString sFilter;
  579. CWnd *cWnd;
  580. TCHAR chReplace;
  581. CString szDlgTtl;
  582. TCHAR szFilter[MAX_PATH];
  583. TCHAR szFileName[MAX_PATH];
  584. TCHAR szTitleName[MAX_PATH];
  585. TCHAR szDirName[MAX_PATH];
  586. HRESULT hresult;
  587. int nIndex = m_RegListBox.GetCurSel();
  588. if( nIndex == -1){
  589. OutputMessageBox( this->GetSafeHwnd(),
  590. IDS_ASSOCIATE_DLGTITLE,
  591. IDS_NOTSELTYPEFACE_MSG, TRUE);
  592. m_RegListBox.SetFocus();
  593. return;
  594. }
  595. //lpAssociationRegTmp = lpAssociationReg + nIndex;
  596. lpAssociationRegTmp = lpAssociationReg + m_RegListBox.GetItemData(nIndex);
  597. // Set filter of file( from string table)
  598. GetStringRes(szFilter, IDS_EUDCTTF_FILTER, ARRAYLEN(szFilter));
  599. int StringLength = lstrlen( szFilter);
  600. chReplace = szFilter[StringLength-1];
  601. for( int i = 0; szFilter[i]; i++){
  602. if( szFilter[i] == chReplace)
  603. szFilter[i] = '\0';
  604. }
  605. GetSystemWindowsDirectory( szDirName, sizeof(szDirName)/sizeof(TCHAR));
  606. #ifdef IN_FONTS_DIR // CAssocDlg::OnModify()
  607. //*STRSAFE* lstrcat( szDirName, TEXT("\\FONTS\\"));
  608. hresult = StringCchCat(szDirName , ARRAYLEN(szDirName), TEXT("\\FONTS\\"));
  609. if (!SUCCEEDED(hresult))
  610. {
  611. return ;
  612. }
  613. #endif // IN_FONTS_DIR
  614. //*STRSAFE* lstrcpy( szFileName, TEXT("*.TTE"));
  615. hresult = StringCchCopy(szFileName , ARRAYLEN(szFileName), TEXT("*.TTE"));
  616. if (!SUCCEEDED(hresult))
  617. {
  618. return ;
  619. }
  620. szDlgTtl.LoadString( IDS_MODIFY_DLGTITLE);
  621. // Set data in structure of OPENFILENAME
  622. ofn.lStructSize = sizeof( OPENFILENAME);
  623. ofn.hInstance = AfxGetInstanceHandle();
  624. ofn.hwndOwner = this->GetSafeHwnd();
  625. ofn.lpstrFilter = szFilter;
  626. ofn.lpstrCustomFilter = NULL;
  627. ofn.nMaxCustFilter = 0;
  628. ofn.nFilterIndex = 0;
  629. ofn.lpstrFile = szFileName;
  630. ofn.lpstrFileTitle = szTitleName;
  631. ofn.nMaxFileTitle = sizeof( szTitleName) / sizeof(TCHAR);
  632. ofn.nMaxFile = sizeof( szFileName) / sizeof(TCHAR);
  633. ofn.lpstrInitialDir = szDirName;
  634. ofn.Flags = OFN_HIDEREADONLY | OFN_NOCHANGEDIR
  635. | OFN_PATHMUSTEXIST ;
  636. // there's no direct overwrite issue here, the file will be re-cycled.
  637. //| OFN_OVERWRITEPROMPT;
  638. ofn.lpstrDefExt = TEXT("tte");
  639. ofn.lpstrTitle = szDlgTtl;
  640. if( !GetSaveFileName( &ofn)){
  641. return;
  642. }
  643. TCHAR tmpName[MAX_PATH];
  644. //*STRSAFE* lstrcpy(tmpName, szDirName);
  645. hresult = StringCchCopy(tmpName , ARRAYLEN(tmpName), szDirName);
  646. if (!SUCCEEDED(hresult))
  647. {
  648. return ;
  649. }
  650. //*STRSAFE* lstrcat(tmpName, TEXT("eudc.tte"));
  651. hresult = StringCchCat(tmpName , ARRAYLEN(tmpName), TEXT("eudc.tte"));
  652. if (!SUCCEEDED(hresult))
  653. {
  654. return ;
  655. }
  656. if( !lstrcmpi(ofn.lpstrFile, tmpName) ) {
  657. OutputMessageBox( this->GetSafeHwnd(),
  658. IDS_MODIFY_DLGTITLE,
  659. IDS_NOUSEEUDCFILE_MSG, TRUE);
  660. return;
  661. }
  662. if( !CheckFileName( ofn.lpstrFile)){
  663. OutputMessageBox( this->GetSafeHwnd(),
  664. IDS_MODIFY_DLGTITLE,
  665. IDS_ILLEGALFILE_MSG, TRUE);
  666. return;
  667. }
  668. if( OExistTTF( ofn.lpstrFile)){
  669. if( !IsEUDCTTF( ofn.lpstrFile)){
  670. OutputMessageBox( this->GetSafeHwnd(),
  671. IDS_MODIFY_DLGTITLE,
  672. IDS_NOTEUDCFILE_MSG, TRUE);
  673. return;
  674. }
  675. }
  676. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileName, ofn.lpstrFile);
  677. hresult = StringCchCopy(lpAssociationRegTmp->szFileName , ARRAYLEN(lpAssociationRegTmp->szFileName), ofn.lpstrFile);
  678. if (!SUCCEEDED(hresult))
  679. {
  680. return ;
  681. }
  682. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileTitle, ofn.lpstrFileTitle);
  683. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), ofn.lpstrFileTitle);
  684. if (!SUCCEEDED(hresult))
  685. {
  686. return ;
  687. }
  688. lpAssociationRegTmp->UpdateFlg = TRUE;
  689. m_RegListBox.InsertString( nIndex,
  690. (LPCTSTR)lpAssociationRegTmp->szFaceName);
  691. m_RegListBox.SetItemData(nIndex, m_RegListBox.GetItemData(nIndex+1));
  692. m_RegListBox.DeleteString( nIndex + 1);
  693. m_RegListBox.SetCurSel( nIndex);
  694. cWnd = GetDlgItem( IDC_REGISTLIST);
  695. GotoDlgCtrl( cWnd);
  696. }
  697. /****************************************/
  698. /* */
  699. /* COMMAND "Remove" */
  700. /* */
  701. /****************************************/
  702. void
  703. CAssocDlg::OnRemove()
  704. {
  705. LPASSOCIATIONREG lpAssociationRegTmp;
  706. TCHAR Tmp[MAX_PATH];
  707. HRESULT hresult;
  708. int nIndex = m_RegListBox.GetCurSel();
  709. if( nIndex == -1){
  710. OutputMessageBox( this->GetSafeHwnd(),
  711. IDS_ASSOCIATE_DLGTITLE,
  712. IDS_NOTSELTYPEFACE_MSG, TRUE);
  713. m_RegListBox.SetFocus();
  714. return;
  715. }
  716. GetStringRes( Tmp, IDS_NOTSELECT_STR, ARRAYLEN(Tmp));
  717. //lpAssociationRegTmp = lpAssociationReg + nIndex;
  718. lpAssociationRegTmp = lpAssociationReg + m_RegListBox.GetItemData(nIndex);
  719. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileName, (const TCHAR *)Tmp);
  720. hresult = StringCchCopy(lpAssociationRegTmp->szFileName , ARRAYLEN(lpAssociationRegTmp->szFileName), (const TCHAR *)Tmp);
  721. if (!SUCCEEDED(hresult))
  722. {
  723. return ;
  724. }
  725. //*STRSAFE* lstrcpy(lpAssociationRegTmp->szFileTitle, (const TCHAR *)Tmp);
  726. hresult = StringCchCopy(lpAssociationRegTmp->szFileTitle , ARRAYLEN(lpAssociationRegTmp->szFileTitle), (const TCHAR *)Tmp);
  727. if (!SUCCEEDED(hresult))
  728. {
  729. return ;
  730. }
  731. lpAssociationRegTmp->UpdateFlg = TRUE;
  732. m_RegListBox.InsertString( nIndex,
  733. lpAssociationRegTmp->szFaceName);
  734. m_RegListBox.SetItemData(nIndex, m_RegListBox.GetItemData(nIndex+1));
  735. m_RegListBox.DeleteString( nIndex + 1);
  736. m_RegListBox.SetCurSel( nIndex);
  737. // DeleteReg(lpAssociationRegTmp->szFaceName);
  738. CWnd *cWnd = GetDlgItem( IDC_REGISTLIST);
  739. GotoDlgCtrl( cWnd);
  740. }
  741. /****************************************/
  742. /* */
  743. /* Check .TTF */
  744. /* */
  745. /****************************************/
  746. static int
  747. CheckTTF(
  748. LOGFONT LogFont)
  749. {
  750. struct NamingTable *Ntbl;
  751. struct NameRecord *NameRec;
  752. HGLOBAL hglb;
  753. DWORD dwSize = 0L;
  754. DWORD dwTable = 0L;
  755. LPSTR lpBuffer, lpTable;
  756. HFONT hFont = NULL;
  757. HGDIOBJ OldFont = NULL;
  758. short nRec = 0;
  759. int sysLCID;
  760. // Check "tategaki" or not
  761. if( LogFont.lfFaceName[0] == '@')
  762. return 0;
  763. // Get current font to Inquire ttf file
  764. hFont = ::CreateFontIndirect( &LogFont);
  765. if( hFont ) {
  766. OldFont = ::SelectObject( hDC, hFont);
  767. }
  768. // Get name table in ttf file
  769. lpTable = "name";
  770. dwTable = *(LPDWORD)lpTable;
  771. dwSize = ::GetFontData( hDC, dwTable, 0L, NULL, 0L);
  772. if( dwSize == GDI_ERROR || dwSize == 0){
  773. if( OldFont ) ::SelectObject(hDC, OldFont);
  774. if( hFont ) ::DeleteObject(hFont);
  775. return 0;
  776. }
  777. hglb = GlobalAlloc( GHND, dwSize);
  778. if( hglb == NULL){
  779. if( OldFont ) ::SelectObject(hDC, OldFont);
  780. if( hFont ) ::DeleteObject(hFont);
  781. return -1;
  782. }
  783. lpBuffer = (LPSTR)GlobalLock( hglb);
  784. ::GetFontData( hDC, dwTable, 0L, (LPVOID)lpBuffer, dwSize);
  785. if( OldFont ) ::SelectObject(hDC, OldFont);
  786. if( hFont ) ::DeleteObject(hFont);
  787. Ntbl = (struct NamingTable *)lpBuffer;
  788. sitom( &Ntbl->NRecs);
  789. nRec = Ntbl->NRecs;
  790. lpBuffer += sizeof(struct NamingTable);
  791. sysLCID = (int) LANGIDFROMLCID(GetSystemDefaultLCID());
  792. while( nRec-- > 0){
  793. NameRec = (struct NameRecord *)lpBuffer;
  794. sitom( &NameRec->PlatformID);
  795. sitom( &NameRec->PlatformSpecEncID);
  796. sitom( &NameRec->LanguageID);
  797. #ifdef BUILD_ON_WINNT
  798. // Unicode TTF
  799. if( CountryInfo.bUnicodeMode ){
  800. // if( NameRec->PlatformID == 3 &&
  801. // NameRec->LanguageID == sysLCID){
  802. GlobalUnlock( hglb);
  803. GlobalFree( hglb);
  804. return 1;
  805. // }
  806. }
  807. #endif //BUILD_ON_WINNT
  808. // Japanese TTF
  809. if( CountryInfo.LangID == EUDC_JPN){
  810. if( NameRec->PlatformID == 3 &&
  811. NameRec->LanguageID == EUDC_JPN){
  812. GlobalUnlock( hglb);
  813. GlobalFree( hglb);
  814. return 1;
  815. }
  816. }
  817. // Chinese Taipei TTF
  818. if( CountryInfo.LangID == EUDC_CHT){
  819. if( NameRec->PlatformID == 3 &&
  820. NameRec->LanguageID == EUDC_CHT){
  821. GlobalUnlock( hglb);
  822. GlobalFree( hglb);
  823. return 1;
  824. }
  825. }
  826. // Chinese GB TTF
  827. if( CountryInfo.LangID == EUDC_CHS){
  828. if( NameRec->PlatformID == 3 &&
  829. NameRec->LanguageID == EUDC_CHS){
  830. GlobalUnlock( hglb);
  831. GlobalFree( hglb);
  832. return 1;
  833. }
  834. }
  835. // Korea TTF(WANSUNG)
  836. if( CountryInfo.LangID == EUDC_KRW){
  837. if( NameRec->PlatformID == 3 &&
  838. NameRec->LanguageID == EUDC_KRW){
  839. GlobalUnlock( hglb);
  840. GlobalFree( hglb);
  841. return 1;
  842. }
  843. }
  844. /*
  845. // Hebrew TTF
  846. if( CountryInfo.LangID == EUDC_HEBREW) {
  847. if( NameRec->PlatformID == 1 &&
  848. NameRec->LanguageID == 0 ) {
  849. GlobalUnlock( hglb);
  850. GlobalFree( hglb);
  851. return 1;
  852. }
  853. }
  854. */
  855. lpBuffer += sizeof(struct NameRecord);
  856. }
  857. GlobalUnlock( hglb);
  858. GlobalFree( hglb);
  859. return 0;
  860. }
  861. /****************************************/
  862. /* */
  863. /* Radio DBCS Clicked */
  864. /* */
  865. /****************************************/
  866. void
  867. CAssocDlg::OnRadioDbcs()
  868. {
  869. CWnd *cWnd;
  870. if( CheckFlg != DBCSCHK){
  871. CheckFlg = DBCSCHK;
  872. m_RegListBox.EnableWindow( TRUE);
  873. m_RegListBox.EnableScrollBar( SB_VERT, ESB_ENABLE_BOTH);
  874. m_RegListBox.UpdateWindow();
  875. cWnd = this->GetDlgItem( IDC_MODIFY);
  876. cWnd->EnableWindow( TRUE);
  877. cWnd = this->GetDlgItem( IDC_REMOVE);
  878. cWnd->EnableWindow( TRUE);
  879. }
  880. }
  881. /****************************************/
  882. /* */
  883. /* Radio SYSTEM Clicked */
  884. /* */
  885. /****************************************/
  886. void
  887. CAssocDlg::OnRadioSystem()
  888. {
  889. CWnd *cWnd;
  890. if( CheckFlg != EUDCCHK){
  891. CheckFlg = EUDCCHK;
  892. m_RegListBox.EnableWindow( FALSE);
  893. m_RegListBox.EnableScrollBar( SB_VERT, ESB_DISABLE_BOTH);
  894. cWnd = this->GetDlgItem( IDC_MODIFY);
  895. cWnd->EnableWindow( FALSE);
  896. cWnd = this->GetDlgItem( IDC_REMOVE);
  897. cWnd->EnableWindow( FALSE);
  898. }
  899. }
  900. /****************************************/
  901. /* */
  902. /* Inquire into file( EUDC or not) */
  903. /* */
  904. /****************************************/
  905. static BOOL
  906. IsEUDCTTF(
  907. TCHAR *ttffile)
  908. {
  909. struct NamingTable *nTbl;
  910. struct NameRecord *nRec;
  911. unsigned int BufSiz;
  912. char *TableBuf, *SearchOfs;
  913. char TTFName[MAX_CODE];
  914. HANDLE fHdl = CreateFile(ttffile,
  915. GENERIC_READ,
  916. FILE_SHARE_READ | FILE_SHARE_WRITE,
  917. NULL,
  918. OPEN_EXISTING,
  919. FILE_ATTRIBUTE_NORMAL,
  920. NULL);
  921. if ( fHdl == INVALID_HANDLE_VALUE)
  922. return FALSE;
  923. if( TTFReadVarTable( fHdl, &TableBuf, &BufSiz, "name")){
  924. CloseHandle( fHdl);
  925. return FALSE;
  926. }
  927. SearchOfs = TableBuf;
  928. nTbl = (struct NamingTable *)TableBuf;
  929. sitom( &nTbl->OfsToStr);
  930. SearchOfs += sizeof(struct NamingTable);
  931. SearchOfs += sizeof(struct NameRecord);
  932. nRec = (struct NameRecord *)SearchOfs;
  933. sitom( &nRec->StringOfs);
  934. SearchOfs = TableBuf + nTbl->OfsToStr + nRec->StringOfs;
  935. SearchOfs += sizeof(char);
  936. for( short Inc = 0; Inc < MAX_CODE - 1; Inc++){
  937. TTFName[Inc] = (char)*SearchOfs;
  938. SearchOfs += sizeof(char)*2;
  939. }
  940. TTFName[Inc] = '\0';
  941. if( lstrcmpA( TTFName, "EUDC") == 0){
  942. free( TableBuf);
  943. CloseHandle( fHdl);
  944. return TRUE;
  945. }
  946. free( TableBuf);
  947. CloseHandle( fHdl);
  948. return FALSE;
  949. }
  950. /****************************************/
  951. /* */
  952. /* Inquire into filename */
  953. /* */
  954. /****************************************/
  955. static BOOL
  956. CheckFileName(
  957. LPTSTR FileStr)
  958. {
  959. TCHAR FileTmp[MAX_PATH];
  960. TCHAR Tmp[MAX_PATH];
  961. TCHAR *FilePtr;
  962. HRESULT hresult =S_OK;
  963. if (!FileStr)
  964. {
  965. return FALSE;
  966. }
  967. FilePtr = FileStr;
  968. while( *FilePtr == ' ')
  969. FilePtr++;
  970. if( *FilePtr == '.' || *FilePtr == '\0')
  971. return FALSE;
  972. int i = 0;
  973. while( *FilePtr != '\0'){
  974. FileTmp[i] = *FilePtr;
  975. FilePtr++;
  976. i++;
  977. }
  978. FileTmp[i] = '\0';
  979. if(( FilePtr = Mytcsrchr( FileTmp, '.')) == NULL)
  980. //*STRSAFE* lstrcat( FileTmp, TEXT(".tte"));
  981. hresult = StringCchCat(FileTmp , ARRAYLEN(FileTmp), TEXT(".tte"));
  982. if (!SUCCEEDED(hresult))
  983. {
  984. return FALSE;
  985. }
  986. else{
  987. #ifdef BUILD_ON_WINNT
  988. //*STRSAFE if( lstrcmpi( FilePtr, TEXT(".TTE")))
  989. if (CompareString(LOCALE_INVARIANT,NORM_IGNORECASE,FilePtr,-1,TEXT(".TTE"),-1) != 2 )
  990. #else
  991. if( stricmp( FilePtr, ".TTE"))
  992. #endif // BUILD_ON_WINNT
  993. return FALSE;
  994. }
  995. //*STRSAFE* lstrcpy(Tmp, FileTmp);
  996. hresult = StringCchCopy(Tmp , ARRAYLEN(Tmp), FileTmp);
  997. if (!SUCCEEDED(hresult))
  998. {
  999. return FALSE;
  1000. }
  1001. if( lstrlen(Tmp) >= MAX_PATH)
  1002. return FALSE;
  1003. //*STRSAFE* lstrcpy( FileStr, FileTmp);
  1004. hresult = StringCchCopy(FileStr , MAX_PATH, FileTmp);
  1005. if (!SUCCEEDED(hresult))
  1006. {
  1007. return FALSE;
  1008. }
  1009. return TRUE;
  1010. }
  1011. static DWORD aIds[] =
  1012. {
  1013. IDC_MODIFY, IDH_EUDC_MODIFY,
  1014. IDC_REMOVE, IDH_EUDC_REMOVE,
  1015. IDC_REGISTLIST, IDH_EUDC_ASSO_LIST,
  1016. IDC_RADIO_SYSTEM, IDH_EUDC_ASSO_STANDARD,
  1017. IDC_RADIO_DBCS, IDH_EUDC_ASSO_TYPEFACE,
  1018. 0,0
  1019. };
  1020. /****************************************/
  1021. /* */
  1022. /* Window Procedure */
  1023. /* */
  1024. /****************************************/
  1025. LRESULT
  1026. CAssocDlg::WindowProc(
  1027. UINT message,
  1028. WPARAM wParam,
  1029. LPARAM lParam)
  1030. {
  1031. if( message == WM_HELP){
  1032. ::WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  1033. HelpPath, HELP_WM_HELP, (DWORD_PTR)(LPSTR)aIds);
  1034. return(0);
  1035. }
  1036. if( message == WM_CONTEXTMENU){
  1037. ::WinHelp((HWND)wParam, HelpPath,
  1038. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)aIds);
  1039. return(0);
  1040. }
  1041. return CDialog::WindowProc(message, wParam, lParam);
  1042. }
  1043. BEGIN_MESSAGE_MAP(CAssocDlg, CDialog)
  1044. //{{AFX_MSG_MAP(CAssocDlg)
  1045. ON_LBN_DBLCLK(IDC_REGISTLIST, OnDblclkRegistlist)
  1046. ON_BN_CLICKED(IDC_MODIFY, OnModify)
  1047. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  1048. ON_BN_CLICKED(IDC_RADIO_DBCS, OnRadioDbcs)
  1049. ON_BN_CLICKED(IDC_RADIO_SYSTEM, OnRadioSystem)
  1050. //}}AFX_MSG_MAP
  1051. END_MESSAGE_MAP()
  1052. /****************************************/
  1053. /* */
  1054. /* MeasureItem */
  1055. /* */
  1056. /****************************************/
  1057. void
  1058. CRegistListBox::MeasureItem(
  1059. LPMEASUREITEMSTRUCT lpMIS)
  1060. {
  1061. CRect ListBoxRect;
  1062. if (!lpMIS)
  1063. {
  1064. return;
  1065. }
  1066. this->GetClientRect( &ListBoxRect);
  1067. ItemHeight = ListBoxRect.Height() /NUMITEM;
  1068. lpMIS->itemHeight = ItemHeight;
  1069. }
  1070. /****************************************/
  1071. /* */
  1072. /* Draw Item */
  1073. /* */
  1074. /****************************************/
  1075. void
  1076. CRegistListBox::DrawItem(
  1077. LPDRAWITEMSTRUCT lpDIS)
  1078. {
  1079. LPASSOCIATIONREG lpAssociationRegTmp;
  1080. LOGFONT LogFont;
  1081. CSize CharSize, FontSize, cSize;
  1082. TCHAR FileTmp[MAX_PATH], NotSel[MAX_PATH];
  1083. int Offset;
  1084. HRESULT hresult;
  1085. if (!lpDIS)
  1086. {
  1087. return;
  1088. }
  1089. CDC* pDC = CDC::FromHandle( lpDIS->hDC);
  1090. if( lpDIS->itemAction & ODA_DRAWENTIRE){
  1091. CBrush fBrush;
  1092. fBrush.CreateSolidBrush(GetSysColor(COLOR_WINDOW)); // COLOR_WIN);
  1093. pDC->FillRect( &lpDIS->rcItem, &fBrush);
  1094. fBrush.DeleteObject();
  1095. pDC->SetBkColor( GetSysColor(COLOR_WINDOW)); //COLOR_WIN);
  1096. //lpAssociationRegTmp = lpAssociationReg + lpDIS->itemID;
  1097. lpAssociationRegTmp = lpAssociationReg + lpDIS->itemData;
  1098. if( CheckFlg == DBCSCHK)
  1099. pDC->SetTextColor( GetSysColor(COLOR_WINDOWTEXT)); //COLOR_BLACK);
  1100. else pDC->SetTextColor( GetSysColor(COLOR_GRAYTEXT)); //COLOR_SHADOW);
  1101. GetFont()->GetObject( sizeof(LOGFONT), &LogFont);
  1102. if( abs( LogFont.lfHeight) < ItemHeight)
  1103. Offset = ( ItemHeight - abs( LogFont.lfHeight)) /2;
  1104. else Offset = 0;
  1105. if( lpAssociationRegTmp->FontTypeFlg){
  1106. pDC->DrawIcon( lpDIS->rcItem.left + LSPACE,
  1107. lpDIS->rcItem.top + Offset, tIcon);
  1108. }
  1109. //*STRSAFE* lstrcpy(FileTmp,(const TCHAR *)lpAssociationRegTmp->szFileTitle);
  1110. hresult = StringCchCopy(FileTmp , ARRAYLEN(FileTmp), (const TCHAR *)lpAssociationRegTmp->szFileTitle);
  1111. if (!SUCCEEDED(hresult))
  1112. {
  1113. return ;
  1114. }
  1115. GetStringRes( NotSel, IDS_NOTSELECT_STR, ARRAYLEN(NotSel));
  1116. if( FileTmp[0] == '\0' ||
  1117. !lstrcmp((const TCHAR *)FileTmp,(const TCHAR *)NotSel)){
  1118. }else{
  1119. TCHAR *FilePtr;
  1120. if(( FilePtr = Mytcsrchr( FileTmp, '.')) != NULL)
  1121. *FilePtr = '\0';
  1122. if( lstrlen((const TCHAR *)FileTmp) > 20){
  1123. FileTmp[20] = '\0';
  1124. //*STRSAFE* lstrcat((TCHAR *)FileTmp, TEXT(".."));
  1125. hresult = StringCchCat((TCHAR *)FileTmp , ARRAYLEN(FileTmp), TEXT(".."));
  1126. if (!SUCCEEDED(hresult))
  1127. {
  1128. return ;
  1129. }
  1130. }
  1131. }
  1132. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1133. (const TCHAR *)FileTmp,
  1134. lstrlen((const TCHAR *)FileTmp), &CharSize);
  1135. pDC->ExtTextOut( lpDIS->rcItem.right - CharSize.cx - RSPACE,
  1136. lpDIS->rcItem.top + Offset, 0, 0,
  1137. (const TCHAR *)FileTmp,
  1138. lstrlen((const TCHAR *)FileTmp), NULL);
  1139. int FontWidth;
  1140. //*STRSAFE* lstrcpy(FontName, (const TCHAR *)lpAssociationRegTmp->szFaceName);
  1141. hresult = StringCchCopy(FontName , ARRAYLEN(FontName), (const TCHAR *)lpAssociationRegTmp->szFaceName);
  1142. if (!SUCCEEDED(hresult))
  1143. {
  1144. return ;
  1145. }
  1146. FontWidth = lpDIS->rcItem.right - lpDIS->rcItem.left
  1147. - LCSPACE - RSPACE - CharSize.cx;
  1148. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1149. (const TCHAR *)FontName,
  1150. lstrlen((const TCHAR *)FontName), &FontSize);
  1151. if( FontWidth <= FontSize.cx){
  1152. int i;
  1153. GetTextExtentPoint32( pDC->GetSafeHdc(),TEXT("<<"),2, &cSize);
  1154. i = ( FontWidth /cSize.cx) * 2;
  1155. FontName[i-2] = '.';
  1156. FontName[i-1] = '.';
  1157. FontName[i] = '\0';
  1158. }
  1159. pDC->ExtTextOut(lpDIS->rcItem.left + LCSPACE,
  1160. lpDIS->rcItem.top + Offset, 0, 0,
  1161. FontName,
  1162. lstrlen(FontName), NULL);
  1163. }
  1164. if(( lpDIS->itemState & ODS_SELECTED) &&
  1165. ( lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE))){
  1166. CBrush fBrush;
  1167. if( CheckFlg == DBCSCHK)
  1168. fBrush.CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
  1169. else fBrush.CreateSolidBrush(GetSysColor(COLOR_WINDOW)); // COLOR_WIN);
  1170. pDC->FillRect( &lpDIS->rcItem, &fBrush);
  1171. fBrush.DeleteObject();
  1172. //lpAssociationRegTmp = lpAssociationReg + lpDIS->itemID;
  1173. lpAssociationRegTmp = lpAssociationReg + lpDIS->itemData;
  1174. if( CheckFlg == DBCSCHK){
  1175. pDC->SetBkColor(::GetSysColor( COLOR_HIGHLIGHT));
  1176. pDC->SetTextColor(::GetSysColor( COLOR_HIGHLIGHTTEXT));
  1177. }else{
  1178. pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // COLOR_WIN);
  1179. pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); // COLOR_SHADOW);
  1180. }
  1181. GetFont()->GetObject( sizeof(LOGFONT), &LogFont);
  1182. if( abs( LogFont.lfHeight) < ItemHeight)
  1183. Offset = ( ItemHeight - abs( LogFont.lfHeight)) /2;
  1184. else Offset = 0;
  1185. if( lpAssociationRegTmp->FontTypeFlg){
  1186. pDC->DrawIcon( lpDIS->rcItem.left + LSPACE,
  1187. lpDIS->rcItem.top + Offset, tIcon);
  1188. }
  1189. //*STRSAFE* lstrcpy(FileTmp,lpAssociationRegTmp->szFileTitle);
  1190. hresult = StringCchCopy(FileTmp , ARRAYLEN(FileTmp), lpAssociationRegTmp->szFileTitle);
  1191. if (!SUCCEEDED(hresult))
  1192. {
  1193. return ;
  1194. }
  1195. GetStringRes( NotSel, IDS_NOTSELECT_STR, ARRAYLEN(NotSel));
  1196. if( FileTmp[0] == '\0' ||
  1197. !lstrcmp(FileTmp,NotSel)){
  1198. }else{
  1199. TCHAR *FilePtr;
  1200. if(( FilePtr = Mytcsrchr( FileTmp, '.')) != NULL)
  1201. *FilePtr = '\0';
  1202. if( lstrlen(FileTmp) > 20){
  1203. FileTmp[20] = '\0';
  1204. //*STRSAFE* lstrcat(FileTmp, TEXT(".."));
  1205. hresult = StringCchCat(FileTmp , ARRAYLEN(FileTmp), TEXT(".."));
  1206. if (!SUCCEEDED(hresult))
  1207. {
  1208. return ;
  1209. }
  1210. }
  1211. }
  1212. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1213. FileTmp,
  1214. lstrlen(FileTmp), &CharSize);
  1215. pDC->ExtTextOut( lpDIS->rcItem.right - CharSize.cx - RSPACE,
  1216. lpDIS->rcItem.top + Offset, 0, 0,
  1217. FileTmp,
  1218. lstrlen(FileTmp), NULL);
  1219. int FontWidth;
  1220. //*STRSAFE* lstrcpy(FontName, lpAssociationRegTmp->szFaceName);
  1221. hresult = StringCchCopy(FontName , ARRAYLEN(FontName), lpAssociationRegTmp->szFaceName);
  1222. if (!SUCCEEDED(hresult))
  1223. {
  1224. return ;
  1225. }
  1226. FontWidth = lpDIS->rcItem.right - lpDIS->rcItem.left
  1227. - LCSPACE - RSPACE - CharSize.cx;
  1228. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1229. FontName,
  1230. lstrlen(FontName), &FontSize);
  1231. if( FontWidth <= FontSize.cx){
  1232. int i;
  1233. GetTextExtentPoint32( pDC->GetSafeHdc(),TEXT("<<"),2, &cSize);
  1234. i = ( FontWidth /cSize.cx) * 2;
  1235. FontName[i-2] = '.';
  1236. FontName[i-1] = '.';
  1237. FontName[i] = '\0';
  1238. }
  1239. pDC->ExtTextOut( lpDIS->rcItem.left + LCSPACE,
  1240. lpDIS->rcItem.top + Offset, 0, 0,
  1241. FontName,
  1242. lstrlen(FontName), NULL);
  1243. }
  1244. if( !(lpDIS->itemState & ODS_SELECTED) &&
  1245. ( lpDIS->itemAction & ODA_SELECT)){
  1246. CBrush fBrush;
  1247. fBrush.CreateSolidBrush(GetSysColor(COLOR_WINDOW)); // COLOR_WIN);
  1248. pDC->FillRect( &lpDIS->rcItem, &fBrush);
  1249. fBrush.DeleteObject();
  1250. //lpAssociationRegTmp = lpAssociationReg + lpDIS->itemID;
  1251. lpAssociationRegTmp = lpAssociationReg + lpDIS->itemData;
  1252. pDC->SetBkColor(GetSysColor(COLOR_WINDOW)); // COLOR_WIN);
  1253. if( CheckFlg == DBCSCHK)
  1254. pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); // COLOR_BLACK);
  1255. else pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); // COLOR_SHADOW);
  1256. GetFont()->GetObject( sizeof(LOGFONT), &LogFont);
  1257. if( abs( LogFont.lfHeight) < ItemHeight)
  1258. Offset = ( ItemHeight - abs( LogFont.lfHeight)) /2;
  1259. else Offset = 0;
  1260. if( lpAssociationRegTmp->FontTypeFlg){
  1261. pDC->DrawIcon( lpDIS->rcItem.left + LSPACE,
  1262. lpDIS->rcItem.top + Offset, tIcon);
  1263. }
  1264. //*STRSAFE* lstrcpy( FileTmp,lpAssociationRegTmp->szFileTitle);
  1265. hresult = StringCchCopy(FileTmp , ARRAYLEN(FileTmp), lpAssociationRegTmp->szFileTitle);
  1266. if (!SUCCEEDED(hresult))
  1267. {
  1268. return ;
  1269. }
  1270. GetStringRes( NotSel, IDS_NOTSELECT_STR, ARRAYLEN(NotSel));
  1271. if( FileTmp[0] == '\0' ||
  1272. !lstrcmp(FileTmp,NotSel)){
  1273. }else{
  1274. TCHAR *FilePtr;
  1275. if(( FilePtr = Mytcsrchr( FileTmp, '.')) != NULL)
  1276. *FilePtr = '\0';
  1277. if( lstrlen(FileTmp) > 20){
  1278. FileTmp[20] = '\0';
  1279. //*STRSAFE* lstrcat(FileTmp, TEXT(".."));
  1280. hresult = StringCchCat(FileTmp , ARRAYLEN(FileTmp), TEXT(".."));
  1281. if (!SUCCEEDED(hresult))
  1282. {
  1283. return ;
  1284. }
  1285. }
  1286. }
  1287. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1288. FileTmp,
  1289. lstrlen(FileTmp), &CharSize);
  1290. pDC->ExtTextOut( lpDIS->rcItem.right - CharSize.cx - RSPACE,
  1291. lpDIS->rcItem.top + Offset, 0, 0,
  1292. FileTmp,
  1293. lstrlen(FileTmp), NULL);
  1294. int FontWidth;
  1295. //*STRSAFE* lstrcpy(FontName, lpAssociationRegTmp->szFaceName);
  1296. hresult = StringCchCopy(FontName , ARRAYLEN(FontName), lpAssociationRegTmp->szFaceName);
  1297. if (!SUCCEEDED(hresult))
  1298. {
  1299. return ;
  1300. }
  1301. FontWidth = lpDIS->rcItem.right - lpDIS->rcItem.left
  1302. - LCSPACE - RSPACE - CharSize.cx;
  1303. GetTextExtentPoint32( pDC->GetSafeHdc(),
  1304. FontName,
  1305. lstrlen(FontName), &FontSize);
  1306. if( FontWidth <= FontSize.cx){
  1307. int i;
  1308. GetTextExtentPoint32( pDC->GetSafeHdc(),TEXT("<<"),2, &cSize);
  1309. i = ( FontWidth /cSize.cx) * 2;
  1310. FontName[i-2] = '.';
  1311. FontName[i-1] = '.';
  1312. FontName[i] = '\0';
  1313. }
  1314. pDC->ExtTextOut( lpDIS->rcItem.left + LCSPACE,
  1315. lpDIS->rcItem.top + Offset, 0, 0,
  1316. FontName,
  1317. lstrlen(FontName), NULL);
  1318. }
  1319. }
  1320. int CRegistListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
  1321. {
  1322. TCHAR TmpFontName1[LF_FACESIZE], TmpFontName2[LF_FACESIZE];
  1323. LPASSOCIATIONREG lpAssociationRegTmp1,lpAssociationRegTmp2;
  1324. HRESULT hresult;
  1325. if (!lpCIS)
  1326. {
  1327. return -1;
  1328. }
  1329. lpAssociationRegTmp1 = lpAssociationReg + lpCIS->itemData1;
  1330. lpAssociationRegTmp2 = (LPASSOCIATIONREG) (lpCIS->itemData2);
  1331. //*STRSAFE* lstrcpy(TmpFontName1, lpAssociationRegTmp1->szFaceName);
  1332. hresult = StringCchCopy(TmpFontName1 , ARRAYLEN(TmpFontName1), lpAssociationRegTmp1->szFaceName);
  1333. if (!SUCCEEDED(hresult))
  1334. {
  1335. return -1;
  1336. }
  1337. //*STRSAFE* lstrcpy(TmpFontName2, lpAssociationRegTmp2->szFaceName);
  1338. hresult = StringCchCopy(TmpFontName2 , ARRAYLEN(TmpFontName2), lpAssociationRegTmp2->szFaceName);
  1339. if (!SUCCEEDED(hresult))
  1340. {
  1341. return -1;
  1342. }
  1343. return (lstrcmp(TmpFontName1, TmpFontName2));
  1344. }
  1345. BOOL CAssocDlg::HandleImportWin95(
  1346. LPTSTR TTFPath,
  1347. LPTSTR BMPPath,
  1348. int Idx)
  1349. {
  1350. TCHAR UserFont[MAX_PATH];
  1351. LPTSTR FilePtr;
  1352. TCHAR szTmpDir[MAX_PATH];
  1353. HRESULT hresult;
  1354. if ( (!TTFPath) || (!BMPPath))
  1355. {
  1356. return FALSE;
  1357. }
  1358. GetTempPath(MAX_PATH, szTmpDir);
  1359. if (!GetTempFileName(szTmpDir, TEXT("EUF"), 0, UserFont))
  1360. {
  1361. //*STRSAFE* lstrcpy(UserFont, BMPPath);
  1362. hresult = StringCchCopy(UserFont , ARRAYLEN(UserFont), BMPPath);
  1363. if (!SUCCEEDED(hresult))
  1364. {
  1365. return FALSE;
  1366. }
  1367. if(( FilePtr = Mytcsrchr( UserFont, '\\')) != NULL)
  1368. *FilePtr = '\0';
  1369. //*STRSAFE* lstrcpy(UserFont, TEXT("EUF.tmp"));
  1370. hresult = StringCchCopy(UserFont , ARRAYLEN(UserFont), TEXT("EUF.tmp"));
  1371. if (!SUCCEEDED(hresult))
  1372. {
  1373. return FALSE;
  1374. }
  1375. }
  1376. if (!MoveFileEx(BMPPath, UserFont, MOVEFILE_REPLACE_EXISTING))
  1377. {
  1378. return FALSE;
  1379. }
  1380. CGageDlg dlg(this, UserFont, BMPPath, TTFPath, TRUE);
  1381. dlg.DoModal();
  1382. return TRUE;
  1383. }