Class: Fzeet::FileDialog

Inherits:
CommonDialog show all
Defined in:
lib/fzeet/windows/comdlg/FileDialog.rb

Direct Known Subclasses

FileOpenDialog, FileSaveDialog

Constant Summary collapse

DialogStruct =
Windows::OPENFILENAME
HookProc =
-> *args { CommonDialog::HookProc.(*args.unshift(DialogStruct)) }

Constants included from WindowMethods

WindowMethods::EnumChildProc

Instance Attribute Summary

Attributes inherited from CommonDialog

#struct

Instance Method Summary collapse

Methods inherited from CommonDialog

crackMessage, #hookProc, #on

Methods included from WindowMethods

#[], #capture=, #capture?, #dialog=, #dialog?, #dlgmsg?, #drawMenuBar, #eachChild, #enabled=, #enabled?, #focus=, #focus?, #invalidate, #location, #location=, #long, #menu, #menu=, #message, #paint, #position, #position=, #postmsg, #question, #rect, #reframe, #sendmsg, #show, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?

Methods included from Toggle

#toggle

Constructor Details

#initialize(opts = {}) ⇒ FileDialog

Returns a new instance of FileDialog.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 132

def initialize(opts = {})
  _opts = {
    filter: nil,
    customFilter: nil,
    filterIndex: 0,
    fileTitle: nil,
    initialDir: nil,
    title: nil,
    flags: 0,
    fileExtension: nil,
    defExt: nil,
    custData: 0,
    hook: nil,
    templateName: nil,
    xflags: 0
  }
  badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty?
  _opts.merge!(opts)

  @struct = DialogStruct.new

  @struct[:lStructSize] = @struct.size
  @struct[:hInstance] = Windows.GetModuleHandle(nil)
  @struct[:lpstrFile] = @buf = FFI::MemoryPointer.new(:char, 4096)
  @struct[:nMaxFile] = @buf.size
  @struct[:Flags] = Fzeet.flags([:enablehook, :explorer, :enablesizing, :overwriteprompt] + [*_opts[:flags]], :ofn_)
  @struct[:lCustData] = object_id
  @struct[:lpfnHook] = HookProc

  super()

  begin
    yield self
  ensure
    dispose
  end if block_given?
end

Instance Method Details

#disposeObject



170
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 170

def dispose; @buf.free end

#pathObject



172
# File 'lib/fzeet/windows/comdlg/FileDialog.rb', line 172

def path; @buf.read_string end