?????????? ?? HTML ??? ????? C++ ?? ????? ?? ?????? ???? ????

???? ID: 274308
??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????????? ???? ?? ?? Microsoft Windows ?????????? ???????????? ??????? ???? (HTML) ????? C++ ?? ????? ?? ?????? ?? ??? ???? ????? ????? ?? ??? ????? ?????? ?? ????? ?? ???? ??? ?? ????? ????????? ?? ??? ????? ???? ?? ??? ???? ??????????? ????

???? ???????

HTML ??? ????? ?????????? ?????? HTML ?????? (CF_HTML) ???? ???? ?? ???? ???????????, ???? Microsoft Excel, Microsoft Word ?? ???? Microsoft Office ??????????? ?? ??? ?????? ????? ?? ??? ????? ?? ???? ??? ?? ??? ???? ???

CF_HTML ???? ??? ?? ???-?????? ?????? ?????, ??? ?????? ?? ?? ?????? ??? ??? fragment ????? ??? ?? ?? ???? ?? ?????????? ?? ????? ?? ??? ?????, ?????????? ??????? ?? offsets fragment ?? ?????? ?? ??? ????? ???? ?? ??? ???? ?? ??? ????? ????? ???? ?????? ??? Offsets ?? ???? ?? ???? ?????? ?? ???? ??? ???????, ?? ????? ?? ??? ????? ???? ?? ??? ????? ????? ?? ????? ?? ???? ???:
// CopyHtml() - Copies given HTML to the clipboard.
// The HTML/BODY blanket is provided, so you only need to
// call it like CallHtml("<b>This is a test</b>");

void CopyHTML(char *html) {
    // Create temporary buffer for HTML header...
    char *buf = new char [400 + strlen(html)];
    if(!buf) return;

    // Get clipboard id for HTML format...
    static int cfid = 0;
    if(!cfid) cfid = RegisterClipboardFormat("HTML Format");

    // Create a template string for the HTML header...
    strcpy(buf,
        "Version:0.9\r\n"
        "StartHTML:00000000\r\n"
        "EndHTML:00000000\r\n"
        "StartFragment:00000000\r\n"
        "EndFragment:00000000\r\n"
        "<html><body>\r\n"
        "<!--StartFragment -->\r\n");

    // Append the HTML...
    strcat(buf, html);
    strcat(buf, "\r\n");
    // Finish up the HTML format...
    strcat(buf,
        "<!--EndFragment-->\r\n"
        "</body>\r\n"
        "</html>");

    // Now go back, calculate all the lengths, and write out the
    // necessary header information. Note, wsprintf() truncates the
    // string when you overwrite it so you follow up with code to replace
    // the 0 appended at the end with a '\r'...
    char *ptr = strstr(buf, "StartHTML");
    wsprintf(ptr+10, "%08u", strstr(buf, "<html>") - buf);
    *(ptr+10+8) = '\r';

    ptr = strstr(buf, "EndHTML");
    wsprintf(ptr+8, "%08u", strlen(buf));
    *(ptr+8+8) = '\r';

    ptr = strstr(buf, "StartFragment");
    wsprintf(ptr+14, "%08u", strstr(buf, "<!--StartFrag") - buf);
    *(ptr+14+8) = '\r';

    ptr = strstr(buf, "EndFragment");
    wsprintf(ptr+12, "%08u", strstr(buf, "<!--EndFrag") - buf);
    *(ptr+12+8) = '\r';

    // Now you have everything in place ready to put on the
    // clipboard.

    // Open the clipboard...
    if(OpenClipboard(0)) {
        
        // Empty what's in there...
        EmptyClipboard();
        
        // Allocate global memory for transfer...
        HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(buf)+4);
        
        // Put your string in the global memory...
        char *ptr = (char *)GlobalLock(hText);
        strcpy(ptr, buf);
        GlobalUnlock(hText);
        
        ::SetClipboardData(cfid, hText);
        
        CloseClipboard();
        // Free memory...
        GlobalFree(hText);
        
    }

    // Clean up...
    delete [] buf;
}
				
?? ??? HTML ??? fragment ?????????? ??? ????????? ????? ?? ??? ?? ?? ?????? ?? ????? ????, ??? ????? ?? ??? ????? ?? ???? ??:
    char *html = 
        "<b>This is a test</b><hr>"
        "<li>entry 1"
        "<li>entry 2";
    CopyHTML(html);
				

???????? ???

?????????? ?? ??? HTML ??? ????? ?? ?? ???? approach ?? ????? ?? Office ??????? ??????? ?? ??? ????? ??? ?? beneficial ?? ???? ??? ?????? ?? ???, ??? ???? ??????? ??????? ???? ?????? ?? ??? ???????? ???? ?? Microsoft Excel ?? Microsoft Word ??? ?????????? ??? ????? ???? ?? ???????? ??, ?? ?? ??? HTML ??? ??? ???? ?? ?????, ??? ?????????? ?? ?????, ?? ??? ??????? ?? ????????? ???? ?? ????? ?? ????? ??, ?????? ??????? ??????? ?? ??? ?? ???-??-????????? ?? ?????? ?? ?? ????

??????

Specifics HTML ?????????? ?????? ?? ???? ??? ???? ????? ?? ??? "HTML ?????????? ??????" MSDN ??? ???? ?????:
HTTP://MSDN.Microsoft.com/en-us/library/aa767917.aspx

???

???? ID: 274308 - ????? ???????: 03 ?????? 2010 - ??????: 2.0
??????: 
kbclipboard kbhowto kbhtml kbmt KB274308 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:274308

??????????? ???