Class: Fzeet::WindowClass

Inherits:
Fzeet::Windows::WNDCLASSEX show all
Defined in:
lib/fzeet/windows/user/Window/Common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prototype, name, opts = {}) ⇒ WindowClass

Returns a new instance of WindowClass.



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/fzeet/windows/user/Window/Common.rb', line 465

def initialize(prototype, name, opts = {})
	@prototype = prototype
	@name = name
	className = FFI::MemoryPointer.from_string(@name)

	_opts = {
		style: [],
		wndProc: BasicWindow::WindowProc,
		clsExtra: 0,
		wndExtra: 0,
		icon: SystemIcon.new(:application),
		cursor: SystemCursor.new(:arrow),
		background: SystemBrush.new(:window),
		iconSm: nil
	}
	badopts = opts.keys - _opts.keys; raise "Bad option(s): #{badopts.join(', ')}." unless badopts.empty?

	self[:cbSize] = Windows::WNDCLASSEX.size
	self[:hInstance] = Windows.GetModuleHandle(nil)
	self[:lpszClassName] = className

	if @prototype
		self[:style] = Fzeet.flags(opts[:style] || [], :cs_) | @prototype[:style]
		self[:lpfnWndProc] = opts[:wndProc] || @prototype[:lpfnWndProc]
		self[:cbClsExtra] = (opts[:clsExtra] || 0) + @prototype[:cbClsExtra]
		self[:cbWndExtra] = (opts[:wndExtra] || 0) + @prototype[:cbWndExtra]
		self[:hIcon] = (opts[:icon] && opts[:icon].handle) || @prototype[:hIcon]
		self[:hCursor] = (opts[:cursor] && opts[:cursor].handle) || @prototype[:hCursor]
		self[:hbrBackground] = (opts[:background] && opts[:background].handle) || @prototype[:hbrBackground]
		self[:hIconSm] = (opts[:iconSm] && _opts[:iconSm].handle) || @prototype[:hIconSm]
	else
		_opts.merge(opts)

		self[:style] = Fzeet.flags(_opts[:style], :cs_)
		self[:lpfnWndProc] = _opts[:wndProc]
		self[:cbClsExtra] = _opts[:clsExtra]
		self[:cbWndExtra] = _opts[:wndExtra]
		self[:hIcon] = _opts[:icon].handle
		self[:hCursor] = _opts[:cursor].handle
		self[:hbrBackground] = _opts[:background].handle
		self[:hIconSm] = _opts[:iconSm] && _opts[:iconSm].handle
	end

	Windows.DetonateLastError(0, :RegisterClassEx, self) { className.free }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



511
512
513
# File 'lib/fzeet/windows/user/Window/Common.rb', line 511

def name
  @name
end

#prototypeObject (readonly)

Returns the value of attribute prototype.



511
512
513
# File 'lib/fzeet/windows/user/Window/Common.rb', line 511

def prototype
  @prototype
end