Class: Clipboard

Inherits:
Object show all
Includes:
ClipboardFormat
Defined in:
lib/vr/clipboard.rb

Constant Summary collapse

GetClipboardData =
Win32API.new('user32','GetClipboardData','I','L')
SetClipboardData =
Win32API.new('user32','SetClipboardData','IL','L')
EnumClipboardFormats =
Win32API.new('user32','EnumClipboardFormats','I','I')
OpenClipboard =
Win32API.new('user32','OpenClipboard','L','I')
CloseClipboard =
Win32API.new('user32','CloseClipboard','V','I')
EmptyClipboard =
Win32API.new('user32','EmptyClipboard','V','I')
VR_CF_TEXT =

modify if you like to use CF_TEXT than CF_OEMTEXT

CF_OEMTEXT

Constants included from ClipboardFormat

ClipboardFormat::CF_HDROP, ClipboardFormat::CF_OEMTEXT, ClipboardFormat::CF_TEXT, ClipboardFormat::CF_URL, ClipboardFormat::RegisterClipboardFormat

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hwnd) ⇒ Clipboard

Returns a new instance of Clipboard.



63
64
65
66
67
# File 'lib/vr/clipboard.rb', line 63

def initialize(hwnd)
  @hwnd = hwnd
  @opened = (OpenClipboard.call(hwnd)!=0)
  raise "fail to open clipboard" unless defined?(@opened)
end

Class Method Details

.open(*args) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/vr/clipboard.rb', line 53

def self.open(*args)
  r = self.new(*args)
  if iterator?
    yield r
    r.close
  else
    return r
  end
end

Instance Method Details

#closeObject



69
70
71
# File 'lib/vr/clipboard.rb', line 69

def close
  @opened = (CloseClipboard.call() == 0)
end

#enum_formatsObject



97
98
99
100
101
102
103
104
# File 'lib/vr/clipboard.rb', line 97

def enum_formats
  r=0
  while true do
    r=EnumClipboardFormats.call(r)
    break if r==0
    yield r 
  end
end

#getData(uformat) ⇒ Object



73
74
75
76
77
78
# File 'lib/vr/clipboard.rb', line 73

def getData(uformat)
  raise "Clipboard not opened" unless defined?(@opened)
  gmem = GetClipboardData.call(uformat.to_i)
  raise "GetData failed" if gmem==0
  GMEM::Get(gmem) if gmem!=0
end

#getTextObject



88
89
90
91
# File 'lib/vr/clipboard.rb', line 88

def getText
  r=getData(VR_CF_TEXT)
  r.split(/\0/,0)[0]
end

#setData(uformat, data) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/vr/clipboard.rb', line 80

def setData(uformat,data)
  raise "Clipboard not opened" unless defined? @opened
  EmptyClipboard.call
  gmem = GMEM::AllocStr(66,data)
  SetClipboardData.call(uformat,gmem)
#    GMEM::Free(gmem)
end

#setText(str) ⇒ Object



93
94
95
# File 'lib/vr/clipboard.rb', line 93

def setText(str)
  setData VR_CF_TEXT,str.to_s
end