I dragged a file into the window and wanted to get the local full path of the dragged file, but it didn’t work very well。As shown below:
my code:
################
# index.rb
################
require 'sketchup.rb'
dialog = UI::HtmlDialog.new(
{
:dialog_title => "drag_file_demo",
:preferences_key => "com.example.html_dialog",
:scrollable => true,
:resizable => true,
:width => 500,
:height => 300,
:left => 100,
:top => 100,
:style => UI::HtmlDialog::STYLE_DIALOG,
}
)
dialog.add_action_callback("file_drop") do |action_context|
hwnd = Win32API.new('user32', 'FindWindow', ['P', 'P'], 'L').call(0, "drag_file_demo")
puts "hwnd: #{hwnd}"
num_files = Win32API.new('shell32', 'DragQueryFile', ['L', 'L', 'P', 'L'], 'L').call(hwnd, 0xFFFFFFFF, nil, 0)
puts "num_files = #{num_files}\n"
if num_files > 0
file_path = buffer.strip
puts file_path
end
end
# Show HTML dialog
dialog.set_file('C:/Users/whxcer/Desktop/file-upload/ruby_upload2/index.html')
dialog.show
<!-- C:/Users/whxcer/Desktop/file-upload/ruby_upload2/index.html -->
<!DOCTYPE html>
<html>
<head>
<script>
function handleFileDrop(event) {
event.preventDefault();
sketchup.file_drop()
}
document.addEventListener("dragover", function(event) {
event.preventDefault();
}, false);
document.addEventListener("drop", handleFileDrop, false);
</script>
</head>
<body>
<h1>
Example of file drag and drop
</h1>
<p>
Drop files here
</p>
</body>
</html>
question:
1. How can I solve this problem?
2. Or is there any other way to solve this problem?
Thank you so much!!