Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[SOLVED] Binding area of GuiDropFiles


  • Please log in to reply
12 replies to this topic
Ronins
  • Members
  • 120 posts
  • Last active: Apr 18 2016 10:54 PM
  • Joined: 11 Apr 2012
Hey guys,

i'd lyk to bind the area of GuiDropFiles. I want this to happen to a specific area. For example, i'd lyk the area to be left half of my GUI. Other than that, U cant drop files anywhere else. I thought i can bind using mousegetpos, but the problem is that, the-drag-n-drop-icon still appears in the "no dropzone" area. Any help?

Cephei1
  • Members
  • 396 posts
  • Last active: Jan 22 2014 08:19 PM
  • Joined: 04 Aug 2008
#Persistent

#SingleInstance, Force



[color=#40BF00]; Top Left Corner of region[/color]

RegionX = 100

RegionY = 100

[color=#40BF00];Bottom Right Corner of region

[/color]RegionW = 300

RegionH = 300



Gui, Add, Text, x%RegionX% y%RegionY% w%RegionW% h%RegionH% Border Center, Drop Files Here

Gui, Show, w800 h600

Return



GuiDropFiles:

	If ( (A_GuiX >= RegionX) && (A_GuiX <= RegionX+RegionW) && (A_GuiY >= RegionY) && (A_GuiY <= RegionY+RegionH) )

	{

		MsgBox, File dropped: %A_GuiEvent%

	}

	Else

	{

		MsgBox, File dropped outside of the region specified

	}

Return


Ahk_L (Unicode 32-bit)


Ronins
  • Members
  • 120 posts
  • Last active: Apr 18 2016 10:54 PM
  • Joined: 11 Apr 2012

#Persistent
#SingleInstance, Force

[color=#40BF00]; Top Left Corner of region[/color]
RegionX = 100
RegionY = 100
[color=#40BF00];Bottom Right Corner of region
[/color]RegionW = 300
RegionH = 300

Gui, Add, Text, x%RegionX% y%RegionY% w%RegionW% h%RegionH% Border Center, Drop Files Here
Gui, Show, w800 h600
Return

GuiDropFiles:
	If ( (A_GuiX >= RegionX) && (A_GuiX <= RegionX+RegionW) && (A_GuiY >= RegionY) && (A_GuiY <= RegionY+RegionH) )
	{
		MsgBox, File dropped: %A_GuiEvent%
	}
	Else
	{
		MsgBox, File dropped outside of the region specified
	}
Return


That i know, but there is sort of cursor problem. If u bring file to the outside area, cursor still shows "droppable" zone. In normal window, where guidropfiles is not specified, when u dragdrop file, "invalid" cursor is shown. I want that cursor thingy

Cephei1
  • Members
  • 396 posts
  • Last active: Jan 22 2014 08:19 PM
  • Joined: 04 Aug 2008
Can you post your code then I could try and understand better and debug it. Also are you using AHK basic or Ahk_L?

Ahk_L (Unicode 32-bit)


Roninz
  • Guests
  • Last active:
  • Joined: --
Using same code as urs. M using ahk l. I'll post screenshots of kind of result that i want

Cephei1
  • Members
  • 396 posts
  • Last active: Jan 22 2014 08:19 PM
  • Joined: 04 Aug 2008
The code above works in both AHK and AHK_L - I tried it in both. The code works flawlessly for me.

Ahk_L (Unicode 32-bit)


Roninz
  • Guests
  • Last active:
  • Joined: --
Code is flawless, i know, i made more or less the same code. But right now, m talking about cursor. Observe the difference in cursors when u drop files on gui(s) with n without guidropfile

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

The code above works in both AHK and AHK_L...

...the problem is not really the code, it's the fact that once you use GuiDropFiles, AutoHotkey will show the "yes you can drop files here" mouse cursor all the time, even if you use extra code to "detect" where the drop occurred & take different action in the script, the user still gets the feedback (mouse pointer icon) that they can drop anywhere, even if you don't want them to.

AutoHotkey needs to be changed, to allow more control over GuiDropFiles...we need to be able to specify an exact area that is "droppable", so that AutoHotkey can tell the OS that, so the mouse cursor can change to indicate "droppableness".

You could probably remove GuiDropFiles & then use an entire DllCall/OnMessage approach & get more control over the file drop notifications. But the bottom line is, that currently, in regards to mouse pointer indications of being able to drop, GuiDropFiles is "all or nothing"...either the entire Gui will "look droppable" or "look non-droppable".

I did a some searching, it may be a little easier than I thought, it could be as simple as calling DragAcceptFiles, as the mouse is moved over the Gui...(this is a WinAPI function, not an AutoHotkey function, so you need DllCall).

I will do some testing & post code, if I get somewhere.
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

Cephei1
  • Members
  • 396 posts
  • Last active: Jan 22 2014 08:19 PM
  • Joined: 04 Aug 2008
Yeh I figured that out little while ago :) Take a look at this on changing the cursor and see if you can put together a code. I have to go unfortunately. Can't play around with it right now.
http://www.autohotke...opic.php?t=6107
This is also under the Ahk_L Documentation under "DllCall" section. Go to the bottom where there are examples.

Good luck!

Ahk_L (Unicode 32-bit)


Ronins
  • Members
  • 120 posts
  • Last active: Apr 18 2016 10:54 PM
  • Joined: 11 Apr 2012
ok, i got a workaround here. I can use 2 seperate GUIs, stick them one above another. So if the file is over base one, it'll show "dont drop here" cursor, while on above GUI, it will show "drop here" cursor. Will work on code tomorrow. Any other ideas?

just me
  • Members
  • 1496 posts
  • Last active: Nov 03 2015 04:32 PM
  • Joined: 28 May 2011
Once again:
#NoEnv
WM_DROPFILES := 0x0233 ; window message
WS_EX_ACCEPTFILES := [color=#BF0000]0x10[/color] ; extended window style
Gui, Margin, 0, 0
Gui, Add, Text, w300 h300 [color=#BF0000]+E0x10[/color] HwndHDROP +Border, Files can be dropped within the borders!
Gui, Add, Edit, x50 y50 w200 h200 HwndHEDIT, Drop target!
Gui, Add, Button, xp y+10, Just a button!
Gui, Add, Edit, x320 y50 w160 h200, Don't accept files!
Gui, Show, w500 h350, Drag&Drop
DropTarget := HEDIT
OnMessage(WM_DROPFILES, "On_WM_DROPFILES")
Return

On_WM_DROPFILES(WParam, LParam, Msg, HWND) {
   ; http://msdn.microsoft.com/en-us/library/bb774303(v=vs.85)
   ; WParam contains a handle to an internal structure describing the dropped files.
   ; Pass this handle DragFinish, DragQueryFile, or DragQueryPoint to retrieve information about the dropped files.
   Static DragQueryFile := "Shell32.dll\DragQueryFile" . (A_IsUnicode ? "W" : "A")
   Global DropTarget ; Global variable containing the target control's HWND
   Dropped := ""
   Files := DllCall(DragQueryFile, "Ptr", WParam, "UInt", -1, "Ptr", 0, "UInt", 0, "UInt")
   Loop, % Files {
      Length := DllCall(DragQueryFile, "Ptr", WParam, "UInt", A_Index - 1, "Ptr", 0, "UInt", 0, "UInt") + 1
      VarSetCapacity(File, Length * (A_IsUnicode ? 2 : 1), 0)
      DllCall(DragQueryFile, "Ptr", WParam, "UInt", A_Index - 1, "Str", File, "UInt", Length, "UInt")
      Dropped .= File . "`r`n"
   }
   DllCall("Shell32.dll\DragFinish", "Ptr", WParam)
   GuiControl, , % DropTarget, % RTrim(Dropped, "`r`n")
   Return 0
}

Prefer ahkscript.org for the time being.


Ronins
  • Members
  • 120 posts
  • Last active: Apr 18 2016 10:54 PM
  • Joined: 11 Apr 2012

Once again:

#NoEnv
WM_DROPFILES := 0x0233 ; window message
WS_EX_ACCEPTFILES := [color=#BF0000]0x10[/color] ; extended window style
Gui, Margin, 0, 0
Gui, Add, Text, w300 h300 [color=#BF0000]+E0x10[/color] HwndHDROP +Border, Files can be dropped within the borders!
Gui, Add, Edit, x50 y50 w200 h200 HwndHEDIT, Drop target!
Gui, Add, Button, xp y+10, Just a button!
Gui, Add, Edit, x320 y50 w160 h200, Don't accept files!
Gui, Show, w500 h350, Drag&Drop
DropTarget := HEDIT
OnMessage(WM_DROPFILES, "On_WM_DROPFILES")
Return

On_WM_DROPFILES(WParam, LParam, Msg, HWND) {
   ; http://msdn.microsoft.com/en-us/library/bb774303(v=vs.85)
   ; WParam contains a handle to an internal structure describing the dropped files.
   ; Pass this handle DragFinish, DragQueryFile, or DragQueryPoint to retrieve information about the dropped files.
   Static DragQueryFile := "Shell32.dll\DragQueryFile" . (A_IsUnicode ? "W" : "A")
   Global DropTarget ; Global variable containing the target control's HWND
   Dropped := ""
   Files := DllCall(DragQueryFile, "Ptr", WParam, "UInt", -1, "Ptr", 0, "UInt", 0, "UInt")
   Loop, % Files {
      Length := DllCall(DragQueryFile, "Ptr", WParam, "UInt", A_Index - 1, "Ptr", 0, "UInt", 0, "UInt") + 1
      VarSetCapacity(File, Length * (A_IsUnicode ? 2 : 1), 0)
      DllCall(DragQueryFile, "Ptr", WParam, "UInt", A_Index - 1, "Str", File, "UInt", Length, "UInt")
      Dropped .= File . "`r`n"
   }
   DllCall("Shell32.dll\DragFinish", "Ptr", WParam)
   GuiControl, , % DropTarget, % RTrim(Dropped, "`r`n")
   Return 0
}


Works perfectly awesome... thanx :D

Maestr0
  • Members
  • 652 posts
  • Last active: Aug 17 2019 06:07 PM
  • Joined: 18 Oct 2008
brilliant, thanks for that, just me. I'm sure I'll need that in a script eventually.