int cText::Create(std::string Font) { // 폰트생성 LOGFONT logf={0}; logf.lfHeight = 8L; logf.lfWeight = FW_NORMAL; logf.lfCharSet = HANGUL_CHARSET; logf.lfOutPrecision= OUT_DEFAULT_PRECIS; logf.lfQuality = ANTIALIASED_QUALITY; logf.lfPitchAndFamily= FF_DONTCARE; char* cFaceName = new char[Font.size()+1]; DXUtil_ConvertWideStringToAnsiCch(cFaceName, logf.lfFaceName, 1+static_cast<int>(Font.size())); strcpy_s(cFaceName, 32, Font.c_str()); m_hFont = CreateFontIndirect(&logf); delete[] cFaceName; return 0; }
//----------------------------------------------------------------------------- // Name: DXUtil_ConvertAnsiStringToGeneric() // Desc: This is a UNICODE conversion utility to convert a WCHAR string into a // TCHAR string. // cchDestChar is the size in TCHARs of tstrDestination. Be careful not to // pass in sizeof(strDest) on UNICODE builds //----------------------------------------------------------------------------- HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar ) { if( tstrDestination==NULL || wstrSource==NULL || cchDestChar < 1 ) return E_INVALIDARG; #ifdef _UNICODE wcsncpy( tstrDestination, wstrSource, cchDestChar ); tstrDestination[cchDestChar-1] = L'\0'; return S_OK; #else return DXUtil_ConvertWideStringToAnsiCch( tstrDestination, wstrSource, cchDestChar ); #endif }
//----------------------------------------------------------------------------- // Name: DXUtil_ConvertGenericStringToAnsi() // Desc: This is a UNICODE conversion utility to convert a TCHAR string into a // CHAR string. // cchDestChar is the size in TCHARs of strDestination //----------------------------------------------------------------------------- HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar ) { if( strDestination==NULL || tstrSource==NULL || cchDestChar < 1 ) return E_INVALIDARG; #ifdef _UNICODE return DXUtil_ConvertWideStringToAnsiCch( strDestination, tstrSource, cchDestChar ); #else strncpy( strDestination, tstrSource, cchDestChar ); strDestination[cchDestChar-1] = '\0'; return S_OK; #endif }
HRESULT DXUtil_ConvertWideStringToAnsiCb( CHAR* strDestination, const WCHAR* wstrSource, int cbDestChar ) { return DXUtil_ConvertWideStringToAnsiCch( strDestination, wstrSource, cbDestChar / sizeof(CHAR) ); }