Jump to content


Photo

how to limit dragging area ?


  • Please log in to reply
17 replies to this topic

#1 Klark92

Klark92
  • Members
  • 854 posts

Posted 28 April 2012 - 03:28 PM

Like gui allows only dragging to listbox or Static text control ... ?

#2 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 29 April 2012 - 12:25 AM

Do you mean ignore the drop when the user tries to drop files on specific controls ?


The following built-in variables are available within GuiDropFiles:
1. A_GuiControl, which contains the text or variable name of the control upon which
the files were dropped (blank if none).
2. A_EventInfo and ErrorLevel, which both contain the number of files dropped.
3. A_GuiX and A_GuiY, which contain the X and Y coordinates of where the files were
dropped (relative to the window's upper left corner).
4. A_GuiEvent, which contains the names of the files that were dropped, with each
filename except the last terminated by a linefeed (`n).


GuiDropFiles:
if A_GuiControl in Button1, Button2, Button3
  return ; ignore the drop

;-- else accept the files ----
return


#3 Klark92

Klark92
  • Members
  • 854 posts

Posted 29 April 2012 - 05:45 PM

I did not work that " if "... sorry, do you have an example ?

#4 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 29 April 2012 - 11:33 PM

I did not work that " if "... sorry, do you have an example ?

I do not have an example other than the partial idea I posted.

I asked a question and you did not respond to it.
Please explain what you want in more detail.

Please post an example script and tell us what you want.

#5 Klark92

Klark92
  • Members
  • 854 posts

Posted 30 April 2012 - 12:26 AM

sorry I didnt read carefully ..

I want only listboxes accept dropping a file ? Not Background or other controls ...

Gui, Add, ListBox, x15 y10 w195 h230, ListBox
Gui, Add, ListBox, x220 y10 w195 h225, ListBox2
Gui, Add, Edit, x20 y260 w190 h20, Edit
Gui, Add, Button, x315 y260 w100 h30, Button
Gui, Show, w430 h302, Gui
Return

GuiClose:
ExitApp


#6 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 30 April 2012 - 02:08 AM

Gui, Add, ListBox, x15 y10 w195 h230 vListBox, Red|Green|Blue|Black|White

Gui, Add, ListBox, x220 y10 w195 h225 vListBox2 Red|Green|Blue|Black|White

Gui, Add, Edit, x20 y260 w190 h20, Edit

Gui, Add, Button, x315 y260 w100 h30, Button

Gui, Show, w430 h302, Gui

Return



GuiClose:

ExitApp





GuiDropFiles:



if A_GuiControl not contains Listbox

{

  tooltip, Sorry`, Klark92 says you must drop files in Listboxes `r%A_GuiControl% doesn't qualify

  return ; ignore the drop



}

;-- else accept the files ----



msgbox  You dropped files on %A_GuiControl%`rThere were %A_EventInfo% files`rThe location was %A_GuiX%`,%A_GuiY%`rThe list of files is %A_GuiEvent%



return


#7 just me

just me
  • Members
  • 1175 posts

Posted 30 April 2012 - 06:04 AM

; Should work with AHK Basic, too!
#NoEnv
; WS_EX_ACCEPTFILES := 0x00000010
Gui, Add, ListBox, x15 y10 w195 h230 +E0x10 HwndHLB1 vListBox1, ListBox
Gui, Add, ListBox, x220 y10 w195 h225 +E0x10 HwndHLB2 vListBox2, ListBox2
Gui, Add, Edit, x20 y260 w190 h20, Edit
Gui, Add, Button, x315 y260 w100 h30, Button
Gui, Show, w430 h302, Gui
GoSub, NoDropOnGUI
Return

GuiClose:
ExitApp

GuiDropFiles:
   ; We cannot rely on A_GuiControl in this context (AHK 1.1.07.03 U32).
   ; So we have to get the control using MouseGetPos
   MouseGetPos, , , , HDROP, 2
   If (HDROP = HLB1)
      DropTarget := "ListBox1"
   Else  ; because there are only two controls
      DropTarget := "ListBox2"
   MsgBox, 0, Dropped!, You dropped`r`n`r`n%A_GuiEvent%`r`n`r`non %DropTarget%!`r`n`r`nA_GuiControl: %A_GuiControl%
   SetTimer, NoDropOnGUI, -100 ; Seems to be needed after dropping
Return

NoDropOnGUI:
   Gui, +LastFound
   Gui, -E0x10
   WinActivate
Return
A little closer?

#8 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 30 April 2012 - 06:21 AM

GuiDropFiles:
   ; We cannot rely on A_GuiControl in this context (AHK 1.1.07.03 U32).
   ; So we have to get the control using MouseGetPos


Can you elaborate on this statement ?

#9 Klark92

Klark92
  • Members
  • 854 posts

Posted 30 April 2012 - 08:47 AM

@just me : when I drag a file to Listbox2 your message says me A_GuiControl is Listbox1 .. I didnt understand that :)

Finally it works. Thanks a lot leef_me ! :)

#10 just me

just me
  • Members
  • 1175 posts

Posted 30 April 2012 - 08:48 AM

A_GuiControl does always contain the name of the first input-capable control in this case. I don't know whether this issue relies on my AHK version, or not.

#11 Klark92

Klark92
  • Members
  • 854 posts

Posted 30 April 2012 - 09:08 AM

okay .. but your method is cool for one control..

#12 just me

just me
  • Members
  • 1175 posts

Posted 30 April 2012 - 11:29 AM

It works for more than one control, you just can't use A_GuiControl.

#13 Klark92

Klark92
  • Members
  • 854 posts

Posted 30 April 2012 - 04:10 PM

new edit x) : for leef me's method, the mouse pointer is not change when mouse on unwanted controls ... but your method is pretty cool ...

#14 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 30 April 2012 - 04:28 PM

It works for more than one control, you just can't use A_GuiControl.

Your statement seems contrary to the information published in the docs.
<!-- m -->http://l.autohotkey.... ... iDropFiles<!-- m -->

:?: Can you provide an example that supports your statement ?

#15 just me

just me
  • Members
  • 1175 posts

Posted 30 April 2012 - 07:56 PM

@Leef_me: Just try my script and look at the value of A_GuiControl reported in the MessageBox. And observe that WS_EX_ACCEPTFILES is removed from the Gui window, that's the whole trick!