---- 本文介绍在PowerBuilder中实现IE风格的图标按钮的技巧。在C++ Builder开发工具中,有一种图标按钮(SpeedButton),这种按钮可以在鼠标移入按钮后,在图片的周围会出现凸出的边框,鼠标移出按钮后边框消失。而在PowerBuilder中没有提供这种功能的按钮,为了使开发的应用程序界面更丰富,我们使用自定义图形控件(Picture)扩展并实现了此功能,这种方法设计出的程序简洁实用。
---- 一、实现功能
---- 按钮可以显示四种状态图形:
---- 1、Normal状态;
---- 2、Disabled状态;
---- 3、MouseOver状态(鼠标进入按钮区);
---- 4、ClickDown状态(鼠标按下)。
---- 二、关键方法
---- 1、当鼠标进入按钮区域时,控件图片改换成MouseOver状态的图片,并设置状态信号;
---- 2、鼠标滑入按钮区域后用Windows API函数SetCapture来捕获鼠标输入消息,跟踪鼠标位置;
---- 3、当监测到鼠标滑出按钮区域时,用ReleaseCapture函数释放鼠标捕获,恢复按钮图片到Normal状态并设置状态信号;
---- 4、改变控件的图片(PictureName)前,先用ReleaseCapture释放鼠标捕获,然后改变PictureName属性值,接着重新调用SetCapture函数,因为改变图片后PowerBuilder重新建立了控件窗口,窗口的句柄(hWnd)也随之改变了。
---- 三、设计过程
---- 1、新建“User Object” -〉选择Visual的Standard类 -〉选择“Picture”;
---- 2、定义全局的或局部的外部函数:
// *******************************
// Declare External Functions
// *******************************
function ulong SetCapture
(ulong hwnd) library "user32.dll"
function boolean ReleaseCapture
(ulong hwnd) library "user32.dll"
function boolean DrawEdge(ulong hdc,
ref rect qrc, uint edge, uint grfFlags)
library "user32.dll"
---- 3、定义结构 数据 类型
RECT
{
long left
long top
long right
long bottom
}
---- 4、定义控件共享变量:
// *******************************
// Declare Shared Variables
// *******************************
boolean sb_SuppressHoverBorder
---- 5、定义控件实例变量:
// *******************************
// Declare Instance Variables
// *******************************
Private:
boolean ib_MouseCaptured
Public:
string is_PicNormal
string is_PicDisabled
string is_PicMouseOver
string is_PicClickDown
int in_State
---- 6、定义用户事件:
// *******************************
// Declare User Events
// *******************************
Event Name="mousemove",ID="pbm_mousemove"
Event Name="lbuttondown", ID="pbm_lbuttondown"
Event Name="lbuttonup",ID="pbm_lbuttonup"
---- 7、编写事件代码:
// “Constructor” 事件代码
// *** begin constructor event ***
//
is_PicNormal = this.PictureName
is_PicDisabled = "Disabled状态图片.bmp"
is_PicMouseOver = "MouseOver状态图片.bmp"
is_PicClickDown = "ClickDown状态图片.bmp"
in_State = 0
sb_SuppressHoverBorder = FALSE
//
// *** end constructor event ***
// “MouseMove” 事件代码
// *** begin mousemove event ***
//
rect lr_Border
if not ib_MouseCaptured then
if flags < > 1 then
this.PictureName = is_PicMouseOver
else
// Left Button Down
this.PictureName = is_PicClickDown
end if
in_State = 1
SetCapture(handle(this))
ib_MouseCaptured = TRUE
if not sb_SuppressHoverBorder then
lr_Border.left = 0
lr_Border.top = 0
lr_Border.right = UnitsToPixels
(this.Width, XUnitsToPixels!)
lr_Border.bottom = UnitsToPixels
(this.Height, YUnitsToPixels!)
if flags < > 1 then
DrawEdge(GetDC(handle(this)),
lr_Border, 4, 1+2+4+8)
else
// Left Button Down
DrawEdge(GetDC(handle(this)),
lr_Border, 2, 1+2+4+8)
end if
---- 一、实现功能
---- 按钮可以显示四种状态图形:
---- 1、Normal状态;
---- 2、Disabled状态;
---- 3、MouseOver状态(鼠标进入按钮区);
---- 4、ClickDown状态(鼠标按下)。
---- 二、关键方法
---- 1、当鼠标进入按钮区域时,控件图片改换成MouseOver状态的图片,并设置状态信号;
---- 2、鼠标滑入按钮区域后用Windows API函数SetCapture来捕获鼠标输入消息,跟踪鼠标位置;
---- 3、当监测到鼠标滑出按钮区域时,用ReleaseCapture函数释放鼠标捕获,恢复按钮图片到Normal状态并设置状态信号;
---- 4、改变控件的图片(PictureName)前,先用ReleaseCapture释放鼠标捕获,然后改变PictureName属性值,接着重新调用SetCapture函数,因为改变图片后PowerBuilder重新建立了控件窗口,窗口的句柄(hWnd)也随之改变了。
---- 三、设计过程
---- 1、新建“User Object” -〉选择Visual的Standard类 -〉选择“Picture”;
---- 2、定义全局的或局部的外部函数:
// *******************************
// Declare External Functions
// *******************************
function ulong SetCapture
(ulong hwnd) library "user32.dll"
function boolean ReleaseCapture
(ulong hwnd) library "user32.dll"
function boolean DrawEdge(ulong hdc,
ref rect qrc, uint edge, uint grfFlags)
library "user32.dll"
---- 3、定义结构 数据 类型
RECT
{
long left
long top
long right
long bottom
}
---- 4、定义控件共享变量:
// *******************************
// Declare Shared Variables
// *******************************
boolean sb_SuppressHoverBorder
---- 5、定义控件实例变量:
// *******************************
// Declare Instance Variables
// *******************************
Private:
boolean ib_MouseCaptured
Public:
string is_PicNormal
string is_PicDisabled
string is_PicMouseOver
string is_PicClickDown
int in_State
---- 6、定义用户事件:
// *******************************
// Declare User Events
// *******************************
Event Name="mousemove",ID="pbm_mousemove"
Event Name="lbuttondown", ID="pbm_lbuttondown"
Event Name="lbuttonup",ID="pbm_lbuttonup"
---- 7、编写事件代码:
// “Constructor” 事件代码
// *** begin constructor event ***
//
is_PicNormal = this.PictureName
is_PicDisabled = "Disabled状态图片.bmp"
is_PicMouseOver = "MouseOver状态图片.bmp"
is_PicClickDown = "ClickDown状态图片.bmp"
in_State = 0
sb_SuppressHoverBorder = FALSE
//
// *** end constructor event ***
// “MouseMove” 事件代码
// *** begin mousemove event ***
//
rect lr_Border
if not ib_MouseCaptured then
if flags < > 1 then
this.PictureName = is_PicMouseOver
else
// Left Button Down
this.PictureName = is_PicClickDown
end if
in_State = 1
SetCapture(handle(this))
ib_MouseCaptured = TRUE
if not sb_SuppressHoverBorder then
lr_Border.left = 0
lr_Border.top = 0
lr_Border.right = UnitsToPixels
(this.Width, XUnitsToPixels!)
lr_Border.bottom = UnitsToPixels
(this.Height, YUnitsToPixels!)
if flags < > 1 then
DrawEdge(GetDC(handle(this)),
lr_Border, 4, 1+2+4+8)
else
// Left Button Down
DrawEdge(GetDC(handle(this)),
lr_Border, 2, 1+2+4+8)
end if
http://j.renren.com/album/1308220832162893213 |
http://j.renren.com/album/1308220832533164105 |
http://j.renren.com/album/1308220833298191342 |
http://j.renren.com/album/1308220833482978108 |
http://j.renren.com/album/1308220834087153933 |
http://j.renren.com/album/1308220834340841341 |
http://j.renren.com/album/1308220834547938474 |
http://j.renren.com/album/1308220835140661277 |
http://j.renren.com/album/1308220835399217575 |
http://j.renren.com/album/1308220835590727512 |
http://j.renren.com/album/1308220836249542677 |
http://j.renren.com/album/1308220836476299005 |
http://j.renren.com/album/1308220837102111730 |
http://j.renren.com/album/1308220837280835554 |
http://j.renren.com/album/1308220837557425960 |
http://j.renren.com/album/1308220848312587939 |
http://j.renren.com/album/1308220851375912691 |
http://j.renren.com/album/1308220852037104701 |
http://j.renren.com/album/1308220852237352401 |
http://j.renren.com/album/1308220852453819468 |
http://j.renren.com/album/1308220852598310613 |
http://j.renren.com/album/1308220853177892371 |
http://j.renren.com/album/1308220853337081016 |
http://j.renren.com/album/1308220853537711566 |
http://j.renren.com/album/1308220854163393204 |
http://www.56.com/p73/v_MTI0OTI2MDk0.html |
http://www.56.com/p81/v_MTI0OTI2MTkw.html |
http://www.56.com/p72/v_MTI0OTI2MjY5.html |
http://www.56.com/p84/v_MTI0OTEyMTEz.html |
http://www.56.com/p54/v_MTI0OTI2MzM5.html |
http://www.56.com/p30/v_MTI0OTI2NDAz.html |
http://www.56.com/p13/v_MTI0OTI2NDc0.html |
http://www.56.com/p19/v_MTI0OTI2NTY4.html |
http://www.56.com/p12/v_MTI0OTI2NjQ5.html |
http://www.56.com/p24/v_MTI0OTI2NzQ5.html |
http://www.56.com/p96/v_MTI0OTI2ODIx.html |
http://www.56.com/p62/v_MTI0OTI2ODc1.html |
http://www.56.com/p61/v_MTI0OTI2OTYy.html |
http://www.56.com/p47/v_MTI0OTI3MDM2.html |
http://www.56.com/p21/v_MTI0OTI3MDk4.html |
http://www.56.com/p95/v_MTI0OTI3MTcy.html |
http://www.56.com/p32/v_MTI0OTI3Mjg1.html |
http://www.56.com/p90/v_MTI0OTI3MzQz.html |
http://www.56.com/p51/v_MTI0OTI3NDgw.html |
http://www.56.com/p39/v_MTI0OTI3NTU2.html |
http://www.56.com/p18/v_MTI0OTI3NjIz.html |
http://www.56.com/p37/v_MTI0OTI3NzMw.html |
http://www.56.com/p57/v_MTI0OTI3ODM4.html |
http://www.56.com/p20/v_MTI0OTI3OTc3.html |
http://www.56.com/p28/v_MTI0OTI4MDcz.html |
http://www.56.com/p33/v_MTI0OTI4MTY2.html |
http://www.56.com/p35/v_MTI0OTI4MjU2.html |
http://www.56.com/p26/v_MTI0OTI4MzM1.html |
http://www.56.com/p39/v_MTI0OTI4NDM2.html |
http://www.56.com/p11/v_MTI0OTI4NDk2.html |
http://www.56.com/p54/v_MTI0OTI4NjI3.html |
http://www.56.com/p41/v_MTI0OTI4OTY2.html |
http://www.56.com/p30/v_MTI0OTI5MDQz.html |
http://www.56.com/p95/v_MTI0OTI5MTk2.html |
http://www.56.com/p42/v_MTI0OTI5MzE5.html |
http://photo.163.com/q/6710137/?mid=174362069 |
http://photo.163.com/q/6710127/?mid=174362069 |
http://photo.163.com/q/6710113/?mid=174362069 |
http://photo.163.com/q/6710105/?mid=174362069 |
http://photo.163.com/q/6710099/?mid=174362069 |
http://photo.163.com/q/6710051/?mid=174362069 |
http://photo.163.com/q/6710032/?mid=174362069 |
http://photo.163.com/q/6710012/?mid=174362069 |
http://photo.163.com/q/6710000/?mid=174362069 |
http://photo.163.com/q/6702987/?mid=174362069 |
http://photo.163.com/q/6710518/?mid=174379042 |
http://photo.163.com/q/6710511/?mid=174379042 |
http://photo.163.com/q/6710506/?mid=174379042 |
http://photo.163.com/q/6710502/?mid=174379042 |
http://photo.163.com/q/6710496/?mid=174379042 |
http://photo.163.com/q/6710487/?mid=174379042 |
http://photo.163.com/q/6710477/?mid=174379042 |
http://photo.163.com/q/6710457/?mid=174379042 |
http://photo.163.com/q/6710451/?mid=174379042 |
http://photo.163.com/q/6710432/?mid=174379042 |