technofantasy
博客园
首页
新随笔
联系
订阅
管理
22 Posts :: 16 Stories :: 62 Comments :: 1 Trackbacks
与我联系
发短消息
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(22)
给我留言
查看留言
我参与的团队
北京.NET俱乐部(1/1361)
湖南.NET俱乐部(0/594)
Office专业开发团队(0/65)
MVP团队(0/498)
随笔分类
ASP.NET(2)
Atlas研究
RichTextBox技巧(5)
VB 2005写作进度(2)
VB.NET(1)
杂类(12)
随笔档案
2008年6月 (1)
2008年5月 (1)
2007年3月 (2)
2006年12月 (1)
2006年10月 (3)
2006年9月 (6)
2006年8月 (2)
2006年7月 (4)
2006年1月 (1)
2005年12月 (1)
文章分类
ASP.NET(3)
Atlas研究(2)
Merlion(2)
VB.NET(1)
Visual Basic(1)
VSTO(1)
Webcasts(6)
相册
Microsoft visual studo 2008巡展长沙站
VB.NET
朋友的BLOG
发条木偶的Blog
美女苏胖墩的BLOG
我的网站
AppleVB
搜索
最新评论
1. re: 微软社区发布会总结(多图杀猫)
看得的确辛苦
--萧寒
2. re: 微软社区发布会总结(多图杀猫)
图片好大啊,可以缩小一下啊
--啊不才
3. re: 微软社区发布会总结(多图杀猫)
看得挺辛苦的
--王孟军!
4. re: 微软社区发布会总结(多图杀猫)
向高手致敬...
--伊狼
5. re: 微软社区发布会总结(多图杀猫)
早知道这么多PLMM去了,我说什么也得去啊,呵呵
--ken_sniper
阅读排行榜
1. 在VB.NET中如何使在Webbrowser中实现标签页中打开新链接(2392)
2. 运行cl.exe编译发生:没有找到 mspdb80.dll 的解决办法(2247)
3. 如何使得ShowModalDialog打开的页面自动刷新(1499)
4. RichTextBox技巧之插入表格(转载)(688)
5. RichTextBox技巧之插入图片(转载)(619)
评论排行榜
1. 湖南微软开发者俱乐部成立大会顺利召开(20)
2. VB 2005的写作进度(9)
3. 微软社区发布会总结(多图杀猫)(6)
4. 让微软出钱捐助难民吧(5)
5. 湖南微软.NET俱乐部 成立大会事宜(4)
RichTextBox技巧之插入图片(转载)
'
Inserts the picture at the current insertion point
Public
Function InsertPicture()
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()
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,
0
,
0
, 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,
0
,
0
, Bmp.Width, Bmp.Height, hPicDC,
0
,
0
, 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()
Function
Hex00(icolor
As
Byte
)
As
String
Hex00
=
Right
(
"
0
"
&
Hex
(icolor),
2
)
End Function
posted on 2006-09-06 17:20
陈锐
阅读(619)
评论(0)
编辑
收藏
所属分类:
RichTextBox技巧
社区
新闻
新用户注册
刷新评论列表
标题
姓名
主页
Email
(只有博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
另存
打印
所属分类的其他文章:
·
RichTextBox技巧之插入图片(转载)
·
RichTextBox技巧之插入表格(转载)
·
RichTextBox技巧之插入上标和下标(转载)
·
RichTextBox技巧之显示自定义高亮显示(转载)
·
RichTextBox技巧之插入带格式文本(转载)
最新IT新闻:
·
微软推新型搜索技术"BrowseRank"挑战谷歌
·
2008年7月26日IT博客精选
·
微软每年向Apache捐10万美元支持开源软件
·
AOL将关闭3个网站以降低成本 集中发力广告
·
谷歌网页索引数量突破1万亿个
博客园新闻频道
博客园首页
社区
Powered by:
博客园
Copyright © 陈锐