Office中国论坛/Access中国论坛

标题: 用位图文件装饰窗体背景及文本框背景 [打印本页]

作者: fannky    时间: 2008-1-8 10:16
标题: 用位图文件装饰窗体背景及文本框背景
声明:本贴非原创,转自http://www.vbaccelerator.com/home/vb/code/libraries/subclassing/tile_a_bitmap_into_a_textbox/article.asp著作权及版权均归原创作者所有说明:这是一篇E文资料,本人E文不甚匮乏,没有翻译成中文还望各位看客谅解。不过写得比较简洁,一般水平还是看得懂的
原文如下:
Tile a Bitmap Into a TextBox Background
An interesting hack which gives you a picture in the background of any multi-line text box.
[attach]27700[/attach]
This sample presents a small class that allows you to tile a bitmap into the background of a TextBox. Note that the technique only works on multi-line text boxes, as the drawing of single-line TextBoxes is done in a different way and cannot be easily overridden in code.
Drawing A TextBox BackgroundThe TextBox control in VB is basically a Windows TextBox control with a thin VB wrapper around it. Although the Windows TextBox control hasn't been designed to allow a user to modify it's background, you can still do it by overriding some of the draw messages sent to the control.
The basic principle of overriding the drawing is to subclass the TextBox for the WM_PAINT message which is sent whenever a portion of the control needs to be repainted. Unfortunately, the TextBox also draws portions of itself outside WM_PAINT messages so some other messages also need to be worked on as well, which I will describe later.
When a WM_PAINT message is received, you can determine the portion of the control which needs to be updated using the GetUpdateRect API call. You can then take control of the drawing by drawing into the update area after you've called the standard processing for this message. To actually draw a rendition of a multi-line TextBox control would be difficult if it wasn't for the fact that all Windows controls support a method of drawing themselves into a DC to enable you to print a copy of the control surface. This message is the WM_PRINT message, and takes the DC to draw into as the wParam parameter of the SendMessage call and flags controlling which parts of the control to draw in the lParam parameter. Here is the code to cause the control to print itself into a DC:

' declares: Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" ( _   ByVal hwnd As Long, ByVal wMsg As Long, _   ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Const PRF_CHECKVISIBLE = &H1&Private Const PRF_NONCLIENT = &H2&Private Const PRF_CLIENT = &H4&Private Const PRF_ERASEBKGND = &H8&Private Const PRF_CHILDREN = &H10&Private Const PRF_OWNED = &H20&  
SendMessageLong m_hWnd, WM_PRINT, m_cWorkDC.hDC, PRF_CLIENT Or PRF_CHECKVISIBLE
Once you know this, it is fairly simple to create a version of the control with a different background: draw the background, then ask the control to draw itself (with a transparent background) onto it and then draw it in place.
Unfortunately as mentioned before, the control draws itself outside of the WM_PAINT message as well. To work around this, you also have to respond to WM_CTLCOLOREDIT messages by setting the background to transparent and then repainting and to WM_ERASEBKGND messages (which you eat). Finally, during scrolling the control also needs to be updated. This requires a bit of hacking as you will see if you look at the code, where I create a scroll state machine that ensures painting at the right time. Once this is done, though, you have a control which works exactly as before except with a bitmap in the background!
The cTextBoxBackground classTo make this easier to use, I've wrapped the code up in a simple class. This class has the following methods:

To use it, first add a TextBox to a form, set it to multi-line mode and then create a form level instance of the cTextBoxBackground class (here I'm assuming it's called m_cLargeTextBoxBack). Then set the background picture and attach it to the text box as follows:
   Set m_cLargeTextBoxBack = New cTextBoxBackground   m_cLargeTextBoxBack.SetBackdrop LoadPicture(App.Path & "\back.bmp")   m_cLargeTextBoxBack.Attach txtTest.hwnd

Custom Bitmap Dialogs

Just for fun, I tried using the class to create a dialog with a completely customised appearance, so all of the UI elements are drawn using a bitmap. The result is shown below:
[attach]27699[/attach]
抱歉,回复之后更精彩!


[ 本帖最后由 fannky 于 2008-1-8 10:23 编辑 ]
作者: goto2008    时间: 2008-1-8 11:37
看看。
作者: andymark    时间: 2008-1-8 11:44
ACCESS能实现这样的效果吗
vbaccelerator是学习控件的好地方 控件都带有源码 值得一看
作者: goto2008    时间: 2008-1-8 11:46
大哥,能做个例子上来吗/?
作者: 5988143    时间: 2008-1-8 12:39
謝謝分享!坐下來慢慢看!
作者: gel12345678    时间: 2008-1-8 13:22
谢谢分享....努力学习中.
作者: 插班生    时间: 2008-1-9 14:59

作者: sxmzq    时间: 2008-1-9 21:52
ACCESS能实现这样的效果吗
作者: tmtony    时间: 2008-1-9 23:16
http://www.vbaccelerator.com/  是个非常好的网站, 一直跟随它一起成长
作者: laiguiyou    时间: 2008-1-10 08:01
看看................
作者: csqhlx    时间: 2008-3-4 21:01
看看…………………………
作者: v_tang    时间: 2008-3-4 21:50
好文章一定要学习一下
作者: yedaoan    时间: 2008-4-2 14:24
2342324
作者: 红尘如烟    时间: 2008-5-5 18:15
我看见E文就晕,完全看不懂啊
作者: layaman_999    时间: 2008-5-26 23:14
看看............
作者: XWQ2000    时间: 2008-6-5 17:26
佳作不断. 收藏不停!
作者: df    时间: 2008-6-10 23:28
看看。
作者: wuyu1623    时间: 2008-7-30 17:36
看看................
作者: chenlugen    时间: 2008-8-23 18:54
q bn rhf rhf
作者: 小鸟飞毛    时间: 2008-8-31 18:03
看看...............
作者: lirong    时间: 2008-10-7 23:39
ACCESS能实现这样的效果吗
作者: lymin    时间: 2008-10-16 20:42
标题: 回复 1# 的帖子
看看[:31] [:50]
作者: xyxj1974    时间: 2008-10-18 16:50
学习学习.
作者: wktt6833    时间: 2008-12-11 16:47
vbaccelerator是学习控件的好地方 控件都带有源码 值得一看
作者: yori2007    时间: 2008-12-15 11:36
[:50]
作者: xianbin555    时间: 2009-1-27 14:27
感谢,不知有没有实例
作者: fewflying    时间: 2009-3-6 10:51
学习学习!
作者: ggjjss    时间: 2009-3-20 14:24
谢谢分享
作者: wzh    时间: 2009-4-4 16:25
谢谢分享
作者: szyewj    时间: 2009-4-17 11:33
謝謝分享!坐下來慢慢看!
作者: sun.gd    时间: 2009-4-21 21:45
看看,
作者: asklove    时间: 2009-4-23 08:39
look
作者: danis    时间: 2009-5-23 22:56
謝謝分享!坐下來慢慢看!
作者: chaojianan    时间: 2009-9-27 09:44
谢谢分享,看看。
作者: 沛敏光    时间: 2009-9-29 20:40
支持论坛发展!做为新人我来顶帖啦嘿嘿!
非主流图片   非主流伤感图片  非主流颓废图片 非主流个性图片  非主流情侣图片

9158虚拟摄像头 9158虚拟视频下载 9158多人视频空间 9158视频聊天下载

美女视频面对面 妞妞美女视频聊天   91美女 91美女网  淮海影院

淮海宽屏  电影我世界 无限影视  经典语录 经典语句

女生视频 美女丝袜视频 美女视频短片 女生网络热舞诱惑 美女视频网

三五美女网 三五美女 三五电影网 三五小说 三五美女在线影院

爱色吧 爱色吧在线电影 就爱色 我色我爱色 依旧爱色 深爱爱色 爱色吧在线

91美女网 丁香五月天91美女网 91美女图 丁香五月天91美女 丁香91美女

美女视频聊天室 虚拟美女接吻视频网站 美女陪你免费视频聊天


友情连接了!合作 发点好地址网址给大家看看
作者: sagemeyou    时间: 2009-11-6 22:40

作者: liaoqiang234    时间: 2010-2-7 19:13
thanks share
作者: lupo    时间: 2010-4-15 14:30
看上去漂亮多了,怎么做到的。
作者: 82077802    时间: 2010-4-25 18:12
謝謝分享!坐下來慢慢看!
作者: zhao__feng    时间: 2010-6-2 21:15
ACCESS能实现这样的效果吗
作者: xie62    时间: 2010-6-10 08:28
看看
作者: liangshiheng    时间: 2011-5-12 17:28
dddddd
作者: kdjifir34562    时间: 2011-8-11 09:35
谢谢!!!学习中...
作者: 可柔    时间: 2011-8-31 21:54
应该好好看看,一个系统如果界面设计的友好,就成功了一半。
作者: 风中漫步    时间: 2011-10-22 14:35
找英汉词典
作者: 付谦    时间: 2012-3-22 17:56
学习与参考
作者: 李力军2    时间: 2013-4-21 16:11
新鲜,必须试下
作者: tieguojincheng    时间: 2013-6-3 20:14
学习。谢谢
作者: hwhwenha01    时间: 2013-8-29 17:19
terterterterter




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3