eudcedit.cpp
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 14k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /********************************************************/
  2. /*                             */
  3. /*                             */
  4. /* EUDC EDITOR     ( Windows 95)             */
  5. /*                             */
  6. /* * Japanese Version                     */
  7. /* * Korea    Version                     */
  8. /* * Chinese  Version                     */
  9. /*                             */
  10. /*                                                      */
  11. /* Copyright (c) 1997-1999 Microsoft Corporation.       */
  12. /********************************************************/
  13. #include  "stdafx.h"
  14. #include  <afxpriv.h>
  15. #include  "eudcedit.h"
  16. #include  "mainfrm.h"
  17. #include "registry.h"
  18. #include "util.h"
  19. #include  "assocdlg.h"
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char  BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24. BEGIN_MESSAGE_MAP(CEudcApp, CWinApp)
  25. //{{AFX_MSG_MAP(CEudcApp)
  26. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  27. //}}AFX_MSG_MAP
  28. ON_COMMAND(ID_CONTEXT_HELP, CWinApp::OnContextHelp)
  29. END_MESSAGE_MAP()
  30. /* Global parameter */
  31. INT CAPTION_HEIGHT; // height of caption
  32. INT BITMAP_WIDTH; // width of bitmap
  33. INT BITMAP_HEIGHT; // height of bitmap
  34. TCHAR HelpPath[MAX_PATH]; // help file path
  35. TCHAR ChmHelpPath[MAX_PATH]; // help file path for HtmlHelp
  36. TCHAR FontPath[MAX_PATH]; // font file path
  37. DWORD COLOR_GRID; // grid color
  38. DWORD COLOR_FITTING; // bitmap color on show outline
  39. DWORD COLOR_CURVE; // color of outline
  40. DWORD COLOR_FACE; // Win95 3D Face SystemColor
  41. DWORD COLOR_HLIGHT; // Win95 3D HighLight System Color
  42. DWORD COLOR_SHADOW; // Win95 3D Shadow SystemColor
  43. DWORD COLOR_WIN; // Win95 Window System Color
  44. CString NotMemTtl;
  45. CString NotMemMsg;
  46. HCURSOR ToolCursor[NUMTOOL]; // cursor for tool
  47. HCURSOR ArrowCursor[NUMRESIZE]; // cursor for resize
  48. COUNTRYINFO CountryInfo; // country information structure
  49. /* Global function */
  50. extern BOOL  SetCountryInfo( UINT LocalCP);
  51. BOOL     g_bKeepEUDCLink = TRUE;
  52. extern "C" BOOL AnyLinkedFonts();
  53. CEudcApp NEAR theApp;
  54. /************************************************/
  55. /* */
  56. /* Default Constructor */
  57. /* */
  58. /************************************************/
  59. CEudcApp::CEudcApp()
  60. {
  61. }
  62. /************************************************/
  63. /* */
  64. /* Initialize Instance */
  65. /* */
  66. /************************************************/
  67. BOOL
  68. CEudcApp::InitInstance()
  69. {
  70. CString MainWndTitle;
  71. CRect MainWndRect;
  72. UINT MaxWndFlag;
  73. // Check whether EUDC editor can open or not
  74. if( !CheckPrevInstance())
  75. return FALSE;
  76. /*------------------------------------------------
  77.  * check if it's Administrator
  78.  *------------------------------------------------*/
  79.   TCHAR winpath[MAX_PATH];
  80.   HANDLE nfh;
  81.   GetSystemWindowsDirectory( winpath, MAX_PATH);
  82. #ifdef IN_FONTS_DIR // CAssocDlg::OnOK()
  83. lstrcat( winpath, TEXT("\FONTS\"));
  84. #else
  85. lstrcat( winpath, TEXT("\"));
  86. #endif // IN_FONTS_DIR
  87.   lstrcat(winpath, _T("eudcadm.tte"));
  88. nfh = CreateFile(winpath,
  89. GENERIC_WRITE,
  90. FILE_SHARE_DELETE,
  91. NULL,
  92. CREATE_ALWAYS,
  93. FILE_ATTRIBUTE_NORMAL,
  94. NULL);
  95. if ( nfh  == INVALID_HANDLE_VALUE)
  96.   {
  97.     HINSTANCE hInst = AfxGetInstanceHandle();
  98.     TCHAR szMessage[256];
  99.     LoadString(hInst, IDS_ACCESSDENIED, szMessage, sizeof(szMessage) / sizeof(TCHAR));
  100.     AfxMessageBox(szMessage, MB_OK, 0);
  101. return FALSE;
  102.   }
  103. else
  104.   {
  105.     CloseHandle(nfh);
  106.     DeleteFile(winpath);
  107.   }
  108. // Set background color for dialog
  109. COLOR_FACE   = ::GetSysColor( COLOR_3DFACE);
  110. COLOR_HLIGHT = ::GetSysColor( COLOR_3DHILIGHT);
  111. COLOR_SHADOW = ::GetSysColor( COLOR_3DSHADOW);
  112. COLOR_WIN    = ::GetSysColor( COLOR_WINDOW);
  113. // SetDialogBkColor( COLOR_FACE);
  114. // Set 3d controls
  115. Enable3dControls();
  116. // Create registry subkey
  117. if( !CreateRegistrySubkey())
  118. return FALSE;
  119. // Open "EUDCEDIT.INI", read data
  120. if( !GetProfileText( &MainWndRect, &MaxWndFlag))
  121. return FALSE;
  122. // Get Language ID with GetSystemDefaultLCID()
  123. //      Get area of EUDC from registry and WideCharToMultiByte().
  124. if( !GetCountryInfo())
  125. return FALSE;
  126. #if WINVER >= 0x0500
  127. // Remember original font link status before we do anything
  128. //pliu  g_bKeepEUDCLink = AnyLinkedFonts();
  129. #endif
  130. //      Get Cursor from resource
  131. if( !GetCursorRes())
  132. return FALSE;
  133. //      Get font and help file path
  134. if( !GetFilePath())
  135. return FALSE;
  136. // Create MDI mainFrame window
  137. MainWndTitle.LoadString( IDS_MAINFRAMETITLE);
  138. CMainFrame* pMainFrame = new CMainFrame;
  139. if (!pMainFrame->Create( MainWndTitle,
  140.     WS_OVERLAPPEDWINDOW , MainWndRect,
  141.     MAKEINTRESOURCE( IDR_MAINFRAME))){
  142. return FALSE;
  143. }
  144. pMainFrame->ShowWindow( m_nCmdShow);
  145. if( MaxWndFlag){
  146. pMainFrame->ShowWindow( SW_SHOWMAXIMIZED);
  147. }
  148. pMainFrame->UpdateWindow();
  149. m_pMainWnd = pMainFrame;
  150. CAssocDlg dlg(m_pMainWnd);
  151. if (!dlg.InitSystemFontAssoc())
  152. {
  153. return FALSE;
  154. }
  155. pMainFrame->m_wndGuideBar.PositionStatusPane();
  156. pMainFrame->SendMessage(WM_COMMAND, ID_READ_CHAR, NULL);
  157. return TRUE;
  158. }
  159. BOOL
  160. CEudcApp::ExitInstance()
  161. {
  162.     EnableEUDC(FALSE);
  163.     if (!g_bKeepEUDCLink && CountryInfo.bOnlyUnicode)
  164.     {
  165.         TCHAR szDefaultFace[LF_FACESIZE];
  166.         TCHAR szFontPath[MAX_PATH];
  167.         TCHAR *Ptr;
  168.         GetStringRes(szDefaultFace, IDS_SYSTEMEUDCFONT_STR);
  169.         if (InqTypeFace(szDefaultFace, szFontPath,MAX_PATH))
  170.         {
  171.             //
  172.             // delete file eudc.tte
  173.             //
  174.             DeleteFile(szFontPath);
  175.             if(( Ptr = Mytcsrchr( szFontPath, '.')) != NULL)
  176.             {
  177.                 *Ptr = '';
  178.                 lstrcat( szFontPath, TEXT(".EUF"));
  179.                 //
  180.                 // delete file eudc.euf
  181.                 //
  182.                 DeleteFile(szFontPath);
  183.             }
  184.         }
  185.         DeleteRegistrySubkey();
  186.     }
  187.     EnableEUDC(TRUE);
  188.     return CWinApp::ExitInstance();
  189. }
  190. /************************************************/
  191. /* */
  192. /* Check whether editor can open or not */
  193. /* */
  194. /************************************************/
  195. BOOL
  196. CEudcApp::CheckPrevInstance()
  197. {
  198. HWND hWnd;
  199. TCHAR TitleBuf[50];
  200. GetStringRes(TitleBuf, IDS_MAINFRAMETITLE);
  201. // Search previous eudcedit mainframe.
  202. hWnd = ::FindWindow( NULL, TitleBuf);
  203. if( hWnd == NULL)
  204. return TRUE;
  205. else  ::SetForegroundWindow( hWnd);
  206. return FALSE;
  207. }
  208. /************************************************/
  209. /* */
  210. /* Correspond to waitting for Input */
  211. /* */
  212. /************************************************/
  213. BOOL
  214. CEudcApp::OnIdle(
  215. LONG  lCount)
  216. {
  217. CWnd *pWnd;
  218. if( !lCount){
  219. for( pWnd = m_pMainWnd->GetWindow( GW_HWNDFIRST); pWnd != NULL;
  220.      pWnd = pWnd->GetNextWindow( GW_HWNDNEXT)){
  221. if( m_pMainWnd == pWnd->GetParent()){
  222. if( pWnd == m_pMainWnd->GetActiveWindow() &&
  223.   ( ::GetCapture() == NULL))
  224. m_pMainWnd->SetActiveWindow();
  225. pWnd->SendMessage( WM_IDLEUPDATECMDUI,
  226.  (WPARAM)TRUE, 0L);
  227. }
  228. }
  229. }
  230. return CWinApp::OnIdle( lCount);
  231. }
  232. /************************************************/
  233. /* */
  234. /*   Open "EUDCEDIT.INI" */
  235. /*   Set parameter of EUDC Editor */
  236. /* */
  237. /************************************************/
  238. BOOL
  239. CEudcApp::GetProfileText(
  240. LPRECT  MainWndRect,
  241. UINT  *MaxWndFlag)
  242. {
  243. TCHAR ProfileBuf[MAX_PATH], *pString;
  244. TCHAR Separation[] = TEXT(" ,");
  245. INT xScreen , yScreen;
  246. UINT BitmapSiz;
  247. BYTE Rcolor, Gcolor, Bcolor;
  248. CString GridColor, CurvColor, FittColor, MainWnd;
  249. // Get system metrics
  250. CAPTION_HEIGHT = ::GetSystemMetrics( SM_CYCAPTION);
  251. xScreen = ::GetSystemMetrics( SM_CXSCREEN);
  252. yScreen = ::GetSystemMetrics( SM_CYSCREEN);
  253. // Read bitmapsize and maxflag
  254. BitmapSiz = this->GetProfileInt(TEXT("Bitmap"), TEXT("BitmapSize"), DEF_BITMAPSIZE);
  255. if( BitmapSiz <= 0)
  256. BitmapSiz = DEF_BITMAPSIZE;
  257. if( BitmapSiz > MAX_BITMAPSIZE)
  258. BitmapSiz = DEF_BITMAPSIZE;
  259. BitmapSiz = ((BitmapSiz + sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
  260. if( BitmapSiz > MAX_BITMAPSIZE)
  261. BitmapSiz = MAX_BITMAPSIZE;
  262. if( BitmapSiz < MIN_BITMAPSIZE)
  263. BitmapSiz = MIN_BITMAPSIZE;
  264. BITMAP_WIDTH  = BitmapSiz;
  265. BITMAP_HEIGHT = BitmapSiz;
  266. *MaxWndFlag = this->GetProfileInt(TEXT("WindowSize"), TEXT("MinMaxFlag"), 0);
  267. // Read color
  268. GridColor = this->GetProfileString(TEXT("Color"), TEXT("Grid"), TEXT("128 128 128"));
  269. CurvColor = this->GetProfileString(TEXT("Color"), TEXT("Curve"), TEXT("255 0 0"));
  270. FittColor = this->GetProfileString(TEXT("Color"), TEXT("Fitting"), TEXT("128 128 128"));
  271. // Read grid color
  272. ConvStringRes((TCHAR *)ProfileBuf, GridColor);
  273. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  274. Rcolor = 0;
  275. else Rcolor = (BYTE)Myttoi( pString);
  276. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  277. Gcolor = 0;
  278. else Gcolor = (BYTE)Myttoi( pString);
  279. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  280. Bcolor = 0;
  281. else Bcolor = (BYTE)Myttoi( pString);
  282. COLOR_GRID = RGB( Rcolor, Gcolor, Bcolor);
  283. // Read outline color
  284. ConvStringRes(ProfileBuf, CurvColor);
  285. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  286. Rcolor = 0;
  287. else Rcolor = (BYTE)Myttoi( pString);
  288. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  289. Gcolor = 0;
  290. else Gcolor = (BYTE)Myttoi( pString);
  291. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  292. Bcolor = 0;
  293. else Bcolor = (BYTE)Myttoi( pString);
  294. COLOR_CURVE = RGB( Rcolor, Gcolor, Bcolor);
  295. // Read bitmap color in show outline
  296. ConvStringRes(ProfileBuf, FittColor);
  297. if(( pString = Mytcstok( ProfileBuf, Separation)) == NULL)
  298. Rcolor = 0;
  299. else Rcolor = (BYTE)Myttoi( pString);
  300. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  301. Gcolor = 0;
  302. else Gcolor = (BYTE)Myttoi( pString);
  303. if(( pString = Mytcstok( NULL, Separation)) == NULL)
  304. Bcolor = 0;
  305. else Bcolor = (BYTE)Myttoi( pString);
  306. COLOR_FITTING = RGB( Rcolor, Gcolor, Bcolor);
  307. // Read main window size
  308. MainWnd = this->GetProfileString(TEXT("WindowSize"),TEXT("MainWindowSize"), TEXT(""));
  309. if( *MainWnd == ''){
  310. MainWndRect->left = 0;
  311. MainWndRect->top  = 0;
  312. MainWndRect->right = (xScreen/5)*4;
  313. MainWndRect->bottom =(yScreen/5)*4;
  314. }else{
  315. ConvStringRes(ProfileBuf, MainWnd);
  316. pString = Mytcstok( ProfileBuf, Separation);
  317. MainWndRect->left = Myttoi( pString);
  318. pString = Mytcstok( NULL, Separation);
  319. MainWndRect->top = Myttoi( pString);
  320. pString = Mytcstok( NULL, Separation);
  321. MainWndRect->right = Myttoi( pString);
  322. pString = Mytcstok( NULL, Separation);
  323. MainWndRect->bottom = Myttoi( pString);
  324. }
  325. return TRUE;
  326. }
  327. /************************************************/
  328. /* */
  329. /* Get country information */
  330. /* */
  331. /************************************************/
  332. BOOL
  333. CEudcApp::GetCountryInfo()
  334. {
  335. UINT LocalCP;
  336. CountryInfo.CurrentRange = 0;
  337. CountryInfo.LangID = (int)GetSystemDefaultLCID();
  338. LocalCP = GetACP();
  339.     CountryInfo.bUnicodeMode = FALSE;
  340. CountryInfo.bOnlyUnicode = FALSE;
  341. switch( CountryInfo.LangID){
  342. case EUDC_JPN:
  343. CountryInfo.CharacterSet = SHIFTJIS_CHARSET;
  344. break;
  345.     case EUDC_HKG:
  346.         CountryInfo.LangID = EUDC_CHT;
  347.         //
  348.         // fall through
  349.         //
  350. case EUDC_CHT:
  351. CountryInfo.CharacterSet = CHINESEBIG5_CHARSET;
  352. break;
  353. case EUDC_KRW:
  354. CountryInfo.CharacterSet = HANGEUL_CHARSET;
  355. break;
  356.     case EUDC_SIN:
  357.         CountryInfo.LangID = EUDC_CHS;
  358.         //
  359.         // Fall through
  360.         //
  361. case EUDC_CHS:
  362. CountryInfo.CharacterSet = GB2312_CHARSET;
  363. break;
  364. default:
  365.     CHARSETINFO csi;
  366.     if (TranslateCharsetInfo((DWORD*)LocalCP, &csi, TCI_SRCCODEPAGE))
  367.        CountryInfo.CharacterSet = csi.ciCharset;
  368. CountryInfo.bOnlyUnicode = TRUE;
  369.     CountryInfo.bUnicodeMode = TRUE;
  370.     lstrcpy(CountryInfo.szForceFont, _T("Microsoft Sans Serif"));
  371. break;
  372. }
  373. if( !SetCountryInfo( LocalCP))
  374. return FALSE;
  375. else  return TRUE;
  376. }
  377. /************************************************/
  378. /* */
  379. /* Get Cursor resource file */
  380. /* */
  381. /************************************************/
  382. BOOL
  383. CEudcApp::GetCursorRes()
  384. {
  385. int i;
  386. // For tool cursor
  387. ToolCursor[PEN]        = this->LoadCursor(IDC_PENCIL);
  388. ToolCursor[BRUSH]      = this->LoadCursor(IDC_BRUSH);
  389. ToolCursor[CIRCLE]     = this->LoadStandardCursor(IDC_CROSS);
  390. ToolCursor[CIRCLEFILL] = this->LoadStandardCursor(IDC_CROSS);
  391. ToolCursor[SLOPE]      = this->LoadStandardCursor(IDC_CROSS);
  392. ToolCursor[RECTBAND]   = this->LoadStandardCursor(IDC_CROSS);
  393. ToolCursor[RECTFILL]   = this->LoadStandardCursor(IDC_CROSS);
  394. ToolCursor[FREEFORM]   = this->LoadStandardCursor(IDC_CROSS);
  395. ToolCursor[RECTCLIP]   = this->LoadStandardCursor(IDC_CROSS);
  396. ToolCursor[ERASER]     = this->LoadCursor(IDC_ERASER);
  397. for( i = PEN; i <= ERASER; i++){
  398. if( ToolCursor[i] == NULL){
  399. return FALSE;
  400. }
  401. }
  402. // For select rectangle cursur
  403. ArrowCursor[VERTICAL]  = this->LoadStandardCursor(
  404.  MAKEINTRESOURCE(IDC_SIZEWE));
  405. ArrowCursor[RIGHTSLOPE]= this->LoadStandardCursor(
  406.  MAKEINTRESOURCE(IDC_SIZENESW));
  407. ArrowCursor[LEFTSLOPE] = this->LoadStandardCursor(
  408.  MAKEINTRESOURCE(IDC_SIZENWSE));
  409. ArrowCursor[HORIZONTAL]= this->LoadStandardCursor(
  410.  MAKEINTRESOURCE(IDC_SIZENS));
  411. ArrowCursor[ALLDIRECT] = this->LoadStandardCursor(
  412.  MAKEINTRESOURCE(IDC_SIZEALL));
  413. for( i = VERTICAL; i <= ALLDIRECT; i++){
  414. if( ArrowCursor[i] == NULL){
  415. return FALSE;
  416. }
  417. }
  418. return TRUE;
  419. }
  420. /************************************************/
  421. /* */
  422. /* Get help file path */
  423. /* */
  424. /************************************************/
  425. BOOL
  426. CEudcApp::GetFilePath()
  427. {
  428. if( !GetSystemWindowsDirectory( FontPath, MAX_PATH))
  429. return FALSE;
  430. lstrcat(FontPath, TEXT("\"));
  431. lstrcpy(HelpPath, TEXT("EUDCEDIT.HLP"));
  432.     lstrcpy(ChmHelpPath, TEXT("EUDCEDIT.CHM"));
  433. NotMemTtl.LoadString( IDS_MAINFRAMETITLE);
  434. NotMemMsg.LoadString( IDS_NOTENOUGHMEMORY_ERROR);
  435. return TRUE;
  436. }
  437. /************************************************/
  438. /* */
  439. /* COMMAND  "About" */
  440. /* */
  441. /************************************************/
  442. void
  443. CEudcApp::OnAppAbout()
  444. {
  445. HICON hIcon;
  446. TCHAR TitleBuf[50];
  447. hIcon = LoadIcon( IDR_MAINFRAME);
  448. GetStringRes((TCHAR *)TitleBuf, IDS_MAINFRAMETITLE);
  449. ShellAbout( m_pMainWnd->GetSafeHwnd(), TitleBuf, TEXT(""), hIcon);
  450. }