News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Paste Special

Started by guga, June 08, 2013, 11:40:23 AM

Previous topic - Next topic

guga

Some small code to paste RTF or HTML contents to clipboard.

Html Pasting


[lHTML: D$ 0]
[HtmlFileLength: D$ 0]
[HtmlFileHandle: D$ 0]
[HtmlFileMemory: D$ 0]
[HtmlFileMemoryEnd: D$ 0]

Proc PasteHTMLftomClipboard:
    call 'user32.RegisterClipboardFormatA' {B$ "HTML Format", 0} | mov D$lHTML eax
    call 'USER32.OpenClipboard' &NULL
    call 'USER32.GetClipboardData' D$lHTML

    call 'KERNEL32.GlobalLock' eax                          ; > eax = pointer
    mov D$HtmlFileMemory eax

    mov edi eax
    mov al 0
    mov ecx 0-1 | repne scasb
    mov ecx edi | sub ecx D$HtmlFileMemory | dec ecx          ; len
    mov D$HtmlFileLength ecx
    mov eax D$HtmlFileMemory | add eax D$HtmlFileLength | mov D$HtmlFileMemoryEnd eax

EndP


Html Clipboard Reference:
http://msdn.microsoft.com/en-us/library/aa767917%28VS.85%29.aspx

Results from HTMLPasting:

Version:0.9
StartHTML:00000171
EndHTML:00017016
StartFragment:00000205
EndFragment:00016980
SourceURL:http://masm32.com/board/index.php?topic=2005.msg20964#msg20964
<html><body>
<!--StartFragment-->
<div id="wrapper" style="width: 98%">
<div id="header"><div class="frame">
  <div id="top_section">
   <h1 class="forumtitle">
    <a href="http://masm32.com/board/index.php">The MASM Forum</a>
   </h1>
   <img id="upshrink" src="http://masm32.com/board/Themes/default/images/upshrink.png" alt="*" title="Shrink or expand the header." style="cursor: pointer;">
   <img id="smflogo" src="http://masm32.com/board/Themes/default/images/smflogo.png" alt="Simple Machines Forum" title="Simple Machines Forum">
  </div>
  <div id="upper_section" class="middletext">
   <div class="user">
    <p class="avatar"><img src="http://masm32.com/board/index.php?action=dlattach;attach=19;type=avatar" alt="" class="avatar"></p>
    <ul class="reset">
     <li class="greeting">Hello <span>guga</span></li>
     <li><a href="http://masm32.com/board/index.php?action=unread">Show unread posts since last visit.</a></li>
     <li><a href="http://masm32.com/board/index.php?action=unreadreplies">Show new replies to your posts.</a></li>
     <li>June 08, 2013, 11:40:57 AM</li>
    </ul>
   </div>
   <div class="news normaltext">
    <form id="search_form" action="http://masm32.com/board/index.php?action=search2" method="post" accept-charset="UTF-8">
     <input name="search" value="" class="input_text" type="text">Â
     
     
     </form>
    <h2>News: </h2>
    <p><strong><a href="http://masm32.com" class="bbc_link" target="_blank"> MASM32 Downloads </a></strong></p>
   </div>
  </div>
  <br class="clear">
 
  <div id="main_menu">
   <ul class="dropmenu" id="menu_nav">
    <li id="button_home">
     <a class="active firstlevel" href="http://masm32.com/board/index.php">
      <span class="last firstlevel">Home</span>
     </a>
    </li>
    <li id="button_help">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=help">
      <span class="firstlevel">Help</span>
     </a>
    </li>
    <li id="button_search">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=search">
      <span class="firstlevel">Search</span>
     </a>
    </li>
    <li id="button_moderate">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=moderate">
      <span class="firstlevel">Moderate</span>
     </a>
     
    </li>
    <li id="button_profile">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=profile">
      <span class="firstlevel">Profile</span>
     </a>
     
    </li>
    <li id="button_pm">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=pm">
      <span class="firstlevel">My Messages</span>
     </a>
     
    </li>
    <li id="button_mlist">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=mlist">
      <span class="firstlevel">Members</span>
     </a>
     
    </li>
    <li id="button_logout">
     <a class="firstlevel" href="http://masm32.com/board/index.php?action=logout;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535">
      <span class="last firstlevel">Logout</span>
     </a>
    </li>
   </ul>
  </div>
  <br class="clear">
</div></div>
<div id="content_section"><div class="frame">
  <div id="main_content_section">
<div class="navigate_section">
  <ul>
   <li>
    <a href="http://masm32.com/board/index.php"><span>The MASM Forum</span></a> »
   </li>
   <li>
    <a href="http://masm32.com/board/index.php#c3"><span>Projects</span></a> »
   </li>
   <li>
    <a href="http://masm32.com/board/index.php?board=28.0"><span>RosAsm</span></a> (Moderator: <a href="http://masm32.com/board/index.php?action=profile;u=46" title="Board Moderator">guga</a>) »
   </li>
   <li class="last">
    <a href="http://masm32.com/board/index.php?topic=2005.0"><span>Paste Special</span></a>
   </li>
  </ul>
</div>
   <a id="top"></a>
   <a id="msg20964"></a><a id="new"></a>
   <div class="pagesection">
    <div class="nextlinks"><a href="http://masm32.com/board/index.php?topic=2005.0;prev_next=prev#new">« previous</a> <a href="http://masm32.com/board/index.php?topic=2005.0;prev_next=next#new">next »</a></div>
  <div class="buttonlist floatright">
   <ul>
    <li><a class="button_strip_reply active" href="http://masm32.com/board/index.php?action=post;topic=2005.0;last_msg=20964"><span>Reply</span></a></li>
    <li><a class="button_strip_notify" href="http://masm32.com/board/index.php?action=notify;sa=off;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535" onclick="return confirm('Are you sure you wish to disable notification of new replies for this topic?');"><span>Unnotify</span></a></li>
    <li><a class="button_strip_mark_unread" href="http://masm32.com/board/index.php?action=markasread;sa=topic;t=20965;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535"><span>Mark unread</span></a></li>
    <li><a class="button_strip_print" href="http://masm32.com/board/index.php?action=printpage;topic=2005.0" rel="new_win nofollow"><span class="last">Print</span></a></li>
   </ul>
  </div>
    <div class="pagelinks floatleft">Pages: [<strong>1</strong>] </div>
   </div>
   <div id="forumposts">
    <div class="cat_bar">
     <h3 class="catbg">
      <img src="http://masm32.com/board/Themes/default/images/topic/normal_post.gif" alt="" align="bottom">
      <span id="author">Author</span>
      Topic: Paste Special  (Read 1 times)
     </h3>
    </div>
    <form action="http://masm32.com/board/index.php?action=quickmod2;topic=2005.0" method="post" accept-charset="UTF-8" name="quickModForm" id="quickModForm" style="margin: 0;" onsubmit="return oQuickModify.bInEditMode ? oQuickModify.modifySave('d29c16571dd58ed4bd0c866be6d64535', 'b6495fa2c71') : false">
    <div class="windowbg">
     <span class="topslice"><span></span></span>
     <div class="post_wrapper">
      <div class="poster">
       <h4>
        <a href="http://masm32.com/board/index.php?action=profile;u=46" title="View the profile of guga">guga</a>
       </h4>
       <ul class="reset smalltext" id="msg_20964_extra_info">
        <li class="membergroup">Moderator</li>
        <li class="postgroup">Member</li>
        <li class="stars"><img src="http://masm32.com/board/Themes/default/images/starmod.gif" alt="*"><img src="http://masm32.com/board/Themes/default/images/starmod.gif" alt="*"><img src="http://masm32.com/board/Themes/default/images/starmod.gif" alt="*"><img src="http://masm32.com/board/Themes/default/images/starmod.gif" alt="*"><img src="http://masm32.com/board/Themes/default/images/starmod.gif" alt="*"></li>
        <li class="avatar">
         <a href="http://masm32.com/board/index.php?action=profile;u=46">
          <img class="avatar" src="http://masm32.com/board/index.php?action=dlattach;attach=19;type=avatar" alt="">
         </a>
        </li>
        <li class="postcount">Posts: 107</li>
        <li class="profile">
         <ul>
          <li><a href="http://masm32.com/board/index.php?action=profile;u=46"><img src="http://masm32.com/board/Themes/default/images/icons/profile_sm.gif" alt="View Profile" title="View Profile"></a></li>
          <li><a href="http://rosasm.freeforums.org" title="rosasm" target="_blank" class="new_win"><img src="http://masm32.com/board/Themes/default/images/www_sm.gif" alt="rosasm"></a></li>
          <li><a href="http://masm32.com/board/index.php?action=pm;sa=send;u=46" title="Personal Message (Online)"><img src="http://masm32.com/board/Themes/default/images/im_on.gif" alt="Personal Message (Online)"></a></li>
         </ul>
        </li>
       </ul>
      </div>
      <div class="postarea">
       <div class="flow_hidden">
        <div class="keyinfo">
         <div class="messageicon">
          <div title="Message Icon" onclick="aIconLists[0].openPopup(this, 20964)" onmouseover="aIconLists[0].onBoxHover(this, true)" onmouseout="aIconLists[0].onBoxHover(this, false)" style="background: transparent; cursor: pointer; padding: 3px; text-align: center;"><img src="http://masm32.com/board/Themes/default/images/post/xx.gif" alt="" id="msg_icon_20964" style="margin: 0px; padding: 3px 0px 3px 0px;"></div>
         </div>
         <h5 id="subject_20964">
          <a href="http://masm32.com/board/index.php?topic=2005.msg20964#msg20964" rel="nofollow">Paste Special</a>
         </h5>
         <div class="smalltext">« <strong> on:</strong> <strong>Today</strong> at 11:40:23 AM »</div>
         <div id="msg_20964_quick_mod"></div>
        </div>
        <ul class="reset smalltext quickbuttons">
         <li class="quote_button"><a href="http://masm32.com/board/index.php?action=post;quote=20964;topic=2005.0;last_msg=20964" onclick="return oQuickReply.quote(20964);">Quote</a></li>
         <li class="modify_button"><a href="http://masm32.com/board/index.php?action=post;msg=20964;topic=2005.0">Modify</a></li>
         <li class="remove_button"><a href="http://masm32.com/board/index.php?action=deletemsg;topic=2005.0;msg=20964;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535" onclick="return confirm('Remove this message?');">Remove</a></li>
        </ul>
       </div>
       <div class="post">
        <div class="inner" id="msg_20964">Some small code to paste RTF or HTML contents to clipboard.<br><br>Html Pasting<br><div class="codeheader">Code: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a></div><pre style="margin: 0; padding: 0;"><code class="bbc_code"><br>[lHTML: D$ 0]<br>[HtmlFileLength: D$ 0]<br>[HtmlFileHandle: D$ 0]<br>[HtmlFileMemory: D$ 0]<br>[HtmlFileMemoryEnd: D$ 0]<br><br>Proc PasteHTMLftomClipboard:<br>    call 'user32.RegisterClipboardFormatA' {B$ "HTML Format", 0} | mov D$lHTML eax<br>    call 'USER32.OpenClipboard' &amp;NULL<br>    call 'USER32.GetClipboardData' D$lHTML<br><br>    call 'KERNEL32.GlobalLock' eax                          ; &gt; eax = pointer<br>    mov D$HtmlFileMemory eax<br><br>    mov edi eax<br>    mov al 0<br>    mov ecx 0-1 | repne scasb<br>    mov ecx edi | sub ecx D$HtmlFileMemory | dec ecx          ; len<br>    mov D$HtmlFileLength ecx<br>    mov eax D$HtmlFileMemory | add eax D$HtmlFileLength | mov D$HtmlFileMemoryEnd eax<br><br>EndP<br></code></pre><br><br><br><br>RTF Pasting<br><div class="codeheader">Code: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a></div><pre style="margin: 0; padding: 0;"><code class="bbc_code"><br>[lRTF: D$ 0]<br>[RtfFileLength: D$ 0]<br>[RtfFileHandle: D$ 0]<br>[RtfFileMemory: D$ 0]<br>[RtfFileMemoryEnd: D$ 0]<br><br>Proc PasteRTFftomClipboard:<br>    call 'user32.RegisterClipboardFormatA' {B$ "Rich Text Format", 0} | mov D$lRTF eax<br>    call 'USER32.OpenClipboard' &amp;NULL<br>    call 'USER32.GetClipboardData' D$lRTF<br><br>    call 'KERNEL32.GlobalLock' eax                          ; &gt; eax = pointer<br>    mov D$RtfFileMemory eax<br>    mov edi eax<br>    mov al 0<br>    mov ecx 0-1 | repne scasb<br>    mov ecx edi | sub ecx D$RtfFileMemory | dec ecx          ; len<br>    mov D$RtfFileLength ecx<br>    mov eax D$RtfFileMemory | add eax D$RtfFileLength | mov D$RtfFileMemoryEnd eax<br><br>EndP<br></code></pre></div>
       </div>
       <img src="http://masm32.com/board/Themes/default/images/icons/modify_inline.gif" alt="Modify message" title="Modify message" class="modifybutton" id="modify_button_20964" style="cursor: pointer;" onclick="oQuickModify.modifyMsg('20964')">
      </div>
      <div class="moderatorbar">
       <div class="smalltext modified" id="modified_20964">
       </div>
       <div class="smalltext reportlinks">
        <img src="http://masm32.com/board/Themes/default/images/ip.gif" alt="">
        <a href="http://masm32.com/board/index.php?action=helpadmin;help=see_member_ip" onclick="return reqWin(this.href);" class="help">186.213.152.69</a>
       </div>
       <div class="signature" id="msg_20964_signature"><a href="http://rosasm.freeforums.org" class="bbc_link" target="_blank">http://rosasm.freeforums.org</a><br><a href="http://winasm.tripod.com" class="bbc_link" target="_blank">http://winasm.tripod.com</a></div>
      </div>
     </div>
     <span class="botslice"><span></span></span>
    </div>
   
    </form>
   </div>
   <a id="lastPost"></a>
   <div class="pagesection">
   
  <div class="buttonlist floatright">
   <ul>
    <li><a class="button_strip_reply active" href="http://masm32.com/board/index.php?action=post;topic=2005.0;last_msg=20964"><span>Reply</span></a></li>
    <li><a class="button_strip_notify" href="http://masm32.com/board/index.php?action=notify;sa=off;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535" onclick="return confirm('Are you sure you wish to disable notification of new replies for this topic?');"><span>Unnotify</span></a></li>
    <li><a class="button_strip_mark_unread" href="http://masm32.com/board/index.php?action=markasread;sa=topic;t=20965;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535"><span>Mark unread</span></a></li>
    <li><a class="button_strip_print" href="http://masm32.com/board/index.php?action=printpage;topic=2005.0" rel="new_win nofollow"><span class="last">Print</span></a></li>
   </ul>
  </div>
    <div class="pagelinks floatleft">Pages: [<strong>1</strong>] </div>
    <div class="nextlinks_bottom"><a href="http://masm32.com/board/index.php?topic=2005.0;prev_next=prev#new">« previous</a> <a href="http://masm32.com/board/index.php?topic=2005.0;prev_next=next#new">next »</a></div>
   </div>
<div class="navigate_section">
  <ul>
   <li>
    <a href="http://masm32.com/board/index.php"><span>The MASM Forum</span></a> »
   </li>
   <li>
    <a href="http://masm32.com/board/index.php#c3"><span>Projects</span></a> »
   </li>
   <li>
    <a href="http://masm32.com/board/index.php?board=28.0"><span>RosAsm</span></a> (Moderator: <a href="http://masm32.com/board/index.php?action=profile;u=46" title="Board Moderator">guga</a>) »
   </li>
   <li class="last">
    <a href="http://masm32.com/board/index.php?topic=2005.0"><span>Paste Special</span></a>
   </li>
  </ul>
</div>
   <div id="moderationbuttons">
  <div class="buttonlist floatbottom" id="moderationbuttons_strip">
   <ul>
    <li><a class="button_strip_move" href="http://masm32.com/board/index.php?action=movetopic;topic=2005.0"><span>Move Topic</span></a></li>
    <li><a class="button_strip_delete" href="http://masm32.com/board/index.php?action=removetopic2;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535" onclick="return confirm('Are you sure you want to remove this topic?');"><span>Remove Topic</span></a></li>
    <li><a class="button_strip_lock" href="http://masm32.com/board/index.php?action=lock;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535"><span>Lock topic</span></a></li>
    <li><a class="button_strip_sticky" href="http://masm32.com/board/index.php?action=sticky;topic=2005.0;b6495fa2c71=d29c16571dd58ed4bd0c866be6d64535"><span class="last">Set topic sticky</span></a></li>
   </ul>
  </div></div>
   <div class="plainbox" id="display_jump_to"><label class="smalltext" for="display_jump_to_select">Jump to:</label> Â </div>
   <a id="quickreply"></a>
   <div class="tborder" id="quickreplybox">
    <div class="cat_bar">
     <h3 class="catbg">
      <span class="ie6_header floatleft"><a href="javascript:oQuickReply.swap();">
       <img src="http://masm32.com/board/Themes/default/images/expand.gif" alt="+" id="quickReplyExpand" class="icon">
      </a>
      <a href="javascript:oQuickReply.swap();">Quick Reply</a>
      </span>
     </h3>
    </div>
   
   </div>
   
   
  </div>
</div></div>
<div id="footer_section"><div class="frame">
  <ul class="reset">
   <li class="copyright">
   <span class="smalltext" style="display: inline; visibility: visible; font-family: Verdana, Arial, sans-serif;"><a href="http://masm32.com/board/index.php?action=credits" title="Simple Machines Forum" target="_blank" class="new_win">SMF 2.0.2</a> |
<a href="http://www.simplemachines.org/about/smf/license.php" title="License" target="_blank" class="new_win">SMF © 2011</a>, <a href="http://www.simplemachines.org" title="Simple Machines" target="_blank" class="new_win">Simple Machines</a>
   </span></li>
   <li><a id="button_xhtml" href="http://validator.w3.org/check?uri=referer" target="_blank" class="new_win" title="Valid XHTML 1.0!"><span>XHTML</span></a></li>
   
   <li class="last"><a id="button_wap2" href="http://masm32.com/board/index.php?wap2" class="new_win"><span>WAP2</span></a></li>
  </ul>
</div></div>
</div>
<!--EndFragment-->



RTF Pasting


[lRTF: D$ 0]
[RtfFileLength: D$ 0]
[RtfFileHandle: D$ 0]
[RtfFileMemory: D$ 0]
[RtfFileMemoryEnd: D$ 0]

Proc PasteRTFftomClipboard:
    call 'user32.RegisterClipboardFormatA' {B$ "Rich Text Format", 0} | mov D$lRTF eax
    call 'USER32.OpenClipboard' &NULL
    call 'USER32.GetClipboardData' D$lRTF

    call 'KERNEL32.GlobalLock' eax                          ; > eax = pointer
    mov D$RtfFileMemory eax
    mov edi eax
    mov al 0
    mov ecx 0-1 | repne scasb
    mov ecx edi | sub ecx D$RtfFileMemory | dec ecx          ; len
    mov D$RtfFileLength ecx
    mov eax D$RtfFileMemory | add eax D$RtfFileLength | mov D$RtfFileMemoryEnd eax

EndP
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Nice code, Guga :t

There is a shorter version, though... ;)

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        PrintLine "From Firefox clipboard:", CrLf$, String$(60, "-")
        PrintLine HtmlClip$()
        Inkey String$(0,0)
        Exit
end start

Output:
From Firefox clipboard:
------------------------------------------------------------
Version:0.9
StartHTML:00000165
EndHTML:00000298
StartFragment:00000199
EndFragment:00000262
SourceURL:http://masm32.com/board/index.php?topic=2005.0;topicseen
<html><body>
<!--StartFragment-->Some small code to paste RTF or HTML contents to clipboard.<br><!--EndFragment-->
</body>
</html>

------------------------------------------------------------

This works, too (test e.g. when writing a mail with Thunderbird):
SetHtmlClip$ "Hello <b>Guga</b>"