CString CIconv::ConvertHTML(CString str) { LoadHTML(); return m_CodingHTML.Encode(str); }
BOOL SimpleBrowser::LoadFromResource(INT resID) { ASSERT(m_pBrowser != NULL); if (m_pBrowser != NULL) { CString resource_string; // load HTML document from resource HRSRC resource_handle = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(resID), RT_HTML); if (resource_handle != NULL) { HGLOBAL resource = LoadResource(AfxGetResourceHandle(), resource_handle); if (resource != NULL) { LPVOID resource_memory = LockResource(resource); if (resource_memory != NULL) { DWORD resource_size = SizeofResource(AfxGetResourceHandle(), resource_handle); // identify the resource document as MBCS (e.g. ANSI) or UNICODE bool UNICODE_document = false; wchar_t *UNICODE_memory = (wchar_t *)resource_memory; int UNICODE_size = resource_size / sizeof(wchar_t); if (UNICODE_size >= 1) { // check for UNICODE byte order mark if (*UNICODE_memory == L'\xFEFF') { UNICODE_document = true; UNICODE_memory += 1; UNICODE_size -= 1; } // otherwise, check for UNICODE leading tag else if (UNICODE_size >= 5) { if ((UNICODE_memory[0] == L'<') && (towupper(UNICODE_memory[1]) == L'H') && (towupper(UNICODE_memory[2]) == L'T') && (towupper(UNICODE_memory[3]) == L'M') && (towupper(UNICODE_memory[4]) == L'L')) { UNICODE_document = true; } } // Note: This logic assumes that the UNICODE resource document is // in little-endian byte order, which would be typical for // any HTML document used as a resource in a Windows application. } // convert resource document if required #if !defined(UNICODE) if (UNICODE_document) { char *MBCS_buffer = resource_string.GetBufferSetLength(resource_size + 1); int MBCS_length = ::WideCharToMultiByte(CP_ACP, 0, UNICODE_memory, UNICODE_size, MBCS_buffer, resource_size + 1, NULL, NULL); resource_string.ReleaseBuffer(MBCS_length); } else resource_string = CString((char *)resource_memory,resource_size); #else if (UNICODE_document) resource_string = CString(UNICODE_memory,UNICODE_size); else { wchar_t *UNICODE_buffer = resource_string.GetBufferSetLength(resource_size + 1); int UNICODE_length = ::MultiByteToWideChar(CP_ACP, 0, (const char *)resource_memory, resource_size, UNICODE_buffer, (resource_size + 1)); resource_string.ReleaseBuffer(UNICODE_length); } #endif } } } return LoadHTML(resource_string); } return FALSE; }