Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WMLiberty Demos - Dragging a popup window
 
WMLiberty -> Demos -> Window Enhancements -> Dragging a popup window (Download)

Code:
' Dragging Popup Window Demo
' By Brent D. Thorn, 2006
' PUBLIC DOMAIN
' This demo uses the WMLiberty DLL to trap the mouse's left-click in a
' popup-type window as a means to move the window around on the screen.

    NoMainWin

    WindowWidth = 320
    WindowHeight = 320

    ' Place static text over most of the window.
    ' And make it with a sunken-looking frame.
    StaticText #pop.lbl, "", 9, 9, 300, 300
    StyleBits  #pop.lbl, _SS_SUNKEN, 0, 0, 0

    Open "" For Window_Popup As #pop

    #pop "TrapClose Quit"
    #pop "Font Arial 16"

    #pop.lbl "This is a popup-type window. " + _
             "You can drag it around with the left mouse button. " + _
             "This works even if it is covered by a statictext control. " + _
             "Press Alt+F4 to exit."

    Open "WMLiberty" For DLL As #wmlib

    ' Get the handle of the window.
    hWnd = HWnd(#pop)

    ' Get the pointer to the function that handles the event.
    Callback lpfn, OnLButtonDown ( ULong, ULong, ULong, ULong ), Long

    ' Set up the handler for the "left button down" event.
    ' The "success" parameter is "1" so that the handler
    ' function won't interfere with the message's default
    ' processing by returning the (default) value of zero.
    CallDLL #wmlib, "SetWMHandler", _
        hWnd As ULong, _
        _WM_LBUTTONDOWN As ULong, _
        lpfn As ULong, _
        1 As Long, _
        ret As Long

        Call DoEvents

Sub DoEvents
' WMLiberty requires a Scan loop.
[Loop]
    Scan
    CallDLL #kernel32, "Sleep", _
        50 As Long, _
        ret As void
    GoTo [Loop]
End Sub

Sub Quit Me$
    ' WMLiberty requires windows to be closed before it is.
    Close #Me$

    Close #wmlib
    End
End Sub

' _WM_LBUTTONDOWN event handler.
Function OnLButtonDown ( hWnd, uMsg, wParam, lParam )
    ' Release mouse's capture of the window.
    CallDLL #user32, "ReleaseCapture", _
        ret As void

    ' Tell the window its caption is being dragged. It's all
    ' a big lie, but then the window doesn't know any better.
    CallDLL #user32, "SendMessageA", _
        hWnd As ULong, _
        _WM_NCLBUTTONDOWN As ULong, _
        _HTCAPTION As Long, _
        0 As Long, _
        ret As Long
End Function

Powered by phpBB © 2001, 2005 phpBB Group