Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Move a toolbar by dragging on child control vs. border/title
Message
From
29/05/2005 14:55:40
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Move a toolbar by dragging on child control vs. border/title
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01018452
Message ID:
01018452
Views:
53
Sample copy and paste code follows my signature

I would like a user to be able to click on a child control of a toolbar and via a standard click and drag motion move the associated toolbar. The reason I'm not using a titlebar's native margins or titlebar is because I plan on stripping away this "chrome" so my toolbar seemlessly blends in with my interface.

For the task at hand, I am using a standard, undocked toolbar control to build a proof-of-concept solution. The technique I'm using works great for moving standard controls and forms. (Thanks to Craig Boyd for this solution)

... but when I use this technique with a child control of a toolbar, I get violent flashing (repainting?) of the toolbar window during the MouseMove event. Yes, the toolbar does move (somewhat), but the mouse pointer begins to fall out of synch with the toolbar and the entire effect is messy.

I've tried wrapping the actual toolbar move event with LockScreen without success. I've also tried wrapping the .Move() method with the LockWindowUpdate() API. This later technique eliminates the violent toolbar painting behavior, but fails to properly update (paint) the toolbar control thats being moved. I've also tried inserting a doevent() before, after, and before/after the Move() method with no improvement.

Any suggestions on how I can achieve my goal?

Thank you,
Malcolm

Copy and paste code. Copy to prg file, run it. Click and drag on the label captioned "Click and drag me!" to move the toolbar and see the effects I'm talking about.
public oToolbarTest
oToolbarTest = createobject( "clsToolbarTest" )
oToolbarTest.Show()

* standard toolbar 
define class clsToolbarTest as Toolbar

  ShowWindow = 1 && in top level form

  add object cntMain as Container with height = 100, width = 200
	
  function Init()
    * add object that manages the move
    This.cntMain.AddObject( "oMover", "clsMover" )
    This.cntMain.oMover.Move( 10, 6 )

    * register this toolbar as the object to move
    This.cntMain.oMover.oLinkedObject = This
    This.cntMain.oMover.Visible = .T.
  endfunc
	
enddefine


* custom label class that captures move request and transfers to linked object
define class clsMover as Label 

  Caption   = "Click and drag me!"
  BackStyle = 0
  AutoSize  = .T.

  * holds reference to object being moved
  oLinkedObject = .Null.

  * remember mouse position at start of drag
  OriginalXpos = 0
  OriginalYpos = 0

  * remember original object being moved's position
  OriginalLeft = 0
  OriginalTop  = 0

  * clear linked object
  function Destroy()
    This.oLinkedObject = .Null.
  endfunc

  function MouseDown
  lparameters nButton, nShift, nXCoord, nYCoord
    if nButton = 1 and vartype( This.oLinkedObject ) == "O"
      with This
        .OriginalXpos = nXCoord
        .OriginalYpos = nYCoord
        .OriginalLeft = This.oLinkedObject.Left
        .OriginalTop  = This.oLinkedObject.Top
      endwith
    endif
  endfunc

  function MouseMove
  lparameters nButton, nShift, nXCoord, nYCoord
    if nButton = 1 and vartype( This.oLinkedObject ) == "O"
      with this
            
        *!* DECLARE INTEGER GetDesktopWindow IN WIN32API
        *!* DECLARE INTEGER LockWindowUpdate IN WIN32API INTEGER lnHandle
        *!* local lnDesktopWin
        *!* lnDeskTopWin = GetDeskTopWindow()
        *!* = LockWindowUpdate(lnDeskTopWin)

        local lnLeft, lnTop
        lnLeft = .OriginalLeft + ( nXCoord - .OriginalXpos )
        lnTop  = .OriginalTop  + ( nYCoord - .OriginalYpos )

        * doesn't appear to affect problem
        *!* doevents && doesn't affect problem
        
        * HERE'S THE CAUSE OF THE FLASHY PAINTING EFFECT !!!
        .oLinkedObject.Move( lnLeft, lnTop )
        
        *!* doevents && doesn't affect problem

        *!* = LockWindowUpdate(0)
      endwith
    endif
  endfunc

enddefine
Malcolm Greene
Brooks-Durham
mgreene@bdurham.com
Next
Reply
Map
View

Click here to load this message in the networking platform