Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Allow Drop File

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Sep 18, 2020 3:04 pm    Post subject: Allow Drop File Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Fri Sep 18, 2020 3:46 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Fri Sep 18, 2020 10:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25807
Location: The netherlands

PostPosted: Sat Sep 19, 2020 1:27 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 203

PostPosted: Sat Sep 19, 2020 2:06 am    Post subject: Reply with quote

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



GIF.gif
 Description:
 Filesize:  265.1 KB
 Viewed:  1904 Time(s)

GIF.gif


Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Sep 19, 2020 4:26 am    Post subject: Reply with quote

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
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 203

PostPosted: Sat Sep 19, 2020 4:55 am    Post subject: Reply with quote

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
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sat Sep 19, 2020 5:29 am    Post subject: Reply with quote

.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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites