您的位置信息之舟电 脑硬件栏目首页数据库类PowerBuilder 收藏本页

→ PowerBuilder制作IE风格的图标按钮二

www.kepusoft.com 信息之舟电脑软件应用栏目

    信息之舟电脑软件应用栏目编者按: ---- 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

        end if

    else

        // 检测鼠标是否滑出按钮区域?
        if (XPos < 0 or YPos < 0) or (XPos >  
    this.Width or YPos > this.Height) then
            ib_MouseCaptured = FALSE
            ReleaseCapture()

            in_State = 0
            this.PictureName = is_PicNormal

        end if

    end if

    return 1
    //
    // *** end mousemove event ***

    // “LButtonDown” 事件代码
    // *** begin lbuttondown event ***
    //
    rect lr_Border

    if ib_MouseCaptured then
        ib_MouseCaptured = FALSE
        ReleaseCapture()
    end if

    in_State = 2
    this.PictureName = is_PicClickDown

    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!)

        DrawEdge(GetDC(handle(this)),  
    lr_Border, 2, 1+2+4+8)
    end if

    return 1
    //
    // *** end lbuttondown event ***

    // “LButtonUp” 事件代码
    // *** begin lbuttonup event ***
    //
    rect lr_Border

    if ib_MouseCaptured then
        ib_MouseCaptured = FALSE
        ReleaseCapture()
    end if

    if (XPos < 0 or YPos < 0) or (XPos >  
    this.Width or YPos > this.Height) then
        in_State = 0
        this.PictureName = is_PicNormal

    else
        in_State = 1
        this.PictureName = is_PicHover

        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!)
            DrawEdge(GetDC(handle(this)),
    lr_Border, 4, 1+2+4+8)
        end if

    end if

    // 产生Clicked事件
    this.event post clicked()
    return 1

    //
    // *** end lbuttonup event ***

    // “Other” 事件代码
    // *** begin other event ***
    //
    if message.number = 533 and ib_MouseCaptured then
        // wm_CaptureChanged
        ib_MouseCaptured = FALSE
        in_State = 0
        this.PictureName = is_PicNormal
        return 1
    end if

    return 0
    //
    // *** end other event ***
    ----  四、简要说明  

    ---- 1、ib_MouseCaptured变量是作为MouseMove事件的刷新控件图片的信号灯及判断是否已安装了鼠标捕捉器;  

    ---- 2、sb_SuppressHoverBorder变量,默认值为FALSE,当值为TRUE时,控件不绘制凸或凹边框;  

    ---- 3、“Other”事件,当鼠标捕捉器被释放或被替换时会触发WM_CAPTURECHANGED事件,例如:您在Clicked事件中调用MessageBox函数时,将触发WM_CAPTURECHANGED事件,在此事件代码中恢复按钮到Normal状态。

www.kepusoft.com 信息之舟电脑之家收集整理推荐文章