如何模拟一个象窗体一样的控件(标题栏、焦点、拖动、改变大小、关闭等等)[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 sor 的 blog

二、声明

' wm_nchittest and mousehookstruct mouse position codes
const hterror = (-2)
const httransparent = (-1)
const htnowhere = 0
const htclient = 1
const htcaption = 2
const htsysmenu = 3
const htgrowbox = 4
const htsize = htgrowbox
const htmenu = 5
const hthscroll = 6
const htvscroll = 7
const htminbutton = 8
const htmaxbutton = 9
const htleft = 10
const htright = 11
const httop = 12
const httopleft = 13
const httopright = 14
const htbottom = 15
const htbottomleft = 16
const htbottomright = 17
const htborder = 18
const htreduce = htminbutton
const htzoom = htmaxbutton
const htsizefirst = htleft
const htsizelast = htbottomright


const wm_size = &h5

const wm_nclbuttondown = &ha1
const htcaption = 2
const wm_close = &h10

const wm_lbuttondown = &h201
const mk_lbutton = &h1
const wm_mousemove = &h200
private declare function releasecapture lib "user32" () as long
private declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long

 

三、代码

'拖动
private sub pictitle_mousedown(button as integer, shift as integer, x as single, y as single)
    if button = 1 then
        releasecapture
        sendmessage usercontrol.hwnd, wm_nclbuttondown, htcaption, 0&
    end if
end sub

private sub usercontrol_resize()
    on error resume next
    closebt = true
   
    cmdback.left = 0
    cmdback.width = usercontrol.width
    cmdback.top = 0
    cmdback.height = usercontrol.height
   
    pictitle.left = 60
    pictitle.top = 60
    pictitle.width = usercontrol.width - 150
    pictitle.height = 255
   
    imgclose(0).top = 30
    imgclose(0).left = pictitle.width - 240
    imgclose(0).visible = closebt
    imgclose(1).top = 30
    imgclose(1).left = pictitle.width - 240
    imgclose(1).visible = (not closebt)
   
    lstcolumn.left = 60
    lstcolumn.top = pictitle.height + 60
    lstcolumn.width = usercontrol.width - lstcolumn.left - 60
    lstcolumn.height = usercontrol.height - lstcolumn.top - 60
   
    lbltitle.top = 60
    lbltitle.left = 300
    lbltitle.width = pictitle.width - 720
end sub
private sub cmdback_mousedown(button as integer, shift as integer, x as single, y as single)
    dim mvdir as integer
    if button <> 1 then exit sub
    releasecapture
   
    if (x <= 60 and y <= 60) then
        mvdir = httopleft
    elseif (cmdback.width - x <= 60 and cmdback.height - y <= 60) then
        mvdir = htbottomright
    elseif (x <= 60 and cmdback.height - y <= 60) then
        mvdir = htbottomleft
    elseif (y <= 60 and cmdback.width - x <= 60) then
        mvdir = httopright
    elseif y <= 60 and x > 60 and cmdback.width - x > 60 then
        mvdir = httop
    elseif cmdback.height - y <= 60 and x > 60 and cmdback.width - x > 60 then
        mvdir = htbottom
    elseif x <= 60 and y > 60 and cmdback.height - y > 60 then
        mvdir = htleft
    elseif cmdback.width - x <= 60 and y > 60 and cmdback.height - y > 60 then
        mvdir = htright
    end if
   
    sendmessage usercontrol.hwnd, wm_nclbuttondown, mvdir, 0&
    sendmessage usercontrol.hwnd, wm_size, 0, 0
    usercontrol_resize
    lstcolumn.setfocus
end sub

private sub cmdback_mousemove(button as integer, shift as integer, x as single, y as single)
    if (x <= 60 and y <= 60) then
        cmdback.mousepointer = 8

本文关键:可变大小的控件
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top