Re: Moving a borderless window - Is there a way?

new topic     » goto parent     » topic index » view thread      » older message » newer message

I have used this algorithm in VB for years. It is as solid as any I know of:


without warning
include win32lib.ew

constant mainWin = create( Window, "Drag test", 0, 0, 0, 300, 100, 0 )

-- we use two global variables. because it is not possible to drag more 
than one window at a time,
-- we only need these two no matter how many windows use them.
sequence refPos
refPos = {0,0}

integer mouseDown
mouseDown = False

procedure mainWin_onMouse(atom event, atom x, atom y, atom shift)
    sequence extent
    sequence size
   
    -- we need to store the position the mouse was at when the button is 
pushed down
    -- otherwise, the window's upper-left corner will "snap" to the 
position of the mouse.
    -- uncomment the second line to see what I mean. this also sets the 
mouseDown flag.
    if event = LeftDown then
        refPos = {x, y}
        --refPos = {0, 0}
        mouseDown = True
    end if
   
    -- if the left mouse button is down, we will now actually move the 
window
    if event = MouseMove and mouseDown then
        -- the extent is used for it's left (1) and top (2) properties
        extent = getRect(mainWin)
        -- getCtlSize is more convienient to use as the 4th and 5th 
arguments to
        -- setRect, because it expects width and height, not right and 
bottom
        size = getCtlSize (mainWin)
       
        -- move the window, and repaint it
        setRect(mainWin,
            extent[1] + x - refPos[1],
            extent[2] + y - refPos[2],
            size[1], size[2], True)
    end if
   
    -- clear the mouseDown flag.
    if event = LeftUp then
        mouseDown = False
        refPos = {0,0}
    end if
end procedure

onMouse[mainWin] = routine_id("mainWin_onMouse")

WinMain(mainWin, Normal)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu