Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the function I came up with the help of <a href="http://bit.ly/139Rmkg" rel="nofollow">Jochen Arndt at codeproject.com</a>. Hope this helps somebody. <a href="http://bit.ly/10c1M3e" rel="nofollow">Here is a complete working code</a>, if you are interested in checking this out.</p> <p><s>It still has one problem. That is when pasted to onenote alone, it pastes gibberish after a anchor tag. It does not happen with Word, PowerPoint or Excel. And it does not have this problem for normal English language texts. If you have a solution for this, please do let me know.</s> The problem seems to be with OneNote. Not with the code.</p> <pre class="lang-cpp prettyprint-override"><code>bool setClipboard(LPCWSTR lpszWide){ int nUtf8Size = ::WideCharToMultiByte(CP_UTF8, 0, lpszWide, -1, NULL, 0, NULL, NULL); if (nUtf8Size &lt; 1) return false; const int nDescLen = 105; HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, nDescLen + nUtf8Size); if (NULL != hGlobal) { bool bErr = false; LPSTR lpszBuf = static_cast&lt;LPSTR&gt;(::GlobalLock(hGlobal)); LPSTR lpszUtf8 = lpszBuf + nDescLen; if (::WideCharToMultiByte(CP_UTF8, 0, lpszWide, -1, lpszUtf8, nUtf8Size, NULL, NULL) &lt;= 0) { bErr = true; } else { LPCSTR lpszStartFrag = strstr(lpszUtf8, "&lt;!--StartFragment--&gt;"); LPCSTR lpszEndFrag = strstr(lpszUtf8, "&lt;!--EndFragment--&gt;"); lpszStartFrag += strlen("&lt;!--StartFragment--&gt;") + 2; int i = _snprintf( lpszBuf, nDescLen, "Version:1.0\r\nStartHTML:%010d\r\nEndHTML:%010d\r\nStartFragment:%010d\r\nEndFragment:%010d\r\n", nDescLen, nDescLen + nUtf8Size - 1, // offset to next char behind string nDescLen + static_cast&lt;int&gt;(lpszStartFrag - lpszUtf8), nDescLen + static_cast&lt;int&gt;(lpszEndFrag - lpszUtf8)); } ::GlobalUnlock(hGlobal); if (bErr) { ::GlobalFree(hGlobal); hGlobal = NULL; } // Get clipboard id for HTML format... static int cfid = 0; cfid = RegisterClipboardFormat("HTML Format"); // Open the clipboard... if(OpenClipboard(0)) { EmptyClipboard(); HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(lpszBuf)+4); char *ptr = (char *)GlobalLock(hText); strcpy(ptr, lpszBuf); GlobalUnlock(hText); ::SetClipboardData(cfid, hText); CloseClipboard(); GlobalFree(hText); } } return NULL != hGlobal; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload