惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Schneier on Security
Schneier on Security
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
A
About on SuperTechFans
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
V2EX - 技术
V2EX - 技术
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
V
Visual Studio Blog
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
Scott Helme
Scott Helme
H
Heimdal Security Blog
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Vulnerabilities – Threatpost
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
Jina AI
Jina AI
S
Securelist
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
AWS News Blog
AWS News Blog
N
News and Events Feed by Topic
博客园 - 三生石上(FineUI控件)
量子位

博客园 - 陈锐

微软社区发布会总结(多图杀猫) 微软 Visual Studio 2008 社区发布全国巡展长沙站预报 让微软出钱捐助难民吧 能够下载时改名的文件权限管理 你的博客的性别是什么? 湖南微软开发者俱乐部成立大会顺利召开 湖南微软.NET俱乐部 成立大会事宜 在VB.NET中如何使在Webbrowser中实现标签页中打开新链接 RichTextBox技巧之插入表格(转载) RichTextBox技巧之插入上标和下标(转载) RichTextBox技巧之显示自定义高亮显示(转载) RichTextBox技巧之插入带格式文本(转载) VB 2005的写作进度 再VB 2005的拖放式数据绑定时遇到的问题 有些问题稍微想一下就明白了 写作进度(7月30日) Charles Petzold给撰书人的建议(from 思归的博客) 运行cl.exe编译发生:没有找到 mspdb80.dll 的解决办法 在VSTO 2005下创建的Office CommandBarButton不能定义在过程内
RichTextBox技巧之插入图片(转载)
陈锐 · 2006-09-06 · via 博客园 - 陈锐

'Inserts the picture at the current insertion point
Public Function InsertPicture(RTB As RichTextBox, pic As StdPicture)
Dim strRTFall As String
Dim lStart As Long
    
With RTB
        .SelText 
= Chr(&H9D) & .SelText & Chr(&H81)
        strRTFall 
= .TextRTF
        strRTFall 
= Replace(strRTFall, "\'9d", PictureToRTF(pic))
        .TextRTF 
= strRTFall
        
'position cursor past new insertion
        lStart = .Find(Chr(&H81))
        strRTFall 
= Replace(strRTFall, "\'81""")
        .TextRTF 
= strRTFall
        .SelStart 
= lStart
    
End With
End Function

PictureToRTF方法:

Public Function PictureToRTF(pic As StdPicture) As String
    
Dim hMetaDC As Long, hMeta As Long, hPicDC As Long, hOldBmp As Long
    
Dim Bmp As BITMAP, Sz As Size, Pt As POINTAPI
    
Dim sTempFile As String, screenDC As Long
    
Dim headerStr As String, retStr As String, byteStr As String
    
Dim ByteArr() As Byte, nBytes As Long
    
Dim fn As Long, i As Long, j As Long

    sTempFile 
= App.Path & "\~pic" & ((Rnd * 1000000+ 1000000\ 1 & ".tmp"  'some temprory file
    If Dir(sTempFile) <> "" Then Kill sTempFile
    
    
'Create a metafile which is a collection of structures that store a
    'picture in a device-independent format.
    hMetaDC = CreateMetaFile(sTempFile)
    
    
'set size of Metafile window
    SetMapMode hMetaDC, MM_ANISOTROPIC
    SetWindowOrgEx hMetaDC, 
00, Pt
    
GetObject pic.Handle, Len(Bmp), Bmp
    SetWindowExtEx hMetaDC, Bmp.Width, Bmp.Height, Sz
    
'save sate for later retrieval
    SaveDC hMetaDC
    
    
'get DC compatible to screen
    screenDC = GetDC(0)
    hPicDC 
= CreateCompatibleDC(screenDC)
    ReleaseDC 
0, screenDC
    
    
'set out picture as new DC picture
    hOldBmp = SelectObject(hPicDC, pic.Handle)
    
    
'copy our picture to metafile
    BitBlt hMetaDC, 00, Bmp.Width, Bmp.Height, hPicDC, 00, vbSrcCopy
    
    
'cleanup - close metafile
    SelectObject hPicDC, hOldBmp
    DeleteDC hPicDC
    DeleteObject hOldBmp
    
'retrieve saved state
    RestoreDC hMetaDC, True
    hMeta 
= CloseMetaFile(hMetaDC)
    DeleteMetaFile hMeta
    
    
'header to string we want to insert
    headerStr = "{\pict\wmetafile8" & _
                
"\picw" & pic.Width & "\pich" & pic.Height & _
                
"\picwgoal" & Bmp.Width * Screen.TwipsPerPixelX & _
                
"\pichgoal" & Bmp.Height * Screen.TwipsPerPixelY & _
                
""
        
    
'read metafile from disk into byte array
    nBytes = FileLen(sTempFile)
    
ReDim ByteArr(1 To nBytes)
    fn 
= FreeFile()
    Open sTempFile 
For Binary Access Read As #fn
    
Get #fn, , ByteArr
    Close #fn
    
Dim nlines As Long
        
    
'turn each byte into two char hex value
    i = 0
    byteStr 
= ""
    
Do
        byteStr 
= byteStr & vbCrLf
        
For j = 1 To 39
            i 
= i + 1
            
If i > nBytes Then Exit For
            byteStr 
= byteStr & Hex00(ByteArr(i))
        
Next j
    
Loop While i < nBytes
    
    
'string we will be inserting
    retStr = headerStr & LCase(byteStr) & vbCrLf & "}"
    PictureToRTF 
= retStr
    
    
'remove temp metafile
    Kill sTempFile

End Function


'adds leading zero to hex value if needed.
Public Function Hex00(icolor As ByteAs String
    Hex00 
= Right("0" & Hex(icolor), 2)
End Function