Drag (and drop) met API

Alles over het toepassen van API en DLL's in Liberty BASIC

Moderator: anthonio

Drag (and drop) met API

Berichtdoor Gordon » za jul 14, 2007 4:15 pm

Hallo,

Ik heb uit het Franse forum http://lbasic.pleug.com/forum/ en daarna
uit het sub forum OPEN SOURCE een listing gehaald.

Deze listing maakt gebruik van drag en drop door middel van een
API.

Hier is de listing te downloaden
http://perso.orange.fr/mc-c/postitlb.zip

De listing is van Macsou.
Code: Selecteer alles
nomainwin

    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    WindowWidth = 250
    WindowHeight = 395

    loadbmp "apercu", "apercu.bmp"

    textbox #win.titre, 5,5,235,20
    texteditor #win.contenu, 5,30,235,103
    button #win.ok, "Aperçu", [aperçu], UL, 5,140,235,20
    graphicbox #win.g, 45,165,150,150
    button #win.ok, "OK", [postit], UL, 5,320,235,20
    button #win.aide, "Aide", [aide], UL, 5,345,235,20

    open "Post-it" for window_nf as #win
    #win.g "flush"
    #win.g "drawbmp apercu 0 0"
    #win.g "flush"
    #win.titre "Titre du post-it"
    infoc$ = "Contenu du post-it"
    #win.contenu "!insert infoc$"
    #win "trapclose [quitwin]"
    call NoEdit
wait

Sub NoEdit
    hMain=hWnd(#win)
    hMainMenu=GetMenu(hMain)
    hMainEdit=GetSubMenu(hMainMenu,0)
    result=RemoveMenu(hMainMenu,hMainEdit)
    Call DrawMenuBar hWnd(#win)
    End Sub

Sub DrawMenuBar hWnd
    CallDLL #user32, "DrawMenuBar",_
    hWnd As long, r As boolean
    End Sub

Function GetSubMenu(hMenuBar,nPos)
    CallDLL #user32, "GetSubMenu",_
    hMenuBar As long, nPos As long,_
    GetSubMenu As long
    End Function

Function GetMenu(hWnd)
    CallDLL #user32, "GetMenu",hWnd As long,_
    GetMenu As long
    End Function

Function RemoveMenu(hMenu,hSubMenu)
    CallDLL #user32, "RemoveMenu", hMenu As long,_
    hSubMenu As long, _MF_BYCOMMAND As long,_
    RemoveMenu As boolean
    End Function

[aperçu]
    #win.g "cls"
    #win.g "drawbmp apercu 0 0"
    #win.titre "!contents? titre$"
    #win.g "font Verdana 7"
    #win.g "backcolor 255 255 115"
    #win.g "color 51 51 51"
    #win.g "place 35 17"
    #win.g "\";titre$
    #win.g "flush"
    #win.contenu "!contents? contenu$"
    #win.g "place 10 40"
    #win.g "\";contenu$
    #win.g "flush"
wait

[aide]
    notice "Aide"+chr$(13)+_
        "Pour aller à la ligne pour le contenu du post-it, ne faites pas entrée car ça fait"+chr$(13)+_
        "un espace trop grand entre les lignes."+chr$(13)+_
        "Utilisez donc ce signe : \ ( Alt Gr+8 ) sans aucun retour à la ligne."+chr$(13)+_
        "Il faut redémarrer le logiciel pour recréer un post-it."
wait

[quitwin]
win = 1
if main = 1 then
        close #win
    end
else
        close #win
    wait
end if

[postit]
#win.ok "!disable"
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    WindowWidth = 150
    WindowHeight = 150

    #win.titre "!contents? titre$"
    #win.contenu "!contents? contenu$"


    loadbmp "drag", "drag.bmp"
    loadbmp "close", "close.bmp"
    loadbmp "main", "main.bmp"

    graphicbox #main.close, 140,0,10,10
    graphicbox #main.drag, 140,140,10,10
    graphicbox #main.maing, 0,0,150,150

    stylebits #main,0,0,_WS_EX_TOOLWINDOW,0
    open "" for window_popup as #main
    #main "trapclose [quit]"
    #main.drag "flush"
    #main.drag "drawbmp drag 0 0"
    #main.drag "flush"
    #main.drag "when leftButtonMove [drag]"
    #main.drag "when leftButtonUp [main]"
    #main.close "drawbmp close 0 0"
    #main.close "flush"
    #main.close "when leftButtonDown [quit]"
    #main.maing "drawbmp main 0 0"
    #main.maing "font Verdana 7"
    #main.maing "backcolor 255 255 115"
    #main.maing "color 51 51 51"
    #main.maing "place 35 17"
    #main.maing "\";titre$
    #main.maing "place 10 40"
    #main.maing "\";contenu$
    #main.maing "flush"
    struct POINTAPI, _
    X as long, _
    Y as long
    hd = hwnd(#main)
[main]
wait

[drag]
   scan
   calldll #user32, "GetCursorPos", POINTAPI As struct, r As Long
        x = POINTAPI.X.struct
        y = POINTAPI.Y.struct
        x = x-145
        y = y-145
   calldll #user32, "SetWindowPos", _
        hd as long, _
        0 as long, _
        x as long, _
        y as long, _
        150 as long, _
        150 as long, _
        _SWP_NOZORDER as long, _
        result as long
   goto [drag]
wait

[quit]
    main = 1
if win = 1 then
        close #main
    end
else
        close #main
    wait
end if


Hartelijk dank Macsou.

Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Berichtdoor Gordon » zo jul 15, 2007 6:01 pm

Het drag and drop gedeelte zit in:
Code: Selecteer alles
    struct POINTAPI, _
    X as long, _
    Y as long
    hd = hwnd(#main)
wait

[drag]
   scan
   calldll #user32, "GetCursorPos", POINTAPI As struct, r As Long
        x = POINTAPI.X.struct
        y = POINTAPI.Y.struct
        x = x-145
        y = y-145
   calldll #user32, "SetWindowPos", _
        hd as ulong, _
        0 as long, _
        x as long, _
        y as long, _
        150 as long, _
        150 as long, _
        _SWP_NOZORDER as long, _
        result as long
   goto [drag]
wait


De cursorpositie wordt gezocht en daarna wordt het venster met
handle nummer hd=hWnd(#main) op de positie van de cursor geplaatst
tot u niet meer sleept met de cursor (when leftButtonMove).

Dit is knap werk voor vensters.
Helaas moest ik (met de hulp van Janet) zelf een routine
ontwikkelen om sprites te draggen en droppen. Sprites hebben
geen Windows handle nummer.

Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am


Keer terug naar API/DLL

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron