### toggleWindows.rb - based on Jim's ideas - only for Windows...
### 20090401 TIG updated
### 20130907 PLATFORM >> RUBY_PLATFORM for future-proofing.
### 20131210 Moe Future-proofing.
###
if RUBY_PLATFORM.downcase =~ /mswin/ ### = a Windows machine
  unless defined?(Win32API)
	  if RUBY_VERSION.to_f > 1.8 ### v2014 NOT needed ???
		require("Win32API.rb")
	  elsif File.exist?(File.join(File.dirname(__FILE__), "Win32API.so"))
		require("Win32API.so")
	  end
  end
  def toggleRollUp(name)
	findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
	pw=findWindow.call(0,name)
	sendMessage = Win32API.new("user32.dll","SendMessage",['N','N','N','P'],'N')
	sendMessage.call(pw,0x00a1,2,"")#WM_NCLBUTTONDOWN
	sendMessage.call(pw,0x0202,0,"")#WM_LBUTTONUP
  end
  def isRolledUp(name)
    findWindow = Win32API.new("user32.dll","FindWindow",['P','P'],'N')
    getWindowRect= Win32API.new("user32.dll","GetWindowRect",['P','PP'],'N')
    pw=findWindow.call(0,name)
    data=Array.new.fill(0.chr,0..4*4).join
    getWindowRect.call(pw,data);
    rect=data.unpack("i*")
    #if window height is less than 90 then the window is rolledup
    return (rect[3]-rect[1])<90
  end
end#if
###