PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → What command to use to allow controls to move around
What command to use to allow controls to move around
Iniciado por guest, 16,sep. 2010 09:16 - 5 respuestas
Publicado el 16,septiembre 2010 - 09:16
Hi,
What command in windev to allow the end user to move the controls (eg. button ) around in the window screen?
for example. i've a group of buttons which enduser can click and drag it around the screen ( within the same window ).
Any sample codes will be nice :)
Regards,
PETER ZHOU
Publicado el 16,septiembre 2010 - 15:52
Hello Peter
I don't think there is any command to do that but if you had a datafile set up to hold the formname and a linked file to hold the control names and their x,y locations, you could create a process to allow the user to click on the control they want to move and move the mouse to the new position and register the x,y position for a left mouse down on the screen. You could then save the new x,y position to the link file and move the control to the new position.
Whenever you open a form, you could search the datafile for the formname and move the controls to their user assigned positions that have been recorded in the link file. I would build the window off screen and then move the window onto its normal screen position
Regards
Al
Publicado el 16,septiembre 2010 - 16:00
al's solution is ok but to move all the controls at the same time put then inside a supercontrol and play with supercontrol_name..x / supercontrol_name..y
Publicado el 16,septiembre 2010 - 18:10
Hi Peter,
I use some slightly adapted code from a old Windev example that can drag and drop an image control.
Perhaps it works on buttons too.
ST_Drag is structure
nXInitis int// Initial mouse X location
nYInitis int// Initial mouse Y location
nXPosis int// Frame bottom right location
nYPosis int// Frame top left location
sControl is string// Name of the control moved
END
Drag_Img is ST_Drag
// Initialize the procedure used to manage the event
Event("Drag","",513)// 513=WM_LBUTTONDOWN=left button down
Event("Drag","*.",512)// 512=WM_MOUSEMOVE=mouse move
Event("Drag","*.",514)// 514=WM_LBUTTONUP=left button up
Procedure Drag() // Manage events used to drag controls
nEventNum is int// Number of the event to process
nNewNr,nXPos,nYPos are int// New control locations
nEventNum=_EVE.wMessage// Retrieve the number of the event to process
IF nEventNumQ3 THEN
Drag_Img:sControl=ControlOver(True, True)
// Check if the control can be moved *************************
IF Left(Drag_Img:sControl,2)="LL" THEN
// **********************************************************
// Capture the mouse events (compulsory)
CallDLL32("User32", "SetCapture", Handle(""))
// Store the initial mouse location
Drag_Img:nXInit=LoWord(_EVE.lParam)// Mouse X location
Drag_Img:nYInit=HiWord(_EVE.lParam)// Mouse Y location
Drag_Img:nXPos={Drag_Img:sControl,indControl}..X// Initial control X location
Drag_Img:nYPos={Drag_Img:sControl,indControl}..Y// Initial control Y location
Drag_Img:nCurNr=Val(ExtractString(Drag_Img:sControl,2,"_"))
ELSE
Drag_Img:sControl=""// No control currently moved
END
ELSE IF nEventNumQ2 THEN
// WM_MOUSEMOVE=mouse move
// Check that a control is currently moved
IF Drag_Img:sControl"" THEN
// Calculate the new object coordinates
nXPos=Drag_Img:nXPos+(LoWord(_EVE.lParam)-Drag_Img:nXInit)
nYPos=Drag_Img:nYPos+(HiWord(_EVE.lParam)-Drag_Img:nYInit)
// Check that the control has been moved
IF nXPos={Drag_Img:sControl,indControl}..X AND nYPos={Drag_Img:sControl,indControl}..Y THEN
RETURN
END
// Check that the control is still located on the BACKGROUND image
IF nXPoswin_KlasPlan..Width-20 THEN
nXPos=win_KlasPlan..Width-{Drag_Img:sControl,indControl}..Width-20
END
END
IF nYPoswin_KlasPlan..Height-28 THEN
nYPos=win_KlasPlan..Height-{Drag_Img:sControl,indControl}..Height-28
END
END
// Move the control
{Drag_Img:sControl,indControl}..X=nXPos
{Drag_Img:sControl,indControl}..Y=nYPos
// If the WM_LBUTTONDOWN message is lost.
// Check that the button is still down.
//IF not KeyPress(kpLButton) THEN
//EventNumQ4// To simulate a button up
//END
END
ELSE IF nEventNumQ4 THEN
// WM_lBUTTONUP=left button up
IF Drag_Img:sControl"" THEN
CallDLL32("User32", "ReleaseCapture")
// Calculate the new object coordinates
nXPos=Drag_Img:nXPos+(LoWord(_EVE.lParam)-Drag_Img:nXInit)
nYPos=Drag_Img:nYPos+(HiWord(_EVE.lParam)-Drag_Img:nYInit)
{Drag_Img:sControl,indControl}..X=Drag_Img:nXPos
{Drag_Img:sControl,indControl}..Y=Drag_Img:nYPos
Drag_Img:sControl=""
END
END
Might be useful. I'm curious if it works for buttons too.
Regards, Piet
Publicado el 20,septiembre 2010 - 11:31
Why don't you use the toolbar control ?
Regards Ab
Publicado el 22,mayo 2018 - 16:13
Hi, i was looking to your code for moving images, you are using variables nEventNumQ3, nEventNumQ2 etc. these are not defined in the code. can you tell me its data type? and there are 2 windows as i understand. win_KlasPlan and nXPoswin_KlasPlan, can you tell me what the 2nd one is?