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

📄 chnconv_exe.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// chnconv_exe.cpp : 拞崙岅僐儞僶乕僞偺僂傿儞僪僂僀儞僞乕僼僃僀僗

#include <windows.h>
#include <stdio.h>
#include <ctype.h>
#include "msc.h"

#include "access.h"
#include "brsfile.h"
#include "cjkctype.h"
#include "codepage.h"
#include "filename.h"
#include "guifont.h"
#include "mkdir.h"
#include "mui.h"
#include "mvwnd.h"
#include "nls.h"
#include "res.h"
#include "resource.h"
#include "sendmsg.h"
#include "shfileop.h"
#include "shfolder.h"
#include "shortcut.h"
#include "stringex.h"
#include "thread.h"
#include "tmpfile.h"
#include "winmain.h"

#include "chnconv.h"
#include "chnconv_opt.h"
#include "chnconv_cp.h"

#include "conv_err.h"
#include "conv_opt.h"
#include "conv_loaddll.h"
#include "conv_icon.h"
#include "conv_opt_gaiji.h"


// for debug
#define DEBUG_TAB_CONTROL  0     // 僞僽僐儞僩儘乕儖傪専嵏
#define DEBUG_DRAW_ICON    0     // 忬嫷昞帵傾僀僐儞偺僒僀僘傪専嵏
#define DEBUG_SEMAPHORE    0     // 曄姺拞偺僟僀傾儘僌昤夋傪専嵏


// Icon
// Bookman Old Styel italic bold 'CC'
// 32-bit -> font size 13
// 48-bit -> font size 22


static int nVersion ;
static int nOsCodePage ;         // OS偺僐乕僪儁乕僕

static char szCommandNameA [ SHORTSTRING_MAX ] ;
static wchar_t szCommandNameW [ SHORTSTRING_MAX ] ;
static const char szTempFileHeaderA [] = "chn" ;
static const wchar_t szTempFileHeaderW [] = L"chn" ;


// 儘乕僇儖娭悢
INT_PTR CALLBACK MainDialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;


// for XP Style
static HINSTANCE hUxTheme ;
typedef HRESULT ( WINAPI *ENABLETHEMEDIALOGTEXTURE ) ( HWND hwnd, DWORD dwFlags ) ;
static ENABLETHEMEDIALOGTEXTURE EnableThemeDialogTexture ;
#define ETDT_ENABLETAB 0x06




int main ( int argc, char *argv [] ) {


   int nError = 0 ;     // 堷偒悢僄儔乕
   int nMuiLangIdSpecified = 0 ;


   if ( DEBUG_TAB_CONTROL || DEBUG_DRAW_ICON || DEBUG_SEMAPHORE ) {
      MessageBoxA ( NULL, "Debug Version", "CHNCONV.EXE", MB_OK ) ;
   }


   // for XP Visual Style
   if ( IsWinXPorLater () ) {
      InitCommonControls () ;
      hUxTheme = LoadLibraryW ( L"UxTheme.dll" ) ;
      GETPROCADDRESS ( hUxTheme, ENABLETHEMEDIALOGTEXTURE, EnableThemeDialogTexture ) ;
   }

   // 僔僗僥儉忣曬傪庢摼
   nOsCodePage = GetACP () ;

   // OS偺僐乕僪儁乕僕傪庢摼
   nOsCodePage = GetACP () ;

   // 儕僜乕僗偺尵岅傪弶婜壔
   if ( IsNT () ) InitMuiLibraryW ( RT_DIALOG, IDD_DIALOG_MAIN, NULL, MUILANG_PREFIX_W ) ;
   else           InitMuiLibraryA ( RT_DIALOG, IDD_DIALOG_MAIN, NULL, MUILANG_PREFIX_A ) ;

   // 僶乕僕儑儞傪弶婜壔
   FILEVERSION FileVersion ;
   if ( ! GetFileVersion ( & FileVersion ) ) nVersion = TranslateVersionInfo ( & FileVersion ) ;


   // 堷偒悢偺庢摼
   for ( int nCountArgv = 1 ; nCountArgv < argc ; nCountArgv ++ ) {
      char *szArgv = argv [ nCountArgv ] ;
      if ( *szArgv == '/' || *szArgv == '-' ) {
         switch ( *( szArgv + 1 ) ) {
            case 'E' :
            case 'e' :
               nMuiLangIdSpecified = LANGID_ENGLISH ;
               break ;
            case 'J' :
            case 'j' :
               nMuiLangIdSpecified = LANGID_JAPANESE ;
               break ;
            case 'L' :
            case 'l' :
               if ( *( szArgv + 2 ) ) {
                  char *szString ;
                  errno = 0 ;
                  int nLangId = strtoul ( szArgv + 2, & szString, 0x10 ) ;
                  if ( errno || *szString ) { nError = nCountArgv ; break ; }
                  nMuiLangIdSpecified = nLangId ;
                  continue ;
               }
               nError = nCountArgv ;
               break ;
            case 'W' :
            case 'w' :
               IsIgnoreSaveWindow = 1 ;
               break ;
            case '@' :
               if ( *( szArgv + 2 ) ) {
                  szConfigFileNameA = GetArgumentA ( nCountArgv ) + 2 ;
                  szConfigFileNameW = GetArgumentW ( nCountArgv ) + 2 ;
                  continue ;
               }
               break ;
            default :
               nError = nCountArgv ;
               break ;
         }
         if ( *( szArgv + 2 ) ) nError = nCountArgv ;
         continue ;
      }
      nError = nCountArgv ;
   }


   // 昞帵尵岅偺愝掕乮僐儅儞僪儔僀儞偐傜偺巜掕乯
   if ( nMuiLangIdSpecified ) LoadMuiLibrary ( nMuiLangIdSpecified ) ;
   // 暥帤楍傪弶婜壔
   LoadStringExA ( IDS_COMMANDNAME, szCommandNameA, SHORTSTRING_MAX ) ;
   if ( IsNT () ) LoadStringExW ( IDS_COMMANDNAME, szCommandNameW, SHORTSTRING_MAX ) ;


   // 僄儔乕昞帵
   if ( nError ) {
      if ( IsNT () ) MessageBoxFormatW ( NULL, szCommandNameW, MB_OK, L"%s%s\n", GetStringW ( IDS_PARAM_ERROR ), GetArgumentW ( nError ) ) ;
      else           MessageBoxFormatA ( NULL, szCommandNameA, MB_OK,  "%s%s\n", GetStringA ( IDS_PARAM_ERROR ), GetArgumentA ( nError ) ) ;
      return 1 ;
   }


   // 僼僅儞僩柤傪弶婜壔
   if ( nOsCodePage == CP_CHINESE_SIMPLIFIED ) {
      szDefaultGbFont = DEFAULT_GB_FONT_L ;
      szDefaultGbGothicFont = DEFAULT_GB_GOTHIC_FONT_L ;
   }
   if ( nOsCodePage == CP_CHINESE_TRADITIONAL ) {
      szDefaultBig5Font = DEFAULT_BIG5_FONT_L ;
      szDefaultBig5GothicFont = DEFAULT_BIG5_GOTHIC_FONT_L ;
   }


   // 僼僅儞僩柤偺弶婜抣傪愝掕
   strcpy ( szGbFont, szDefaultGbFont ) ;
   strcpy ( szGbGothicFont, szDefaultGbGothicFont ) ;
   strcpy ( szBig5Font, szDefaultBig5Font ) ;
   strcpy ( szBig5GothicFont, szDefaultBig5GothicFont ) ;
   strcpy ( szPinyinFont, szDefaultPinyinFont ) ;
   strcpy ( szPinyinGothicFont, szDefaultPinyinGothicFont ) ;


   // 僆僾僔儑儞傪庢摼
   int IsConfigFileNotFound = ReadOption () ;
   if ( IsConfigFileNotFound < 0 ) {
      if ( IsNT () ) MessageBoxW ( NULL, GetStringW ( IDS_NOT_ENOUGH_MEMORY ), szCommandNameW, MB_OK ) ;
      else           MessageBoxA ( NULL, GetStringA ( IDS_NOT_ENOUGH_MEMORY ), szCommandNameA, MB_OK ) ;
      return 1 ;
   }
   if ( IsConfigFileNotFound && ( szConfigFileNameA || szConfigFileNameW ) ) {
      if ( IsNT () ) MessageBoxFormatW ( NULL, szCommandNameW, MB_OK, L"%s\n\n%s\n", GetStringW ( IDS_CANNOT_READ_OPTION ), szConfigFileNameW ) ;
      else           MessageBoxFormatA ( NULL, szCommandNameA, MB_OK,  "%s\n\n%s\n", GetStringA ( IDS_CANNOT_READ_OPTION ), szConfigFileNameA ) ;
      return 1 ;
   }


   // 昞帵尵岅偺愝掕乮娐嫬僼傽僀儖偐傜偺巜掕乯
   if ( ! nMuiLangIdSpecified && nSavedMuiLangId ) {
      LoadMuiLibrary ( nSavedMuiLangId ) ;
      // 傕偆偄偪偳暥帤楍傪弶婜壔
      LoadStringExA ( IDS_COMMANDNAME, szCommandNameA, SHORTSTRING_MAX ) ;
      if ( IsNT () ) LoadStringExW ( IDS_COMMANDNAME, szCommandNameW, SHORTSTRING_MAX ) ;
   }


   // 弶婜僼僅儖僟傪庢摼
   if ( IsNT () ) {
      if ( ! *szBrowsePathW ) {
         if ( *szBrowsePathA ) {
            MultiByteToWideChar ( nOsCodePage, 0, szBrowsePathA, -1, szBrowsePathW, MAX_PATH ) ;
         }
         else {
            GetSpecialFolderPathW ( NULL, szBrowsePathW, CSIDL_PERSONAL, 0 ) ;
            if ( ! *szBrowsePathW ) wcscpy ( szBrowsePathW, L"C:\\" ) ;
         }
      }
   }
   else {
      if ( ! *szBrowsePathA ) {
         if ( *szBrowsePathW ) {
            WideCharToMultiByte ( nOsCodePage, 0, szBrowsePathW, -1, szBrowsePathA, MAX_PATH, NULL, NULL ) ;
         }
         else {
            GetSpecialFolderPathA ( NULL, szBrowsePathA, CSIDL_PERSONAL, 0 ) ;
            if ( ! *szBrowsePathA ) strcpy ( szBrowsePathA, "C:\\" ) ;
         }
      }
   }

   // 僟僀傾儘僌偺傾僀僥儉偺惍崌惈傪僠僃僢僋
   if ( ! IsDlgItemIdConformable () ) {
      if ( IsNT () ) MessageBoxW ( NULL, GetStringW ( IDS_UNKNOWN_ERROR ), szCommandNameW, MB_OK ) ;
      else           MessageBoxA ( NULL, GetStringA ( IDS_UNKNOWN_ERROR ), szCommandNameA, MB_OK ) ;
      return 0 ;
   }


   // 僟僀傾儘僌傪昞帵
   if ( IsNT () ) DialogBoxExW ( IDD_DIALOG_MAIN, NULL, MainDialogProc ) ;
   else           DialogBoxExA ( IDD_DIALOG_MAIN, NULL, MainDialogProc ) ;

   // 僆僾僔儑儞傪曐懚
   if ( IsOptionChanged || IsSavePath || IsSaveCode || IsSaveWindow || IsConfigFileNotFound ) WriteOption () ;

   return 0 ;
}



////////////////////////////////////////////
//            儊僀儞僟僀傾儘僌            //
////////////////////////////////////////////



int SetSemaphore ( int nValue ) ;
#define LockSemaphore()       SetSemaphore ( 1 )   // if success, return 0
#define UnlockSemaphore()     SetSemaphore ( 0 )
#define IsLockedSemaphore()   ( SetSemaphore ( -1 ) != 0 )


typedef struct {
   HWND           hWnd ;
   volatile int   *pIsAborted ;
} CONVERSIONTHREADINFO ;

int WINAPI ConversionThread ( void *pConversionThreadInfo ) ;


int SetOption ( HWND hWnd ) ;
int DisplayHelp ( HWND hWnd ) ;
int SetMainDialogTitle ( HWND hWnd, int nMode ) ;
int GetMainDialogPos ( HWND hWnd, int *pX, int *pY ) ;
int DisplayAvailableForm ( HWND hWnd, int nType, int nCode ) ;

int CallBrowseForFile ( HWND hWnd, int nFileNumber, int IsDestination ) ;
#define BrowseSrcFileName(hWnd,nFileNumber)  CallBrowseForFile(hWnd,nFileNumber,0)
#define BrowseDstFileName(hWnd,nFileNumber)  CallBrowseForFile(hWnd,nFileNumber,1)

static WNDPROC OldEditCtrlProc ;
LRESULT CALLBACK NewEditCtrlProcA ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;
LRESULT CALLBACK NewEditCtrlProcW ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;



// 儊僀儞僟僀傾儘僌
INT_PTR CALLBACK MainDialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) {

   static HFONT hFont ;
   static volatile int IsAborted ;
   int nId ;

   switch ( dwMessage ) {

      case WM_INITDIALOG :

         // 僂傿儞僪僂昞帵埵抲傪弶婜壔
         if ( IsSaveWindow && ! IsIgnoreSaveWindow ) {
            SetWindowPos ( hWnd, NULL, nSavedWindowX, nSavedWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER ) ;
            MoveWindowTitleIntoDesktop ( hWnd ) ;
         }
         else {
            MoveWindowToCenter ( hWnd ) ;
         }

         // 僞僀僩儖傪愝掕
         Wm_SetIcon ( hWnd, ICON_BIG, LoadIconEx ( IDI_ICON_2 ) ) ;  // ICON_BIG偱側偄偲 ALT+TAB 偱傾僀僐儞傪昞帵偱偒側偄
         SetMainDialogTitle ( hWnd, 0 ) ;

         // 惉岟儊僢僙乕僕偺弶婜壔
         for ( int nCount = 0 ; nCount < SRC_DST_FILE_NELEM ; nCount ++ ) SetStatusIcon ( hWnd, nCount, STATUS_ICON_READY ) ;

         if ( DEBUG_DRAW_ICON ) DisplayControlSize ( hWnd, IDC_STATIC_STATUS_MIN ) ;

         // 儔僕僆儃僞儞傪愝掕
         CheckDlgButton ( hWnd, nSrcType + IDC_CHECK_SRC_TYPE_MIN, BST_CHECKED ) ;
         CheckDlgButton ( hWnd, nDstType + IDC_CHECK_DST_TYPE_MIN, BST_CHECKED ) ;
         DisplayAvailableForm ( hWnd, nSrcType, nSrcCode ) ;

         // 僐儞儃儃僢僋僗偺愝掕
         Dlg_ComboBox_ResetContent ( hWnd, IDC_COMBO_SRC_CODE ) ;

⌨️ 快捷键说明

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