大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 发现剪帖板的秘密

发现剪帖板的秘密

时间: 2021-07-31 作者:daque

     windows 中的ctrl+c 和ctrl+v  大师该当很熟习了, 然而您领会剪帖板里有啥? 举个例子, 在 ie4当选一段东东,按ctrl+c, 而后在frontpage 中按ctrl+v, 您选的东东完备地正片到了frontpage 中, 字体, 脸色之类。 鲜明, 剪帖板中确定包括了html 消息, 而即使咱们在编制程序也要获得那些消息, 该如何办呢? 正文供给了两种本领, 一是怎样获得对于剪贴方法的称呼, 一是怎样用文本方法表露剪贴版中一定剪贴方法实质。 在咱们的第一个演练中, 运用一个很笨的本领来获得 html 剪贴方法的称呼。 getclipboardformatname 不妨由剪贴板的id 获得该方法的称呼, 所以用一个轮回来搜索一切包括html 笔墨的方法。  在第二个例子中, 咱们运用了在例子第一中学获得的称呼, 把在 ie4 中剪贴的html 实质兼并到一个 textbox 中, 好让咱们领会内里有怎么办的消息。 实行办法 例子一 获得剪贴方法的称呼 1 兴建一个工程。 2 在工程中减少一个吩咐按钮(command1)。 3 减少底下的代码: private declare function getclipboardformatname lib "user32" alias "getclipboardformatnamea" (byval wformat as long, byval lpstring as string, byval nmaxcount as long) as long private sub command1_click() dim formatid as long dim bufferlen as long dim buffer as string * 80 for formatid = 50000 to 60000 '普遍灵验的 id 在该区内 bufferlen = getclipboardformatname(formatid, buffer, 80) if bufferlen > 0 then if instr(ucase(left(buffer, bufferlen)), "html") > 0 then msgbox formatid & ":" & buffer end if next end sub 4 运转该步调, 不妨创造多个带 html 的方法称呼, 过程尝试,html format是咱们要找的。 提防: 没有 ie4 的话, 不妨运用 rtf 举行查问, 以察看 richtext 的剪贴实质。 例子二 获得 ie4 的剪贴实质 1 兴建一个工程。 2 在工程中减少一个吩咐按钮(command1), 一个textbox(text1), 允很多行表露。 3 减少底下的代码: private declare function openclipboard lib "user32" (byval hwnd as long) as long private declare function closeclipboard lib "user32" () as long private declare function getclipboarddata lib "user32" (byval wformat as long) as long private declare function isclipboardformatavailable lib "user32" (byval wformat as long) as long private declare function registerclipboardformat lib "user32" alias "registerclipboardformata" (byval lpstring as string) as long private declare function globallock lib "kernel32" (byval hmem as long) as long private declare function globalunlock lib "kernel32" (byval hmem as long) as long private declare function globalsize lib "kernel32" (byval hmem as long) as long private declare sub copymemory lib "kernel32" alias "rtlmovememory" (lpvdest as any, lpvsource as any, byval cbcopy as long) public function getclipboardidforcustomformat(byval sname as string) as long dim wformat as long wformat = registerclipboardformat(sname & chr$(0)) if (wformat > &hc000&) then getclipboardidforcustomformat = wformat end if end function public function getclipboarddataasstring(byval hwndowner as long, byval lformatid as long) as string dim bdata() as byte dim hmem as long dim lsize as long dim lptr as long if (openclipboard(hwndowner)) then if (isclipboardformatavailable(lformatid) <> 0) then hmem = getclipboarddata(lformatid) if (hmem <> 0) then lsize = globalsize(hmem) if (lsize > 0) then lptr = globallock(hmem) if (lptr <> 0) then redim bdata(0 to lsize - 1) as byte copymemory bdata(0), byval lptr, lsize globalunlock hmem getclipboarddataasstring = strconv(bdata, vbunicode) end if end if end if end if closeclipboard end if end function private sub command1_click() dim lid as long dim stext as string ' 即使没有 ie4,不妨运用 "rtf format"  lid = getclipboardidforcustomformat("html format") if (lid <> 0) then stext = getclipboarddataasstring(me.hwnd, lid) text1.text = stext end if end sub 4 运转该步调。 在ie4 当选大肆的东东, 按ctrl+c, 而后按 command1, 不妨在text1 中看到如次的实质, 中国字表露题目与 getclipboarddataasstring = strconv(bdata, vbunicode) 相关: version:1.0 starthtml:000000213 endhtml:000000863 startfragment:000000758 endfragment:000000772 startselection:000000758 endselection:000000772 sourceurl:file://g:\frontpage webs\content\vbtt\download.htm <!doctype html public "-//w3c//dtd w3 html//en"> 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.