Module: ShenmeGUI::FileDialog

Extended by:
Fiddle::Importer
Includes:
Fiddle::Win32Types
Defined in:
lib/shenmegui/file_dialog.rb

Constant Summary collapse

Struct_OPENFILENAME =
struct <<-EOS.gsub %r{^\s+}, ''
  DWORD lStructSize,
  HWND hwndOwner,
  HINSTANCE hInstance,
  LPCSTR lpstrFilter,
  LPSTR lpstrCustomFilter,
  DWORD nMaxCustFilter,
  DWORD nFilterIndex,
  LPSTR lpstrFile,
  DWORD nMaxFile,
  LPSTR lpstrFileTitle,
  DWORD nMaxFileTitle,
  LPCSTR lpstrInitialDir,
  LPCSTR lpstrTitle,
  DWORD Flags,
  WORD nFileOffset,
  WORD nFileExtension,
  LPCSTR lpstrDefExt,
  long* lCustData,
  int lpfnHook,
  LPCSTR lpTemplateName
EOS

Class Method Summary collapse

Class Method Details

.construct_OPENFILENAME(params = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/shenmegui/file_dialog.rb', line 36

def self.construct_OPENFILENAME(params={})
  filter = params[:filter] ? "#{params[:filter]}\0#{params[:filter]}\0\0" : 0
  title = params[:title] || 0
  flags = 0x00880000
  flags += 0x00000200 if params[:multiselect]
  flags += 0x10000000 if params[:showhidden]

  path = "\0" * 1024
  ofn = Struct_OPENFILENAME.malloc
  ofn.lStructSize = sizeof(ofn)
  ofn.hwndOwner = self.GetForegroundWindow
  ofn.lpstrFilter = filter
  ofn.lpstrCustomFilter = 0
  ofn.nMaxCustFilter = 0
  ofn.nFilterIndex = 0
  ofn.lpstrFile = path
  ofn.nMaxFile = path.size
  ofn.lpstrFileTitle = 0
  ofn.nMaxFileTitle = 0
  ofn.lpstrInitialDir = 0
  ofn.lpstrTitle = title
  ofn.nFileOffset = 0
  ofn.nFileExtension = 0
  ofn.lpstrDefExt = 0
  ofn.lCustData = 0
  ofn.lpfnHook = 0
  ofn.lpTemplateName = 0

  ofn.Flags = flags

  [ofn, path]
end

.get_open_file_name(params = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/shenmegui/file_dialog.rb', line 69

def self.get_open_file_name(params={})
  ofn, path = construct_OPENFILENAME(params)
  GetOpenFileName(ofn)
  ofn = nil
  path = path.split("\0")
  path = path[1..-1].collect{|x| "#{path[0]}\\#{x}"} if path.size > 1
  path.collect{|x| x.force_encoding('GBK').encode('UTF-8')}
  path.size > 1 ? path : path[0]
end

.get_save_file_name(params = {}) ⇒ Object



79
80
81
82
83
84
# File 'lib/shenmegui/file_dialog.rb', line 79

def self.get_save_file_name(params={})
  ofn, path = construct_OPENFILENAME(params)
  GetSaveFileName(ofn)
  ofn = nil
  path.force_encoding('GBK').encode('UTF-8')
end