PowerBuilder制作IE风格的图标按钮
2013-08-22 11:25
211 查看
---- 本文介绍在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
相关文章推荐
- PowerBuilder制作IE风格的图标按钮
- VC使用位图和图标制作按钮
- 图标按钮、位图按钮、CBitmapButton 类位图按钮的制作
- Bootstrap风格的按钮 BButton(把图标做成字体,可以省下很多图片资源)
- 制作 Facebook 风格的网页按钮(无需图片)
- 用VC6扩展CButton类制作风格独特的按钮
- css ISO风格 按钮和Table 兼容IE
- 超简单:三秒钟搞定 Axure制作圆形头像或按钮图标!!
- [转]在vc MFC下制作具有XP风格按钮等控件
- MFC实现多风格真彩色大图标工具栏按钮
- 制作风格独特的按钮—用VC6扩展CButton
- VC使用位图和图标制作按钮
- Bootstrap 教程第三课:制作有图标的按钮
- Powerbuilder IE图片按钮
- 在线制作Web2.0风格按钮
- VC使用位图和图标制作按钮
- 用VC6扩展CButton类制作风格独特的按钮
- VC使用位图和图标制作按钮
- Bootstrap 教程第四课:制作一组功能图标按钮