From c8dd3e6d707be787af7ec429c661d64f1d962c2d Mon Sep 17 00:00:00 2001 From: David-FromVS Date: Sat, 19 Sep 2020 23:44:08 +0100 Subject: [PATCH] Add project files. --- StdAfx.cpp | 8 + StdAfx.h | 26 +++ UTF8Conv.cpp | 77 +++++++ UTF8Conv.h | 49 ++++ UTF8Conv.rc | 254 +++++++++++++++++++++ UTF8Conv.sln | 20 ++ UTF8Conv.vcxproj | 243 ++++++++++++++++++++ UTF8Conv.vcxproj.filters | 60 +++++ UTF8ConvDlg.cpp | 468 +++++++++++++++++++++++++++++++++++++++ UTF8ConvDlg.h | 64 ++++++ res/UTF8Conv.ico | Bin 0 -> 1078 bytes res/UTF8Conv.rc2 | 13 ++ res/icon1.ico | Bin 0 -> 190 bytes resource.h | 28 +++ 14 files changed, 1310 insertions(+) create mode 100644 StdAfx.cpp create mode 100644 StdAfx.h create mode 100644 UTF8Conv.cpp create mode 100644 UTF8Conv.h create mode 100644 UTF8Conv.rc create mode 100644 UTF8Conv.sln create mode 100644 UTF8Conv.vcxproj create mode 100644 UTF8Conv.vcxproj.filters create mode 100644 UTF8ConvDlg.cpp create mode 100644 UTF8ConvDlg.h create mode 100644 res/UTF8Conv.ico create mode 100644 res/UTF8Conv.rc2 create mode 100644 res/icon1.ico create mode 100644 resource.h diff --git a/StdAfx.cpp b/StdAfx.cpp new file mode 100644 index 0000000..020a53c --- /dev/null +++ b/StdAfx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// UTF8Conv.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + + diff --git a/StdAfx.h b/StdAfx.h new file mode 100644 index 0000000..e86311c --- /dev/null +++ b/StdAfx.h @@ -0,0 +1,26 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#if !defined(AFX_STDAFX_H__738621FE_FCE3_4198_BC12_F3084DC75CAA__INCLUDED_) +#define AFX_STDAFX_H__738621FE_FCE3_4198_BC12_F3084DC75CAA__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers + +#include // MFC core and standard components +#include // MFC extensions +#include // MFC support for Internet Explorer 4 Common Controls +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__738621FE_FCE3_4198_BC12_F3084DC75CAA__INCLUDED_) diff --git a/UTF8Conv.cpp b/UTF8Conv.cpp new file mode 100644 index 0000000..5932e8f --- /dev/null +++ b/UTF8Conv.cpp @@ -0,0 +1,77 @@ +// UTF8Conv.cpp : Defines the class behaviors for the application. +// + +#include "stdafx.h" +#include +#include "UTF8Conv.h" +#include "UTF8ConvDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#if defined(_M_IA64) +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#if defined(_M_X64) +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvApp + +BEGIN_MESSAGE_MAP(CUTF8ConvApp, CWinApp) + //{{AFX_MSG_MAP(CUTF8ConvApp) + // NOTE - the ClassWizard will add and remove mapping macros here. + // DO NOT EDIT what you see in these blocks of generated code! + //}}AFX_MSG + ON_COMMAND(ID_HELP, CWinApp::OnHelp) +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvApp construction + +CUTF8ConvApp::CUTF8ConvApp() +{ + // TODO: add construction code here, + // Place all significant initialization in InitInstance +} + +///////////////////////////////////////////////////////////////////////////// +// The one and only CUTF8ConvApp object + +CUTF8ConvApp theApp; + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvApp initialization + +BOOL CUTF8ConvApp::InitInstance() +{ + const INITCOMMONCONTROLSEX iccex{ sizeof( iccex ), ICC_LINK_CLASS }; + + if ( InitCommonControlsEx( &iccex ) ) + { + CUTF8ConvDlg dlg; + m_pMainWnd = &dlg; + int nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: Place code here to handle when the dialog is + // dismissed with OK + } + else if (nResponse == IDCANCEL) + { + // TODO: Place code here to handle when the dialog is + // dismissed with Cancel + } + } + + // Since the dialog has been closed, return FALSE so that we exit the + // application, rather than start the application's message pump. + return FALSE; +} diff --git a/UTF8Conv.h b/UTF8Conv.h new file mode 100644 index 0000000..e6a7e9d --- /dev/null +++ b/UTF8Conv.h @@ -0,0 +1,49 @@ +// UTF8Conv.h : main header file for the UTF8CONV application +// + +#if !defined(AFX_UTF8CONV_H__BA5C5808_95EE_4F29_A50A_1F95705DFE32__INCLUDED_) +#define AFX_UTF8CONV_H__BA5C5808_95EE_4F29_A50A_1F95705DFE32__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#ifndef __AFXWIN_H__ + #error include 'stdafx.h' before including this file for PCH +#endif + +#include "resource.h" // main symbols + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvApp: +// See UTF8Conv.cpp for the implementation of this class +// + +class CUTF8ConvApp : public CWinApp +{ +public: + CUTF8ConvApp(); + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CUTF8ConvApp) + public: + virtual BOOL InitInstance(); + //}}AFX_VIRTUAL + +// Implementation + + //{{AFX_MSG(CUTF8ConvApp) + // NOTE - the ClassWizard will add and remove member functions here. + // DO NOT EDIT what you see in these blocks of generated code ! + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_UTF8CONV_H__BA5C5808_95EE_4F29_A50A_1F95705DFE32__INCLUDED_) diff --git a/UTF8Conv.rc b/UTF8Conv.rc new file mode 100644 index 0000000..54c4b46 --- /dev/null +++ b/UTF8Conv.rc @@ -0,0 +1,254 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_ABOUTBOX DIALOGEX 0, 0, 235, 44 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "About UTF8/7 Converter" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + ICON IDR_MAINFRAME,IDC_STATIC,7,10,20,20 + LTEXT "UTF8/7 Converter Version 2.1",IDC_STATIC,40,10,119,8,SS_NOPREFIX + DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP + CONTROL "Copyright © JD Design 2009-2020",IDC_SYSLINK1, + "SysLink",WS_TABSTOP,39,21,134,8 +END + +IDD_UTF8CONV_DIALOG DIALOGEX 0, 0, 349, 154 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_APPWINDOW +CAPTION "UTF8/7 <-> Unicode Viewer" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + COMBOBOX IDC_UTF_BASE,7,37,65,38,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Unicode (&Windows) string:",IDC_STATIC,7,55,182,8 + EDITTEXT IDC_UNICODE_TXT,7,66,275,14,ES_AUTOHSCROLL + LTEXT "&UTF-7/8 string:",IDC_STATIC,7,92,50,8 + EDITTEXT IDC_ANSI_TXT,7,103,335,14,ES_AUTOHSCROLL + LTEXT "UTF string as &hex:",IDC_STATIC,7,122,83,8 + EDITTEXT IDC_HEX_TXT,7,133,335,14,ES_AUTOHSCROLL + DEFPUSHBUTTON "To UTF",IDOK,188,87,50,14,NOT WS_VISIBLE | WS_GROUP + PUSHBUTTON "To Unicode",IDC_TOASCII,247,87,50,14,NOT WS_VISIBLE | WS_GROUP + PUSHBUTTON "Close",IDCANCEL,292,66,50,14,WS_GROUP + LTEXT "Enter text into the Unicode or UTF string fields to see the equivalent in the other fields.\nSimilarly, enter hex values for the UTF string to see the equivalent Unicode and UTF strings.",IDC_STATIC,7,7,335,16,SS_NOPREFIX + CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME,7,27,335,1,WS_EX_STATICEDGE + ICON IDI_CROSS,IDC_INVALID_HEX,105,124,20,20,SS_REALSIZEIMAGE | NOT WS_VISIBLE +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 2,1,0,0 + PRODUCTVERSION 2,1,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "JD Design" + VALUE "FileDescription", "UTF8/7 Conversion Application" + VALUE "FileVersion", "2.1.0.0" + VALUE "InternalName", "UTF8Conv" + VALUE "LegalCopyright", "Copyright (C) JD Design 2009-2020" + VALUE "OriginalFilename", "UTF8Conv.EXE" + VALUE "ProductName", "UTF8/7 Converter Application" + VALUE "ProductVersion", "2.1.0.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_ABOUTBOX, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 37 + END + + IDD_UTF8CONV_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 342 + TOPMARGIN, 7 + BOTTOMMARGIN, 147 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// AFX_DIALOG_LAYOUT +// + +IDD_UTF8CONV_DIALOG AFX_DIALOG_LAYOUT +BEGIN + 0 +END + +IDD_ABOUTBOX AFX_DIALOG_LAYOUT +BEGIN + 0 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog Info +// + +IDD_UTF8CONV_DIALOG DLGINIT +BEGIN + IDC_UTF_BASE, 0x403, 6, 0 +0x5455, 0x2d46, 0x0038, + IDC_UTF_BASE, 0x403, 6, 0 +0x5455, 0x2d46, 0x0037, + 0 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + IDS_ABOUTBOX "&About UTF8/7 Converter..." +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (United Kingdom) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "#define _AFX_NO_SPLITTER_RESOURCES\r\n" + "#define _AFX_NO_OLE_RESOURCES\r\n" + "#define _AFX_NO_TRACKER_RESOURCES\r\n" + "#define _AFX_NO_PROPERTY_RESOURCES\r\n" + "\r\n" + "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" + "#ifdef _WIN32\r\n" + "LANGUAGE 9, 1\r\n" + "#pragma code_page(1252)\r\n" + "#endif //_WIN32\r\n" + "#include ""res\\UTF8Conv.rc2"" // non-Microsoft Visual C++ edited resources\r\n" + "#include ""afxres.rc"" // Standard components\r\n" + "#endif\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDR_MAINFRAME ICON "res\\UTF8Conv.ico" + +IDI_CROSS ICON "res\\icon1.ico" + +#endif // English (United Kingdom) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// +#define _AFX_NO_SPLITTER_RESOURCES +#define _AFX_NO_OLE_RESOURCES +#define _AFX_NO_TRACKER_RESOURCES +#define _AFX_NO_PROPERTY_RESOURCES + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE 9, 1 +#pragma code_page(1252) +#endif //_WIN32 +#include "res\UTF8Conv.rc2" // non-Microsoft Visual C++ edited resources +#include "afxres.rc" // Standard components +#endif + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/UTF8Conv.sln b/UTF8Conv.sln new file mode 100644 index 0000000..c087a8a --- /dev/null +++ b/UTF8Conv.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UTF8Conv", "UTF8Conv.vcxproj", "{8F0567ED-6356-1012-1E29-8AACD50C05BF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8F0567ED-6356-1012-1E29-8AACD50C05BF}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F0567ED-6356-1012-1E29-8AACD50C05BF}.Debug|Win32.Build.0 = Debug|Win32 + {8F0567ED-6356-1012-1E29-8AACD50C05BF}.Release|Win32.ActiveCfg = Release|Win32 + {8F0567ED-6356-1012-1E29-8AACD50C05BF}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/UTF8Conv.vcxproj b/UTF8Conv.vcxproj new file mode 100644 index 0000000..4a0854f --- /dev/null +++ b/UTF8Conv.vcxproj @@ -0,0 +1,243 @@ + + + + + Debug + Win32 + + + Debug + Win32 + + + Release + Win32 + + + Release + Win32 + + + + + + MFCProj + {8F0567ED-6356-1012-1E29-8AACD50C05BF} + 10.0 + + + + Application + Static + Unicode + v142 + + + Application + Static + Unicode + v142 + + + + + + + + + + + + + + + false + + + true + + + + MultiThreaded + true + MinSpace + true + Level4 + NDEBUG;WIN32;_WINDOWS;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions) + + + + + Use + stdafx.h + + + + + false + true + stdcpp17 + + + true + NDEBUG;%(PreprocessorDefinitions) + .\Release/UTF8Conv.tlb + true + Win32 + + + 0x0809 + NDEBUG;%(PreprocessorDefinitions) + + + true + .\Release/UTF8Conv.bsc + + + true + Windows + %(AdditionalDependencies) + UseLinkTimeCodeGeneration + + + "$(WindowsSDK80Path)bin\x86\signtool.exe" sign /f "..\David's Code Signing Certificate.pfx" /p Swizz1eStix90125 /d UTF8Conv $(TargetPath) + + + Sign + + + + + MultiThreadedDebug + Disabled + true + Level4 + EditAndContinue + _DEBUG;WIN32;_WINDOWS;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions) + + + true + + + Use + stdafx.h + + + + + true + EnableFastChecks + stdcpp17 + + + true + _DEBUG;%(PreprocessorDefinitions) + .\Debug/UTF8Conv.tlb + true + Win32 + + + 0x0809 + _DEBUG;%(PreprocessorDefinitions) + + + true + .\Debug/UTF8Conv.bsc + + + true + true + Windows + %(AdditionalDependencies) + + + + + + + true + Level4 + NDEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Release/UTF8Conv.pch + Create + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + true + Level4 + _DEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Debug/UTF8Conv.pch + Create + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + + + true + Level4 + NDEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Release/UTF8Conv.pch + Use + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + true + Level4 + _DEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Debug/UTF8Conv.pch + Use + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + + + true + Level4 + NDEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Release/UTF8Conv.pch + Use + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + true + Level4 + _DEBUG;WIN32;_WINDOWS;_UNICODE;%(PreprocessorDefinitions) + .\Debug/UTF8Conv.pch + Use + stdafx.h + $(INTDIR)/ + $(INTDIR)/ + + + + + 0x0809 + NDEBUG;%(PreprocessorDefinitions) + 0x0809 + _DEBUG;%(PreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UTF8Conv.vcxproj.filters b/UTF8Conv.vcxproj.filters new file mode 100644 index 0000000..ed4718e --- /dev/null +++ b/UTF8Conv.vcxproj.filters @@ -0,0 +1,60 @@ + + + + + {5c8b92e7-9348-4e76-81c2-937a8dcedb9a} + h;hpp;hxx;hm;inl + + + {06fa8480-b8e5-4878-957f-cf6cdd6c112c} + ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe + + + {dfd92f30-1b2e-43f3-98cd-876c0fc5d4e0} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/UTF8ConvDlg.cpp b/UTF8ConvDlg.cpp new file mode 100644 index 0000000..c208088 --- /dev/null +++ b/UTF8ConvDlg.cpp @@ -0,0 +1,468 @@ +// UTF8ConvDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "UTF8Conv.h" +#include "UTF8ConvDlg.h" +#include +#include +using namespace std; + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CAboutDlg dialog used for App About + +class CAboutDlg : public CDialog +{ +public: + CAboutDlg(); + +// Dialog Data + //{{AFX_DATA(CAboutDlg) + enum { IDD = IDD_ABOUTBOX }; + //}}AFX_DATA + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CAboutDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + //{{AFX_MSG(CAboutDlg) + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult); +}; + +CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) +{ + //{{AFX_DATA_INIT(CAboutDlg) + //}}AFX_DATA_INIT +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CAboutDlg) + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) + //{{AFX_MSG_MAP(CAboutDlg) + // No message handlers + //}}AFX_MSG_MAP + ON_NOTIFY(NM_CLICK, IDC_SYSLINK1, &CAboutDlg::OnNMClickSyslink1) + ON_NOTIFY(NM_RETURN, IDC_SYSLINK1, &CAboutDlg::OnNMClickSyslink1) +END_MESSAGE_MAP() + +void CAboutDlg::OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult) +{ + PNMLINK pNMLink = reinterpret_cast( pNMHDR ); + if ( pNMLink->item.szUrl[0] != L'\0' ) + { + ShellExecute( m_hWnd, NULL, pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL ); + } + *pResult = 0; +} + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvDlg dialog + +CUTF8ConvDlg::CUTF8ConvDlg(CWnd* pParent /*=NULL*/) + : CDialog(CUTF8ConvDlg::IDD, pParent) + , m_CodePageItem( 0 ) +{ + //{{AFX_DATA_INIT(CUTF8ConvDlg) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT + // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + + m_bUpdatingANSI = false; + m_bUpdatingHex = false; + m_bUpdatingUnicode = false; +} + +void CUTF8ConvDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CUTF8ConvDlg) + // NOTE: the ClassWizard will add DDX and DDV calls here + //}}AFX_DATA_MAP + DDX_CBIndex( pDX, IDC_UTF_BASE, m_CodePageItem ); +} + +BEGIN_MESSAGE_MAP(CUTF8ConvDlg, CDialog) + //{{AFX_MSG_MAP(CUTF8ConvDlg) + ON_WM_SYSCOMMAND() + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDOK, OnConvert) + ON_BN_CLICKED(IDC_TOASCII, OnToascii) + //}}AFX_MSG_MAP + ON_EN_CHANGE(IDC_ANSI_TXT, &CUTF8ConvDlg::OnEnChangeUtf8AsAnsi) + ON_EN_CHANGE(IDC_UNICODE_TXT, &CUTF8ConvDlg::OnEnChangeUnicodeEntry) + ON_EN_CHANGE(IDC_HEX_TXT, &CUTF8ConvDlg::OnEnChangeHexTxt) + ON_CBN_SELCHANGE( IDC_UTF_BASE, &CUTF8ConvDlg::OnCbnSelchangeUtfBase ) +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvDlg message handlers + +BOOL CUTF8ConvDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + // Add "About..." menu item to system menu. + + // IDM_ABOUTBOX must be in the system command range. + ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); + ASSERT(IDM_ABOUTBOX < 0xF000); + + CMenu* pSysMenu = GetSystemMenu(FALSE); + if (pSysMenu != NULL) + { + CString strAboutMenu; + strAboutMenu.LoadString(IDS_ABOUTBOX); + if (!strAboutMenu.IsEmpty()) + { + pSysMenu->AppendMenu(MF_SEPARATOR); + pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); + } + } + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + SetIcon(m_hIcon, TRUE); // Set big icon + SetIcon(m_hIcon, FALSE); // Set small icon + + // TODO: Add extra initialization here +#ifdef _DEBUG + // https://en.wikipedia.org/wiki/UTF-7 + // https://www.utf8-chartable.de/ + // "1香港版 (Hong Kong) 2العالم العربي (Arabic)" + SetDlgItemText( IDC_UNICODE_TXT, L"£ - U+00A2, utf-8 0xc2 0xa3, uft-7 +AKM-" ); +#endif + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CUTF8ConvDlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialog::OnSysCommand(nID, lParam); + } +} + +// If you add a minimize button to your dialog, you will need the code below +// to draw the icon. For MFC applications using the document/view model, +// this is automatically done for you by the framework. + +void CUTF8ConvDlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // device context for painting + + SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); + + // Center icon in client rectangle + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // Draw the icon + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialog::OnPaint(); + } +} + +// The system calls this to obtain the cursor to display while the user drags +// the minimized window. +HCURSOR CUTF8ConvDlg::OnQueryDragIcon() +{ + return (HCURSOR) m_hIcon; +} + +#include +#include + +static const char HexChars[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + +// Note: Although this is passed a wide character representation, it's only ever single byte characters, so the upper byte is always 0 +static CString ConvertStringToHexPresentation( wstring_view sUtf ) +{ + const size_t NumChars = sUtf.length(); + + CString strResults; + // Hex is shown as 3 chars per character "xx " + LPTSTR pszResults = strResults.GetBuffer( 3* NumChars ); + + for ( size_t indx = 0; indx < NumChars; ++indx ) + { + const BYTE ch = static_cast( sUtf[indx] ); + pszResults[indx*3] = HexChars[( ch >> 4 ) & 0x0f ]; + pszResults[indx*3 + 1] = HexChars[ ch & 0x0f ]; + pszResults[indx*3 + 2] = ' '; + } + strResults.ReleaseBuffer(); + strResults.Trim(); + + return strResults; +} + +static BYTE CharToBin( TCHAR ch ) +{ + BYTE Value = 0x0FF; + + BYTE indx; + for ( indx = 0; indx < _countof( HexChars ); ++indx ) + { + if ( ch == HexChars[indx] ) + { + Value = indx; + break; + } + } + _ASSERT( Value != 0x0FF ); + return Value; +} + +// Bit of a mouthful, but this is what it does: +// Converts a UTF-16 string to the single byte (UTF7/8) form, but returns it in a UTF-16 string. +static CString Utf16StringToSingleByteStringAsUtf16String( const CString& Utf16String, UINT CodePage ) +{ + // Convert to the single byte code page + CW2AEX pA( Utf16String, CodePage ); + + const auto len = strlen( pA ); + + // convert the single byte form to a wide form + CString str; + for ( size_t indx = 0; indx < len; ++indx ) + { + // Must use BYTE here to prevent sign extension doing the wrong thing + const BYTE ch = pA[indx]; + str += ch; + } + + return str; +} + +// Uses the UTF16 field as the source, and populates the UTF-7/8 & Hex fields +void CUTF8ConvDlg::OnConvert() +{ + CString sUtf16; + GetDlgItemText( IDC_UNICODE_TXT, sUtf16 ); + + // Get the code page combo box item value + UpdateData(); + const UINT cp = m_CodePageItem != 0 ? CP_UTF7 : CP_UTF8; + + const auto sUtf8{ Utf16StringToSingleByteStringAsUtf16String( sUtf16, cp ) }; + + m_bUpdatingANSI = true; + // Don't use the ANSI Windows API (as I had done) as it gives the wrong result + // when Windows is set to use UTF-8 as its system codepage. + SetDlgItemText( IDC_ANSI_TXT, sUtf8 ); + m_bUpdatingANSI = false; + + const auto strHex{ ConvertStringToHexPresentation( { sUtf8, static_cast(sUtf8.GetLength()) } ) }; + + m_bUpdatingHex = true; + SetDlgItemText( IDC_HEX_TXT, strHex ); + m_bUpdatingHex = false; +} + +// Uses the Hex as the source and populates the other fields +void CUTF8ConvDlg::OnToascii() +{ + CString sHexText; + GetDlgItemText( IDC_HEX_TXT, sHexText ); + + { + /* The text should be pairs of hex characters with optional white-space characters */ + + /* Parse each hex pair and convert to binary */ + const int NumChars = sHexText.GetLength(); + + bool bSecondOfPair = false; + bool bContentsOK = true; + BYTE Value = 0; // Init to quieten compiler + + CWnd* pInvalidMarker = GetDlgItem( IDC_INVALID_HEX ); + + /* Store the results in this vector */ + vector vBin; + vBin.reserve( NumChars/2 );// Guess an initial size for the vector + + for ( int indx = 0; ( indx < NumChars ) && bContentsOK; ++indx ) + { + TCHAR ch = sHexText[indx]; + + if ( isspace( ch ) ) + { + /* Ignore it */ + } + else + { + /* It must be hex 0..9, A..F (or a..f) */ + if ( isxdigit( ch ) ) + { + /* Jolly good */ + + /* is this the first or second of the pair? */ + if ( bSecondOfPair ) + { + Value <<= 4; + Value += CharToBin( ch ); + + vBin.push_back( Value ); + } + else + { + Value = CharToBin( ch ); + } + + /* Next time it's the other way round */ + bSecondOfPair = !bSecondOfPair; + } + else + { + /* File has non hex characters - abort it */ + bContentsOK = false; + CEdit * pE = static_cast( GetDlgItem( IDC_HEX_TXT ) ); + GotoDlgCtrl( pE ); + pE->SetSel( indx, indx+1, true ); + pInvalidMarker->ShowWindow( SW_SHOWNA ); + break; + } + } + } + /* Check we've had reasonable content to convert */ + if ( bContentsOK ) + { + /* Enable/Disable the red X (invalid hex) control */ + pInvalidMarker->ShowWindow( bSecondOfPair ? SW_SHOWNA : SW_HIDE ); + + if ( bSecondOfPair ) + { +// AfxMessageBox( _T("Data does not contain an even number of hex characters.") ); + } + else + { + /* We have the binary in the vector */ + CStringA sUtf8A( reinterpret_cast( vBin.data() ), vBin.size() ); + + m_bUpdatingANSI = true; + // Don't use the ANSI Windows API (as I had done) as it gives the wrong result + // when Windows is set to use UTF-8 as its system codepage. + + // Copy the characters of the single byte string into a UTF16 string + CString sUtf8W; + for ( int indx = 0; indx < sUtf8A.GetLength(); ++indx ) + { + // Must use BYTE here to prevent sign extension doing the wrong thing + const BYTE ch = sUtf8A[indx]; + sUtf8W += ch; + } + + SetDlgItemText( IDC_ANSI_TXT, sUtf8W ); + m_bUpdatingANSI = false; + + const UINT cp = m_CodePageItem != 0 ? CP_UTF7 : CP_UTF8; + + // Convert the single byte UTF7/8 string to UTF16 + CA2WEX pszUnicode( sUtf8A, cp ); + + m_bUpdatingUnicode = true; + SetDlgItemText( IDC_UNICODE_TXT, pszUnicode ); + m_bUpdatingUnicode = false; + } + } + } +} + +// Uses the Utf-7/8 as the source and populates the other fields +void CUTF8ConvDlg::OnEnChangeUtf8AsAnsi() +{ + if ( !m_bUpdatingANSI ) + { + /* Take the control's text and re-create the hex form of it */ + CString strUtf8; + + GetDlgItemText( IDC_ANSI_TXT, strUtf8 ); + + { + CString strHex = ConvertStringToHexPresentation( { strUtf8, static_cast(strUtf8.GetLength()) } ); + + m_bUpdatingHex = true; + SetDlgItemText( IDC_HEX_TXT, strHex ); + m_bUpdatingHex = false; + + // Convert the string containing the utf7/8 form, into Windows UTF-16 form + // So, first get it into single byte form + CStringA sUtfA; + // Since the Unicode string is really single byte, just loop and copy the characters + for ( int indx = 0; indx < strUtf8.GetLength(); ++indx ) + { + // Do as BYTE (unsigned) to prevent any unexpected sign extension + const BYTE ch = static_cast(strUtf8[indx]); + sUtfA += ch; + } + + UpdateData(); // So as to get the combo variable updated + const UINT cp = m_CodePageItem != 0 ? CP_UTF7 : CP_UTF8; + + // Convert the single byte string to UTF16 from the single byte UTF-7/8 format + CA2WEX pszW( sUtfA, cp ); + + m_bUpdatingUnicode = true; + SetDlgItemText( IDC_UNICODE_TXT, pszW ); + m_bUpdatingUnicode = false; + } + } +} + +void CUTF8ConvDlg::OnEnChangeUnicodeEntry() +{ + if ( !m_bUpdatingUnicode ) + { + OnConvert(); + } +} + +void CUTF8ConvDlg::OnEnChangeHexTxt() +{ + if ( !m_bUpdatingHex ) + { + OnToascii(); + } +} + + +void CUTF8ConvDlg::OnCbnSelchangeUtfBase() +{ + // Utf7/8 combo changed - get everything to update + OnConvert(); +} diff --git a/UTF8ConvDlg.h b/UTF8ConvDlg.h new file mode 100644 index 0000000..4e69a24 --- /dev/null +++ b/UTF8ConvDlg.h @@ -0,0 +1,64 @@ +// UTF8ConvDlg.h : header file +// + +#if !defined(AFX_UTF8CONVDLG_H__A22124A9_8D7A_4D81_AD2F_E07620E978F7__INCLUDED_) +#define AFX_UTF8CONVDLG_H__A22124A9_8D7A_4D81_AD2F_E07620E978F7__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +///////////////////////////////////////////////////////////////////////////// +// CUTF8ConvDlg dialog + +class CUTF8ConvDlg : public CDialog +{ +// Construction +public: + CUTF8ConvDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CUTF8ConvDlg) + enum { IDD = IDD_UTF8CONV_DIALOG }; + // NOTE: the ClassWizard will add data members here + //}}AFX_DATA + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CUTF8ConvDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + HICON m_hIcon; + + // Generated message map functions + //{{AFX_MSG(CUTF8ConvDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnConvert(); + afx_msg void OnToascii(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnEnChangeUtf8AsAnsi(); + afx_msg void OnEnChangeUnicodeEntry(); +private: + bool m_bUpdatingUnicode; + bool m_bUpdatingHex; + bool m_bUpdatingANSI; +public: +afx_msg void OnEnChangeHexTxt(); +private: + int m_CodePageItem; +public: + afx_msg void OnCbnSelchangeUtfBase(); +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_UTF8CONVDLG_H__A22124A9_8D7A_4D81_AD2F_E07620E978F7__INCLUDED_) diff --git a/res/UTF8Conv.ico b/res/UTF8Conv.ico new file mode 100644 index 0000000000000000000000000000000000000000..d09788845631d95df4f09c734d0962707f65ae61 GIT binary patch literal 1078 zcmc(dI}*Y$3`93TL4|XKR1C-9XfElvQjSBJlFq!fF%!(B;4{M}vb2&d%eJIWD-A<0 zX`{xQ;n|jgDDf-Cq8KqXjw9NElz*jU3*obi;nd)a zbB1fn$(ANdnnF^zk|e;gv>dPFY*yke$G?5VL!M(EoL`fR%<(X<$NSIlQeRu|54aTa zVZAN;`P?6I(tNs}8wq|muYbbZym{^uS^o<6x%+rPYM)2!3dbx3ksimQr?X