Loading ...
Sorry, an error occurred while loading the content.
 

MoveWindow API

Expand Messages
  • mzxgiant
    I m trying to create a subroutine that moves a pop-up style window (with a graphics box completely covering the size of the window) so that when one clicks
    Message 1 of 3 , Jan 31, 2005
      I'm trying to create a subroutine that moves a pop-up style window
      (with a graphics box completely covering the size of the window) so
      that when one clicks inside the window (or rather, essentially in the
      graphics box) and drags, the window moves around the screen...

      I figured make a trap that says when the user left-clicks, take the
      current position of the mouse, and when they drag, figure out the new
      position of the mouse, and figure out like NewX-OldX and NewY-OldY,
      then add that change to the original UpperLeftX/Y of the window...
      all the calculations work fine, but when I pass them into the API
      (user32, MoveWindow) the window doesn't move at all. I added debug
      strings into the program to show me what the new UpperLeft is supposed
      to be, but the window itself never moves.

      Code so far:
      (in the init code for the window/gfxbox)
      print #main.console, "when leftButtonDown [getmousexy]"
      print #main.console, "when leftButtonMove [moveconsole]"
      [moveconsole]
      deltay = MouseY - oldmousey
      deltax = MouseX - oldmousex
      UpperLeftX = UpperLeftX + deltax
      UpperLeftY = UpperLeftY + deltay
      if UpperLeftX < 0 then UpperLeftX = 0
      if UpperLeftY < 0 then UpperLeftY = 0
      hMain = hwnd(#main)
      print "DeltaX: ";deltax
      print "DeltaY: ";deltay
      print "UpperLeftX: ";UpperLeftX
      print "UpperLeftY: ";UpperLeftY
      print "HWnd: ";hMain
      result = movecadrid(UpperLeftX,UpperLeftY,hMain,xsize,ysize)
      print "Result: ";result
      goto [receive] ' <- a loop later in the program
      [getmousexy]
      oldmousex = MouseX
      oldmousey = MouseY
      goto [receive] ' <- a loop later in the program
      function movecadrid(UpperLeftX,UpperLeftY,hMain,xsize,ysize)
      calldll #user, "MoveWindow", _
      hMain as ulong, _
      UpperLeftX as long, _
      UpperLeftY as long, _
      xsize as long, _
      ysize as long, _
      1 as long, _
      result as boolean
      end function

      Any ideas? =/
    • John Davidson
      ... the ... Here s one way mzxgiant. Not perfect but may point you in the right direction. You might want to check the Newsletters and the Liberty BASIC 4
      Message 2 of 3 , Jan 31, 2005
        --- In libertybasic@yahoogroups.com, "mzxgiant" <MZXGiant@t...> wrote:
        >
        >
        > I'm trying to create a subroutine that moves a pop-up style window
        > (with a graphics box completely covering the size of the window) so
        > that when one clicks inside the window (or rather, essentially in
        the
        > graphics box) and drags, the window moves around the screen...
        >

        Here's one way mzxgiant.
        Not perfect but may point you in the right direction.

        You might want to check the Newsletters and the Liberty BASIC 4
        Companion for more in depth tutelage.


        John Davidson
        e-me: johnshomeport@...
        home: http://www.geocities.com/johnshomeport/
        Did ya Libby yet? http://lblibby.com/


        nomainwin
        WindowWidth=150
        WindowHeight=100
        UpperLeftX=int((DisplayWidth-WindowWidth)/2)
        UpperLeftY=int((DisplayHeight-WindowHeight)/2)

        ' Initialize for move
        cursorX=UpperLeftX
        cursorY=UpperLeftY
        oldMouseX=1
        BackgroundColor$="darkcyan"

        button #main.b1,"Close",[quit.Main],ul,35,70,75,22
        graphicbox #main.console,0,0,100,50
        open "" for window_popup as #main

        h=hWnd( #main)
        print #main.console, "when leftButtonMove [moveconsole]"

        wait
        [quit.Main]
        close #main
        end

        [moveconsole]
        struct point,x as long, y as long
        ' used 50 20 to center up on the graphicbox
        point.x.struct =50 'screen x position to translate
        point.y.struct =25 'screen y position to translate

        calldll #user32, "ScreenToClient",_
        h as long,_ 'window handle
        point as struct,_ 'name of struct
        r as long

        'Calculate the position
        '1. Get the Client area
        ' point.x.struct is UpperLeftX
        ' point.y.struct is UpperLeftY
        '2. Subtract client corner from the current mouse position.

        cursorX=(MouseX-point.x.struct)
        cursorY=(MouseY-point.y.struct)

        if oldMouseX<>MouseX or oldMouseY<>MouseY then
        oldMouseX=MouseX
        oldMouseY=MouseY
        'Used a SUB because no return is required.
        call movecadrid cursorX,cursorY,_
        hwnd(#main),WindowWidth,WindowHeight

        end if
        wait

        SUB movecadrid ulx,uly,hMain,width,height
        calldll #user32, "MoveWindow", _
        hMain as ulong, _
        ulx as long, _
        uly as long, _
        width as long, _
        height as long, _
        1 as long, _
        result as boolean
        END SUB
      • Brent Thorn
        I posted a more elegant solution to this back on December 3, 2004 in message #23530. I can repost if you can t find it. -Brent http://members.aol.com/b6sw ...
        Message 3 of 3 , Jan 31, 2005
          I posted a more elegant solution to this back on December 3, 2004 in
          message #23530. I can repost if you can't find it.

          -Brent

          http://members.aol.com/b6sw

          --- In libertybasic@yahoogroups.com, "mzxgiant" <MZXGiant@t...> wrote:
          >
          >
          > I'm trying to create a subroutine that moves a pop-up style window
          > (with a graphics box completely covering the size of the window) so
          > that when one clicks inside the window (or rather, essentially in
          the
          > graphics box) and drags, the window moves around the screen...
          >
          > I figured make a trap that says when the user left-clicks, take the
          > current position of the mouse, and when they drag, figure out the
          new
          > position of the mouse, and figure out like NewX-OldX and NewY-OldY,
          > then add that change to the original UpperLeftX/Y of the window...
          > all the calculations work fine, but when I pass them into the API
          > (user32, MoveWindow) the window doesn't move at all. I added debug
          > strings into the program to show me what the new UpperLeft is
          supposed
          > to be, but the window itself never moves.
          >
          > Code so far:
          > (in the init code for the window/gfxbox)
          > print #main.console, "when leftButtonDown [getmousexy]"
          > print #main.console, "when leftButtonMove [moveconsole]"
          > [moveconsole]
          > deltay = MouseY - oldmousey
          > deltax = MouseX - oldmousex
          > UpperLeftX = UpperLeftX + deltax
          > UpperLeftY = UpperLeftY + deltay
          > if UpperLeftX < 0 then UpperLeftX = 0
          > if UpperLeftY < 0 then UpperLeftY = 0
          > hMain = hwnd(#main)
          > print "DeltaX: ";deltax
          > print "DeltaY: ";deltay
          > print "UpperLeftX: ";UpperLeftX
          > print "UpperLeftY: ";UpperLeftY
          > print "HWnd: ";hMain
          > result = movecadrid(UpperLeftX,UpperLeftY,hMain,xsize,ysize)
          > print "Result: ";result
          > goto [receive] ' <- a loop later in the program
          > [getmousexy]
          > oldmousex = MouseX
          > oldmousey = MouseY
          > goto [receive] ' <- a loop later in the program
          > function movecadrid(UpperLeftX,UpperLeftY,hMain,xsize,ysize)
          > calldll #user, "MoveWindow", _
          > hMain as ulong, _
          > UpperLeftX as long, _
          > UpperLeftY as long, _
          > xsize as long, _
          > ysize as long, _
          > 1 as long, _
          > result as boolean
          > end function
          >
          > Any ideas? =/
        Your message has been successfully submitted and would be delivered to recipients shortly.