| 
			
				|  | Cheat Engine The Official Site of Cheat Engine
 
 
 |  
 
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Corroder Grandmaster Cheater Supreme
 
  Reputation: 75 
 Joined: 10 Apr 2015
 Posts: 1668
 
 
 | 
			
				|  Posted: Fri Sep 18, 2020 3:04 pm    Post subject: Allow Drop File |   |  
				| 
 |  
				| How to use Allow Drop File on form components?. i.e: Drag and drop text file to CEMemo or an Image to CEImage?
 Any example?
 _________________
 
 Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
 |  |  
		| Back to top |  |  
		|  |  
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Fri Sep 18, 2020 3:46 pm    Post subject: |   |  
				| 
 |  
				| in the form's OnDropFiles event fetch the current mouse cursor position 
 then use screenToClient(x,y) on the controls to figure out which control the mouse is over
 _________________
 
 Do not ask me about online cheats. I don't know any and wont help finding them.
 Like my help? Join me on Patreon so i can keep helping
 |  |  
		| Back to top |  |  
		|  |  
		| Corroder Grandmaster Cheater Supreme
 
  Reputation: 75 
 Joined: 10 Apr 2015
 Posts: 1668
 
 
 | 
			
				|  Posted: Fri Sep 18, 2020 10:42 pm    Post subject: |   |  
				| 
 |  
				| Thanks DB, the script below is an example to drag components on the form: 
 
  	  | Code: |  	  | memo = UDF1.CEMemo1 image = UDF1.CEImage1
 
 local down = false
 
 function ObjMouseDown(sender, x, y)
 down = true
 end
 
 function ObjMouseMove(sender, x, y)
 if down == true then
 local x,y = getMousePos()
 x1,y1 = UDF1.ScreenToClient(x,y)
 sender.Top = y1
 sender.Left = x1
 end
 end
 
 function ObjMouseUp(sender, x, y)
 down = false
 end
 
 
 UDF1.show()
 memo.onMouseDown = ObjMouseDown
 memo.onMouseMove = ObjMouseMove
 memo.onMouseUp = ObjMouseUp
 
 image.onMouseDown = ObjMouseDown
 image.onMouseMove = ObjMouseMove
 image.onMouseUp = ObjMouseUp
 | 
 
 But, I am sorry for not clear information. What I mean is to drag and drop file from explorer to the controls.
 i.e : drag a text file from explorer to CEMemo and the text automatically as CEMemo Text, or an image to CEImage, etc.
 
 Similar like do in Lazarus (with listbox control), example:
 
 
  	  | Code: |  	  | procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String); var
 i: Integer;
 begin
 for i := Low(FileNames) to High(FileNames) do
 ListBox1.Items.Add(FileNames[i]);
 end;
 end;
 | 
 
 I try port to CE Lua:
 
 
  	  | Code: |  	  | form.AllowdropFiles = true 
 function form_FormDropFiles(sender, FileNames)
 FileNames = {}
 for i = 0, #FileNames do
 ListBox1.Items.Add(FileNames[i]);
 end
 end
 
 | 
 
 Of course doesn't work. So, is there any ways to do it properly in CE Lua?.
 _________________
 
 Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
 |  |  
		| Back to top |  |  
		|  |  
		| Dark Byte Site Admin
 
  Reputation: 470 
 Joined: 09 May 2003
 Posts: 25807
 Location: The netherlands
 
 | 
			
				|  Posted: Sat Sep 19, 2020 1:27 am    Post subject: |   |  
				| 
 |  
				| of course that won't work as you're throwing away the filenames tables before you read through it 
 and do you assign that function to OnDropFiles ?
 _________________
 
 Do not ask me about online cheats. I don't know any and wont help finding them.
 Like my help? Join me on Patreon so i can keep helping
 |  |  
		| Back to top |  |  
		|  |  
		| .lua Expert Cheater
 
  Reputation: 1 
 Joined: 13 Sep 2018
 Posts: 203
 
 
 | 
			
				|  Posted: Sat Sep 19, 2020 2:06 am    Post subject: |   |  
				| 
 |  
				|  	  | Code: |  	  | if f then f.destroy() end f=createForm()
 f.FormStyle='fsSystemStayOnTop'
 f.AllowDropFiles=true
 
 m=createMemo(f)
 m.setSize(200,150)
 m.setPosition(5,5)
 m.Lines.Add('This is Memo')
 m.Lines.Add('Please drag in the TXT file')
 
 img=createImage(f)
 img.Stretch=true
 img.Align='alClient'
 function setPrompt(str,v)
 img.Canvas.clear()
 img.Canvas.gradientFill(0,0,img.width,img.height,0x55,0xff00ff,v)
 img.Canvas.Brush.Style=1
 img.Canvas.textOut(0,200,str)
 end
 setPrompt('This is image , Please drag in the jpg file',1)
 
 f.OnDropFiles=function(sender,filename)
 for k,v in pairs(filename) do
 local fi=('.txt' or '.ini' or '.lua')
 local path,name = string.match(string.lower(v),'(.*\\)(.*)')
 local txt=string.match(string.lower(v),'(.*)%.txt')
 local jpg=string.match(string.lower(v),'(.*)%.jpg')
 if jpg then
 img.Picture.loadFromFile(jpg..'.jpg')
 setPrompt('Current file:'..path..name,0)
 elseif txt then
 local file=io.open(utf8ToAnsi(txt)..'.txt','r')
 if file then m.Lines.Add(file:read('*a'))  file:close() end
 setPrompt('Current file:'..path..name,0)
 else
 beep()  setPrompt('The file is not in jpg or txt format',0)
 end
 end
 end
 | 
 
 
 
 
	
		
	 
		| Description: |  |  
		| Filesize: | 265.1 KB |  
		| Viewed: | 1905 Time(s) |  
		| 
  
 
 |  
 |  |  
		| Back to top |  |  
		|  |  
		| Corroder Grandmaster Cheater Supreme
 
  Reputation: 75 
 Joined: 10 Apr 2015
 Posts: 1668
 
 
 | 
			
				|  Posted: Sat Sep 19, 2020 4:26 am    Post subject: |   |  
				| 
 |  
				| Thanks DB and lua... my bad, not really understand what I am trying to do by follow some articles for lazarus/delphi style to drag and drop process. 
 It's work and this is script according to my needs.
 
 
  	  | Code: |  	  | if f then f.Destroy() end 
 f = createForm()
 f.setSize(600, 400)
 f.Position = 'poScreenCenter'
 f.Caption = 'Test Drag And Drop'
 f.AllowdropFiles = true
 
 memo1 = createMemo(f)
 memo1.setSize(580,340)
 memo1.setPosition(10,10)
 memo1.ScrollBars = 'ssAutoBoth'
 
 btn1 = createButton(f)
 btn1.setSize(150, 30)
 btn1.setPosition(225, 360)
 btn1.Caption = 'Clear Memo Text'
 
 f.OnDropFiles=function(sender,filename)
 for k,v in pairs(filename) do
 local txt = string.match(string.lower(v),'(.*)%.txt')
 if txt then
 local file=io.open(txt..'.txt','r')
 if file then
 local content = file:read('*a')
 file:close()
 memo1.Clear()
 memo1.Lines.Text = content
 else
 showMessage('file error')
 end
 end
 end
 end
 
 btn1.OnClick = function(sender)
 memo1.Clear()
 end
 
 | 
 _________________
 
 Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
 |  |  
		| Back to top |  |  
		|  |  
		| .lua Expert Cheater
 
  Reputation: 1 
 Joined: 13 Sep 2018
 Posts: 203
 
 
 | 
			
				|  Posted: Sat Sep 19, 2020 4:55 am    Post subject: |   |  
				| 
 |  
				| You'd better write it safely, because if you have a file name with wide characters, it may appear that the file does not exist 
  	  | Code: |  	  | local file=io.open(utf8ToAnsi(txt)..'.txt','r') | 
 |  |  
		| Back to top |  |  
		|  |  
		| Corroder Grandmaster Cheater Supreme
 
  Reputation: 75 
 Joined: 10 Apr 2015
 Posts: 1668
 
 
 | 
			
				|  Posted: Sat Sep 19, 2020 5:29 am    Post subject: |   |  
				| 
 |  
				|  	  | .lua wrote: |  	  | You'd better write it safely, because if you have a file name with wide characters, it may appear that the file does not exist 
  	  | Code: |  	  | local file=io.open(utf8ToAnsi(txt)..'.txt','r') | 
 | 
 
 Yes, I know. The script I made has no error handle checking. Actually I am use functions IsDirExist() or IsFileExist including check if the file name contains native characters or not, and use assertion too.
 Thank to remind me
 _________________
 
 Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
 |  |  
		| Back to top |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 You cannot attach files in this forum
 You can download files in this forum
 
 |  |