Class: Fzeet::ColorDialog

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

Constant Summary collapse

DialogStruct =
Windows::CHOOSECOLOR
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, #size, #size=, #style, #style?, #text, #text=, #textlen, #topmost=, #topmost?, #update, #visible=, #visible?, #xstyle, #xstyle?

Methods included from Toggle

#toggle

Constructor Details

#initialize(opts = {}) ⇒ ColorDialog

Returns a new instance of ColorDialog.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fzeet/windows/comdlg/ColorDialog.rb', line 40

def initialize(opts = {})
	_opts = {

	}
	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[:lpCustColors] = @buf = FFI::MemoryPointer.new(:ulong, 16)
	@struct[:Flags] = Fzeet.flags(:enablehook, :cc_)
	@struct[:lCustData] = object_id
	@struct[:lpfnHook] = HookProc

	super()

	begin
		yield self
	ensure
		dispose
	end if block_given?
end

Instance Method Details

#colorObject



73
# File 'lib/fzeet/windows/comdlg/ColorDialog.rb', line 73

def color; result = @struct[:rgbResult]; [Windows.GetRValue(result), Windows.GetBValue(result), Windows.GetBValue(result)] end

#disposeObject



65
# File 'lib/fzeet/windows/comdlg/ColorDialog.rb', line 65

def dispose; @buf.free end

#show(window = Application.window) ⇒ Object



67
68
69
70
71
# File 'lib/fzeet/windows/comdlg/ColorDialog.rb', line 67

def show(window = Application.window)
	@struct[:hwndOwner] = window.handle

	DialogResult.new((Windows.ChooseColor(@struct) == 0) ? Windows::IDCANCEL : Windows::IDOK)
end