win32console 1.0.8-i386-mswin32 → 1.1.0-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/Console.cpp +15 -0
  2. data/HISTORY_GEM.txt +34 -0
  3. data/README.txt +0 -1
  4. data/{lib/README_GEM.txt → README_GEM.txt} +1 -1
  5. data/Rakefile +5 -5
  6. data/lib/Console.so +0 -0
  7. data/lib/Win32/Console/ANSI.rb +283 -240
  8. data/lib/Win32/Console/api.rb +342 -0
  9. data/lib/Win32/Console/constants.rb +66 -0
  10. data/lib/Win32/Console.rb +77 -675
  11. metadata +10 -114
  12. data/doc/classes/Win32/Console/ANSI/IO.html +0 -220
  13. data/doc/classes/Win32/Console/ANSI/IO.src/M000035.html +0 -32
  14. data/doc/classes/Win32/Console/ANSI/IO.src/M000036.html +0 -205
  15. data/doc/classes/Win32/Console/ANSI/IO.src/M000037.html +0 -40
  16. data/doc/classes/Win32/Console/ANSI/IO.src/M000038.html +0 -25
  17. data/doc/classes/Win32/Console/ANSI.html +0 -103
  18. data/doc/classes/Win32/Console/API.html +0 -758
  19. data/doc/classes/Win32/Console/API.src/M000039.html +0 -27
  20. data/doc/classes/Win32/Console/API.src/M000040.html +0 -27
  21. data/doc/classes/Win32/Console/API.src/M000041.html +0 -27
  22. data/doc/classes/Win32/Console/API.src/M000042.html +0 -32
  23. data/doc/classes/Win32/Console/API.src/M000043.html +0 -32
  24. data/doc/classes/Win32/Console/API.src/M000044.html +0 -28
  25. data/doc/classes/Win32/Console/API.src/M000045.html +0 -26
  26. data/doc/classes/Win32/Console/API.src/M000046.html +0 -26
  27. data/doc/classes/Win32/Console/API.src/M000047.html +0 -27
  28. data/doc/classes/Win32/Console/API.src/M000048.html +0 -30
  29. data/doc/classes/Win32/Console/API.src/M000049.html +0 -29
  30. data/doc/classes/Win32/Console/API.src/M000050.html +0 -27
  31. data/doc/classes/Win32/Console/API.src/M000051.html +0 -28
  32. data/doc/classes/Win32/Console/API.src/M000052.html +0 -30
  33. data/doc/classes/Win32/Console/API.src/M000053.html +0 -27
  34. data/doc/classes/Win32/Console/API.src/M000054.html +0 -29
  35. data/doc/classes/Win32/Console/API.src/M000055.html +0 -29
  36. data/doc/classes/Win32/Console/API.src/M000056.html +0 -28
  37. data/doc/classes/Win32/Console/API.src/M000057.html +0 -27
  38. data/doc/classes/Win32/Console/API.src/M000058.html +0 -47
  39. data/doc/classes/Win32/Console/API.src/M000059.html +0 -32
  40. data/doc/classes/Win32/Console/API.src/M000060.html +0 -47
  41. data/doc/classes/Win32/Console/API.src/M000061.html +0 -34
  42. data/doc/classes/Win32/Console/API.src/M000062.html +0 -32
  43. data/doc/classes/Win32/Console/API.src/M000063.html +0 -32
  44. data/doc/classes/Win32/Console/API.src/M000064.html +0 -35
  45. data/doc/classes/Win32/Console/API.src/M000065.html +0 -26
  46. data/doc/classes/Win32/Console/API.src/M000066.html +0 -27
  47. data/doc/classes/Win32/Console/API.src/M000067.html +0 -29
  48. data/doc/classes/Win32/Console/API.src/M000068.html +0 -27
  49. data/doc/classes/Win32/Console/API.src/M000069.html +0 -27
  50. data/doc/classes/Win32/Console/API.src/M000070.html +0 -28
  51. data/doc/classes/Win32/Console/API.src/M000071.html +0 -27
  52. data/doc/classes/Win32/Console/API.src/M000072.html +0 -26
  53. data/doc/classes/Win32/Console/API.src/M000073.html +0 -27
  54. data/doc/classes/Win32/Console/API.src/M000074.html +0 -31
  55. data/doc/classes/Win32/Console/API.src/M000075.html +0 -27
  56. data/doc/classes/Win32/Console/API.src/M000076.html +0 -32
  57. data/doc/classes/Win32/Console/API.src/M000077.html +0 -27
  58. data/doc/classes/Win32/Console/API.src/M000078.html +0 -32
  59. data/doc/classes/Win32/Console/API.src/M000079.html +0 -32
  60. data/doc/classes/Win32/Console/API.src/M000080.html +0 -32
  61. data/doc/classes/Win32/Console/Constants.html +0 -360
  62. data/doc/classes/Win32/Console.html +0 -650
  63. data/doc/classes/Win32/Console.src/M000001.html +0 -31
  64. data/doc/classes/Win32/Console.src/M000002.html +0 -23
  65. data/doc/classes/Win32/Console.src/M000003.html +0 -23
  66. data/doc/classes/Win32/Console.src/M000004.html +0 -27
  67. data/doc/classes/Win32/Console.src/M000005.html +0 -23
  68. data/doc/classes/Win32/Console.src/M000006.html +0 -28
  69. data/doc/classes/Win32/Console.src/M000007.html +0 -23
  70. data/doc/classes/Win32/Console.src/M000008.html +0 -24
  71. data/doc/classes/Win32/Console.src/M000009.html +0 -44
  72. data/doc/classes/Win32/Console.src/M000010.html +0 -23
  73. data/doc/classes/Win32/Console.src/M000011.html +0 -33
  74. data/doc/classes/Win32/Console.src/M000012.html +0 -26
  75. data/doc/classes/Win32/Console.src/M000013.html +0 -27
  76. data/doc/classes/Win32/Console.src/M000014.html +0 -28
  77. data/doc/classes/Win32/Console.src/M000015.html +0 -23
  78. data/doc/classes/Win32/Console.src/M000016.html +0 -23
  79. data/doc/classes/Win32/Console.src/M000017.html +0 -23
  80. data/doc/classes/Win32/Console.src/M000018.html +0 -29
  81. data/doc/classes/Win32/Console.src/M000019.html +0 -23
  82. data/doc/classes/Win32/Console.src/M000020.html +0 -23
  83. data/doc/classes/Win32/Console.src/M000021.html +0 -28
  84. data/doc/classes/Win32/Console.src/M000022.html +0 -23
  85. data/doc/classes/Win32/Console.src/M000023.html +0 -28
  86. data/doc/classes/Win32/Console.src/M000024.html +0 -35
  87. data/doc/classes/Win32/Console.src/M000025.html +0 -28
  88. data/doc/classes/Win32/Console.src/M000026.html +0 -28
  89. data/doc/classes/Win32/Console.src/M000027.html +0 -28
  90. data/doc/classes/Win32/Console.src/M000028.html +0 -31
  91. data/doc/classes/Win32/Console.src/M000029.html +0 -23
  92. data/doc/classes/Win32/Console.src/M000030.html +0 -23
  93. data/doc/classes/Win32/Console.src/M000031.html +0 -23
  94. data/doc/classes/Win32/Console.src/M000032.html +0 -27
  95. data/doc/classes/Win32/Console.src/M000033.html +0 -27
  96. data/doc/classes/Win32/Console.src/M000034.html +0 -25
  97. data/doc/classes/Win32.html +0 -115
  98. data/doc/created.rid +0 -1
  99. data/doc/files/Console_ANSI_rdoc.html +0 -407
  100. data/doc/files/Console_cpp.html +0 -104
  101. data/doc/files/Console_rdoc.html +0 -964
  102. data/doc/files/lib/Win32/Console/ANSI_rb.html +0 -123
  103. data/doc/files/lib/Win32/Console_rb.html +0 -297
  104. data/doc/fr_class_index.html +0 -32
  105. data/doc/fr_file_index.html +0 -31
  106. data/doc/fr_method_index.html +0 -106
  107. data/doc/index.html +0 -24
  108. data/doc/rdoc-style.css +0 -172
@@ -0,0 +1,342 @@
1
+
2
+ # The actual api to access windows functions
3
+ module Win32
4
+ class Console
5
+ class API
6
+ require 'Win32API'
7
+
8
+ class << self
9
+
10
+ def constant(t)
11
+ begin
12
+ return Win32::Console::Constants.const_get(t)
13
+ rescue
14
+ return nil
15
+ end
16
+ end
17
+
18
+ def AllocConsole()
19
+ @AllocConsole ||= Win32API.new( "kernel32", "AllocConsole", [], 'l' )
20
+ @AllocConsole.call()
21
+ end
22
+
23
+ def CreateConsoleScreenBuffer( dwDesiredAccess, dwShareMode, dwFlags )
24
+ @CreateConsoleScreenBuffer ||= Win32API.new( "kernel32", "CreateConsoleScreenBuffer", ['l', 'l', 'p', 'l', 'p'], 'l' )
25
+ @CreateConsoleScreenBuffer.call( dwDesiredAccess, dwShareMode, nil, dwFlags, nil )
26
+ end
27
+
28
+ def FillConsoleOutputAttribute( hConsoleOutput, wAttribute, nLength, col, row )
29
+ @FillConsoleOutputAttribute ||= Win32API.new( "kernel32", "FillConsoleOutputAttribute", ['l', 'i', 'l', 'l', 'p'], 'l' )
30
+ dwWriteCoord = (row << 16) + col
31
+ lpNumberOfAttrsWritten = ' ' * 4
32
+ @FillConsoleOutputAttribute.call( hConsoleOutput, wAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
33
+ return lpNumberOfAttrsWritten.unpack('L')
34
+ end
35
+
36
+ def FillConsoleOutputCharacter( hConsoleOutput, cCharacter, nLength, col, row )
37
+ @FillConsoleOutputCharacter ||= Win32API.new( "kernel32", "FillConsoleOutputCharacter", ['l', 'i', 'l', 'l', 'p'], 'l' )
38
+ dwWriteCoord = (row << 16) + col
39
+ lpNumberOfAttrsWritten = ' ' * 4
40
+ @FillConsoleOutputCharacter.call( hConsoleOutput, cCharacter, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
41
+ return lpNumberOfAttrsWritten.unpack('L')
42
+ end
43
+
44
+ def FlushConsoleInputBuffer( hConsoleInput )
45
+ @FlushConsoleInputBuffer ||= Win32API.new( "kernel32", "FillConsoleInputBuffer", ['l'], 'l' )
46
+ @FlushConsoleInputBuffer.call( hConsoleInput )
47
+ end
48
+
49
+ def FreeConsole()
50
+ @FreeConsole ||= Win32API.new( "kernel32", "FreeConsole", [], 'l' )
51
+ @FreeConsole.call()
52
+ end
53
+
54
+ def GenerateConsoleCtrlEvent( dwCtrlEvent, dwProcessGroupId )
55
+ @GenerateConsoleCtrlEvent ||= Win32API.new( "kernel32", "GenerateConsoleCtrlEvent", ['l', 'l'], 'l' )
56
+ @GenerateConsoleCtrlEvent.call( dwCtrlEvent, dwProcessGroupId )
57
+ end
58
+
59
+ def GetConsoleCP()
60
+ @GetConsoleCP ||= Win32API.new( "kernel32", "GetConsoleCP", [], 'l' )
61
+ @GetConsoleCP.call()
62
+ end
63
+
64
+ def GetConsoleCursorInfo( hConsoleOutput )
65
+ @GetConsoleCursorInfo ||= Win32API.new( "kernel32", "GetConsoleCursorInfo", ['l', 'p'], 'l' )
66
+ lpConsoleCursorInfo = ' ' * 8
67
+ @GetConsoleCursorInfo.call( hConsoleOutput, lpConsoleCursorInfo )
68
+ return lpConsoleCursorInfo.unpack('LL')
69
+ end
70
+
71
+ def GetConsoleMode( hConsoleHandle )
72
+ @GetConsoleMode ||= Win32API.new( "kernel32", "GetConsoleMode", ['l', 'p'], 'l' )
73
+ lpMode = ' ' * 4
74
+ @GetConsoleMode.call( hConsoleHandle, lpMode )
75
+ return lpMode.unpack('L').first
76
+ end
77
+
78
+ def GetConsoleOutputCP()
79
+ @GetConsoleOutputCP ||= Win32API.new( "kernel32", "GetConsoleOutputCP", [], 'l' )
80
+ @GetConsoleOutputCP.call()
81
+ end
82
+
83
+ def GetConsoleScreenBufferInfo( hConsoleOutput )
84
+ @GetConsoleScreenBufferInfo ||= Win32API.new( "kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'l' )
85
+ lpBuffer = ' ' * 22
86
+ @GetConsoleScreenBufferInfo.call( hConsoleOutput, lpBuffer )
87
+ return lpBuffer.unpack('SSSSSssssSS')
88
+ end
89
+
90
+ def GetConsoleTitle()
91
+ @GetConsoleTitle ||= Win32API.new( "kernel32", "GetConsoleTitle", ['p', 'l'], 'l' )
92
+ nSize = 120
93
+ lpConsoleTitle = ' ' * nSize
94
+ @GetConsoleTitle.call( lpConsoleTitle, nSize )
95
+ return lpConsoleTitle.strip
96
+ end
97
+
98
+ def GetConsoleWindow()
99
+ @GetConsoleWindow ||= Win32API.new( "kernel32", "GetConsoleWindow",[], 'l' )
100
+ @GetConsoleWindow.call()
101
+ end
102
+
103
+ def GetLargestConsoleWindowSize( hConsoleOutput )
104
+ @GetLargestConsoleWindowSize ||= Win32API.new( "kernel32", "GetLargestConsoleWindowSize", ['l'], 'l' )
105
+ coord = @GetLargestConsoleWindowSize.call( hConsoleOutput )
106
+ x = coord >> 16
107
+ y = coord & 0x0000ffff
108
+ return [x,y]
109
+ end
110
+
111
+ def GetNumberOfConsoleInputEvents( hConsoleInput )
112
+ @GetNumberOfConsoleInputEvents ||= Win32API.new( "kernel32", "GetNumberOfConsoleInputEvents", ['l', 'p'], 'l' )
113
+ lpcNumberOfEvents = 0
114
+ @GetNumberOfConsoleInputEvents.call( hConsoleInput, lpcNumberOfEvents )
115
+ return lpcNumberOfEvents
116
+ end
117
+
118
+ def GetNumberOfConsoleMouseButtons( )
119
+ @GetNumberOfConsoleMouseButtons ||= Win32API.new( "kernel32", "GetNumberOfConsoleMouseButtons", ['p'], 'l' )
120
+ lpNumberOfMouseButtons = 0
121
+ @GetNumberOfConsoleMouseButtons.call( lpNumberOfMouseButtons )
122
+ return lpNumberOfMouseButtons
123
+ end
124
+
125
+ def GetStdHandle( nStdHandle )
126
+ @GetStdHandle ||= Win32API.new( "kernel32", "GetStdHandle", ['l'], 'l' )
127
+ @GetStdHandle.call( nStdHandle )
128
+ end
129
+
130
+ # <<HandlerRoutine>> : This is not an actual API function, just a concept description in the SDK.
131
+
132
+ def PeekConsoleInput( hConsoleInput )
133
+ @PeekConsoleInput ||= Win32API.new( "kernel32", "PeekConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
134
+ lpNumberOfEventsRead = ' ' * 4
135
+ lpBuffer = ' ' * 20
136
+ nLength = 20
137
+ @PeekConsoleInput.call( hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead )
138
+ type = lpBuffer.unpack('s')[0]
139
+
140
+ case type
141
+ when KEY_EVENT
142
+ return lpBuffer.unpack('sSSSSCS')
143
+ when MOUSE_EVENT
144
+ return lpBuffer.unpack('sSSSS')
145
+ when WINDOW_BUFFER_SIZE_EVENT
146
+ return lpBuffer.unpack('sS')
147
+ when MENU_EVENT
148
+ return lpBuffer.unpack('sS')
149
+ when FOCUS_EVENT
150
+ return lpBuffer.unpack('sS')
151
+ else
152
+ return []
153
+ end
154
+ end
155
+
156
+ def ReadConsole( hConsoleInput, lpBuffer, nNumberOfCharsToRead )
157
+ @ReadConsole ||= Win32API.new( "kernel32", "ReadConsole", ['l', 'p', 'l', 'p', 'p'], 'l' )
158
+ lpBuffer = ' ' * nNumberOfCharsToRead unless lpBuffer
159
+ lpNumberOfCharsRead = ' ' * 4
160
+ lpReserved = ' ' * 4
161
+ @ReadConsole.call( hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved )
162
+ return lpNumberOfCharsRead.unpack('L')
163
+ end
164
+
165
+ def ReadConsoleInput( hConsoleInput )
166
+ @ReadConsoleInput ||= Win32API.new( "kernel32", "ReadConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
167
+ lpNumberOfEventsRead = ' ' * 4
168
+ lpBuffer = ' ' * 20
169
+ nLength = 20
170
+ @ReadConsoleInput.call( hConsoleInput, lpBuffer, nLength,
171
+ lpNumberOfEventsRead )
172
+ type = lpBuffer.unpack('s')[0]
173
+
174
+ case type
175
+ when KEY_EVENT
176
+ return lpBuffer.unpack('sSSSSCS')
177
+ when MOUSE_EVENT
178
+ return lpBuffer.unpack('sSSSS')
179
+ when WINDOW_BUFFER_SIZE_EVENT
180
+ return lpBuffer.unpack('sS')
181
+ when MENU_EVENT
182
+ return lpBuffer.unpack('sS')
183
+ when FOCUS_EVENT
184
+ return lpBuffer.unpack('sS')
185
+ else
186
+ return []
187
+ end
188
+ end
189
+
190
+ def ReadConsoleOutput( hConsoleOutput, lpBuffer, cols, rows, bufx, bufy, left, top, right, bottom )
191
+ @ReadConsoleOutput ||= Win32API.new( "kernel32", "ReadConsoleOutput", ['l', 'p', 'l', 'l', 'p'], 'l' )
192
+ dwBufferSize = cols * rows * 4
193
+ lpBuffer = ' ' * dwBufferSize
194
+ dwBufferCoord = (bufy << 16) + bufx
195
+ lpReadRegion = [ left, top, right, bottom ].pack('ssss')
196
+ @ReadConsoleOutput.call( hConsoleOutput, lpBuffer, dwBufferSize,
197
+ dwBufferCoord, lpReadRegion )
198
+ end
199
+
200
+ def ReadConsoleOutputAttribute( hConsoleOutput, nLength, col, row )
201
+ @ReadConsoleOutputAttribute ||= Win32API.new( "kernel32", "ReadConsoleOutputAttribute", ['l', 'p', 'l', 'l', 'p'], 'l' )
202
+ lpAttribute = ' ' * nLength
203
+ dwReadCoord = (row << 16) + col
204
+ lpNumberOfAttrsRead = ' ' * 4
205
+ @ReadConsoleOutputAttribute.call( hConsoleOutput, lpAttribute, nLength, dwReadCoord, lpNumberOfAttrsRead )
206
+ return lpAttribute
207
+ end
208
+
209
+ def ReadConsoleOutputCharacter( hConsoleOutput, lpCharacter, nLength, col, row )
210
+ @ReadConsoleOutputCharacter ||= Win32API.new( "kernel32", "ReadConsoleOutputCharacter", ['l', 'p', 'l', 'l', 'p'], 'l' )
211
+ dwReadCoord = (row << 16) + col
212
+ lpNumberOfCharsRead = ' ' * 4
213
+ @ReadConsoleOutputCharacter.call( hConsoleOutput, lpCharacter, nLength, dwReadCoord, lpNumberOfCharsRead )
214
+ return lpNumberOfCharsRead.unpack('L')
215
+ end
216
+
217
+ def ScrollConsoleScreenBuffer( hConsoleOutput, left1, top1, right1, bottom1,col, row, char, attr, left2, top2, right2, bottom2 )
218
+ @ScrollConsoleScreenBuffer ||= Win32API.new( "kernel32", "ScrollConsoleScreenBuffer", ['l', 'p', 'p', 'l', 'p'], 'l' )
219
+ lpScrollRectangle = [left1, top1, right1, bottom1].pack('ssss')
220
+ lpClipRectangle = [left2, top2, right2, bottom2].pack('ssss')
221
+ dwDestinationOrigin = (row << 16) + col
222
+ lpFill = [char, attr].pack('ss')
223
+ @ScrollConsoleScreenBuffer.call( hConsoleOutput, lpScrollRectangle, lpClipRectangle, dwDestinationOrigin, lpFill )
224
+ end
225
+
226
+ def SetConsoleActiveScreenBuffer( hConsoleOutput )
227
+ @SetConsoleActiveScreenBuffer ||= Win32API.new( "kernel32", "SetConsoleActiveScreenBuffer", ['l'], 'l' )
228
+ @SetConsoleActiveScreenBuffer.call( hConsoleOutput )
229
+ end
230
+
231
+ # <<SetConsoleCtrlHandler>>: Will probably not be implemented.
232
+
233
+ def SetConsoleCP( wCodePageID )
234
+ @SetConsoleCP ||= Win32API.new( "kernel32", "SetConsoleCP", ['l'], 'l' )
235
+ @SetConsoleCP.call( wCodePageID )
236
+ end
237
+
238
+ def SetConsoleCursorInfo( hConsoleOutput, col, row )
239
+ @SetConsoleCursorInfo ||= Win32API.new( "kernel32", "SetConsoleCursorInfo", ['l', 'p'], 'l' )
240
+ lpConsoleCursorInfo = [size,visi].pack('LL')
241
+ @SetConsoleCursorInfo.call( hConsoleOutput, lpConsoleCursorInfo )
242
+ end
243
+
244
+ def SetConsoleCursorPosition( hConsoleOutput, col, row )
245
+ @SetConsoleCursorPosition ||= Win32API.new( "kernel32", "SetConsoleCursorPosition", ['l', 'p'], 'l' )
246
+ dwCursorPosition = (row << 16) + col
247
+ @SetConsoleCursorPosition.call( hConsoleOutput, dwCursorPosition )
248
+ end
249
+
250
+ def SetConsoleMode( hConsoleHandle, lpMode )
251
+ @SetConsoleMode ||= Win32API.new( "kernel32", "SetConsoleMode", ['l', 'p'], 'l' )
252
+ @SetConsoleMode.call( hConsoleHandle, lpMode )
253
+ end
254
+
255
+ def SetConsoleOutputCP( wCodePageID )
256
+ @SetConsoleOutputCP ||= Win32API.new( "kernel32", "GetConsoleOutputCP", ['l'], 'l' )
257
+ @SetConsoleOutputCP.call( wCodePageID )
258
+ end
259
+
260
+ def SetConsoleScreenBufferSize( hConsoleOutput, col, row )
261
+ @SetConsoleScreenBufferSize ||= Win32API.new( "kernel32", "SetConsoleScreenBufferSize", ['l', 'l'], 'l' )
262
+ dwSize = (row << 16) + col
263
+ @SetConsoleScreenBufferSize.call( hConsoleOutput, dwSize )
264
+ end
265
+
266
+ def SetConsoleTextAttribute( hConsoleOutput, wAttributes )
267
+ @SetConsoleTextAttribute ||= Win32API.new( "kernel32", "SetConsoleTextAttribute", ['l', 'i'], 'l' )
268
+ @SetConsoleTextAttribute.call( hConsoleOutput, wAttributes )
269
+ end
270
+
271
+ def SetConsoleTitle( lpConsoleTitle )
272
+ @SetConsoleTitle ||= Win32API.new( "kernel32", "SetConsoleTitle", ['p'], 'l' )
273
+ @SetConsoleTitle.call( lpConsoleTitle )
274
+ end
275
+
276
+ def SetConsoleWindowInfo( hConsoleOutput, bAbsolute, left, top, right, bottom )
277
+ @SetConsoleWindowInfo ||= Win32API.new( "kernel32", "SetConsoleWindowInfo", ['l', 'l', 'p'], 'l' )
278
+ lpConsoleWindow = [ left, top, right, bottom ].pack('ssss')
279
+ @SetConsoleWindowInfo.call( hConsoleOutput, bAbsolute, lpConsoleWindow )
280
+ end
281
+
282
+ def SetStdHandle( nStdHandle, hHandle )
283
+ @SetStdHandle ||= Win32API.new( "kernel32", "SetStdHandle", ['l', 'l'], 'l' )
284
+ @SetStdHandle.call( nStdHandle, hHandle )
285
+ end
286
+
287
+ def WriteConsole( hConsoleOutput, lpBuffer )
288
+ @WriteConsole ||= Win32API.new( "kernel32", "WriteConsole", ['l', 'p', 'l', 'p', 'p'], 'l' )
289
+ nNumberOfCharsToWrite = lpBuffer.length()
290
+ lpNumberOfCharsWritten = ' ' * 4
291
+ lpReserved = ' ' * 4
292
+ @WriteConsole.call( hConsoleOutput, lpBuffer, nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved )
293
+ return lpNumberOfCharsWritten
294
+ end
295
+
296
+ def WriteFile( hConsoleOutput, lpBuffer )
297
+ @WriteFile ||= Win32API.new( "kernel32", "WriteFile", ['l', 'p', 'l', 'p', 'p'], 'l' )
298
+ nNumberOfBytesToWrite = lpBuffer.length()
299
+ lpNumberOfBytesWritten = ' ' * 4
300
+ lpReserved = nil
301
+ @WriteFile.call( hConsoleOutput, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpReserved )
302
+ return lpNumberOfBytesWritten.unpack('L')
303
+ end
304
+
305
+ def WriteConsoleInput( hConsoleInput, lpBuffer )
306
+ @WriteConsoleInput ||= Win32API.new( "kernel32", "WriteConsoleInput", ['l', 'p', 'l', 'p'], 'l' )
307
+ @WriteConsoleInput.call( hConsoleInput, lpBuffer, nLength, lpNumberOfEventsWritten )
308
+ end
309
+
310
+ # @@ Todo: Test this
311
+ def WriteConsoleOutput( hConsoleOutput, buffer, cols, rows, bufx, bufy, left, top, right, bottom )
312
+ @WriteConsoleOutput ||= Win32API.new( "kernel32", "WriteConsoleOutput", ['l', 'p', 'l', 'l', 'p'], 'l' )
313
+ lpBuffer = buffer.flatten.pack('ss' * buffer.length() * 2)
314
+ dwBufferSize = (buffer.length() << 16) + 2
315
+ dwBufferCoord = (row << 16) + col
316
+ lpWriteRegion = [ left, top, right, bottom ].pack('ssss')
317
+ @WriteConsoleOutput.call( hConsoleOutput, lpBuffer, dwBufferSize, dwBufferCoord, lpWriteRegion )
318
+ end
319
+
320
+ def WriteConsoleOutputAttribute( hConsoleOutput, lpAttribute, col, row )
321
+ @WriteConsoleOutputAttribute ||= Win32API.new( "kernel32", "WriteConsoleOutputAttribute", ['l', 'p', 'l', 'l', 'p'], 'l' )
322
+ nLength = lpAttribute.length()
323
+ dwWriteCoord = (row << 16) + col
324
+ lpNumberOfAttrsWritten = ' ' * 4
325
+ @WriteConsoleOutputAttribute.call( hConsoleOutput, lpAttribute, nLength, dwWriteCoord, lpNumberOfAttrsWritten )
326
+ return lpNumberOfAttrsWritten.unpack('L')
327
+ end
328
+
329
+ def WriteConsoleOutputCharacter( hConsoleOutput, lpCharacter, col, row )
330
+ @WriteConsoleOutputCharacter ||= Win32API.new( "kernel32", "WriteConsoleOutputCharacter", ['l', 'p', 'l', 'l', 'p'], 'l' )
331
+ nLength = lpCharacter.length()
332
+ dwWriteCoord = (row << 16) + col
333
+ lpNumberOfCharsWritten = ' ' * 4
334
+ @WriteConsoleOutputCharacter.call( hConsoleOutput, lpCharacter, nLength, dwWriteCoord, lpNumberOfCharsWritten )
335
+ return lpNumberOfCharsWritten.unpack('L')
336
+ end
337
+
338
+ end
339
+ end
340
+ end
341
+
342
+ end
@@ -0,0 +1,66 @@
1
+ # The WINDOWS constants
2
+
3
+ module Win32
4
+ class Console
5
+ module Constants
6
+ STD_INPUT_HANDLE = 0xFFFFFFF6
7
+ STD_OUTPUT_HANDLE = 0xFFFFFFF5
8
+ STD_ERROR_HANDLE = 0xFFFFFFF4
9
+ INVALID_HANDLE_VALUE = 0xFFFFFFFF
10
+ GENERIC_READ = 0x80000000
11
+ GENERIC_WRITE = 0x40000000
12
+ FILE_SHARE_READ = 0x00000001
13
+ FILE_SHARE_WRITE = 0x00000002
14
+ CONSOLE_TEXTMODE_BUFFER = 0x00000001
15
+
16
+ FOREGROUND_BLUE = 0x0001
17
+ FOREGROUND_GREEN = 0x0002
18
+ FOREGROUND_RED = 0x0004
19
+ FOREGROUND_INTENSITY = 0x0008
20
+ BACKGROUND_BLUE = 0x0010
21
+ BACKGROUND_GREEN = 0x0020
22
+ BACKGROUND_RED = 0x0040
23
+ BACKGROUND_INTENSITY = 0x0080
24
+
25
+ ENABLE_PROCESSED_INPUT = 0x0001
26
+ ENABLE_LINE_INPUT = 0x0002
27
+ ENABLE_ECHO_INPUT = 0x0004
28
+ ENABLE_WINDOW_INPUT = 0x0008
29
+ ENABLE_MOUSE_INPUT = 0x0010
30
+ ENABLE_PROCESSED_OUTPUT = 0x0001
31
+ ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
32
+
33
+ KEY_EVENT = 0x0001
34
+ MOUSE_EVENT = 0x0002
35
+ WINDOW_BUFFER_SIZE_EVENT = 0x0004
36
+ MENU_EVENT = 0x0008
37
+ FOCUS_EVENT = 0x0010
38
+
39
+ CAPSLOCK_ON = 0x0080
40
+ ENHANCED_KEY = 0x0100
41
+ NUMLOCK_ON = 0x0020
42
+ SHIFT_PRESSED = 0x0010
43
+ LEFT_CTRL_PRESSED = 0x0008
44
+ RIGHT_CTRL_PRESSED = 0x0004
45
+ LEFT_ALT_PRESSED = 0x0002
46
+ RIGHT_ALT_PRESSED = 0x0001
47
+ SCROLLLOCK_ON = 0x0040
48
+
49
+ MOUSE_WHEELED = 0x0004
50
+ DOUBLE_CLICK = 0x0002
51
+ MOUSE_MOVED = 0x0001
52
+
53
+ FROM_LEFT_1ST_BUTTON_PRESSED = 0x0001
54
+ FROM_LEFT_2ND_BUTTON_PRESSED = 0x0004
55
+ FROM_LEFT_3RD_BUTTON_PRESSED = 0x0008
56
+ FROM_LEFT_4TH_BUTTON_PRESSED = 0x0010
57
+ RIGHTMOST_BUTTON_PRESSED = 0x0002
58
+
59
+ CTRL_C_EVENT = 0x0000
60
+ CTRL_BREAK_EVENT = 0x0001
61
+ CTRL_CLOSE_EVENT = 0x0002
62
+ CTRL_LOGOFF_EVENT = 0x0005
63
+ CTRL_SHUTDOWN_EVENT = 0x0006
64
+ end
65
+ end
66
+ end