powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Прошу помощи - консольная утилита
10 сообщений из 35, страница 2 из 2
Прошу помощи - консольная утилита
    #35706354
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А чем огорчил?
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35706410
Фотография Игорь Горбонос
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
> Автор: Grayscale
> Меня нет на VBStreets))))

Значит ошибся, извини

> А чем огорчил?

Да уже ничем.

--
С уважением Горбонос Игорь Леонидович

Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35714170
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Еще раз позволю себе поучать глупыми вопросами... Точнее одним. В этом проекте
HandKotвот пример консольного приложения,
а алгоритм нужный вам сами напишите

I Have Nine Lives You Have One Only
THINK!
консоль приложением используется та, из которой запускалось приоложение, я - же тупо скопироваав все подряд получаю новую консоль (итого 2)... Оба приложения standart exe... с чем это связано? никак не пойму...
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35714253
Фотография Игорь Горбонос
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
> Автор: Grayscale
> консоль приложением используется та, из которой запускалось приоложение, я - же тупо скопироваав все подряд
> получаю новую консоль (итого 2)... Оба приложения standart exe... с чем это связано? никак не пойму...


Ничего не понял

--
С уважением Горбонос Игорь Леонидович

Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35714287
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Я скачал пример из сообщения, что цитировал. При запуске он отрабатывает так как мне бы хотелось, поковырялся разобрался, взял нужное, но при запуске из консоли командой projectName, мой проект создает еще одну консоль все что делаю (allocConsole, getStdHandle, writeFile), замучался, тупо скопировал из того проекта код в свой(модуль console), и выполняю 2 оператора (intializeConsole,conPrint), но все равно появляется 2 консоли! Проверил свойства проектов - совпадают в чем беда не понимаю...
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35714343
Фотография Игорь Горбонос
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Тогда может быть сделаешь маленький пример и выложишь сюда, а то магический шар запотел, после выходных

--
С уважением Горбонос Игорь Леонидович

Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35714374
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Это то что не удается запустить, как надо мне самому...
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Public Function WriteCon(s As String) As Long
Dim info As STARTUPINFO
Dim TMP As Long
Dim result As Long
Dim sOut As String
    AllocConsole
    GetStartupInfo info
    sOut = "cool" & Chr( 0 )
    TMP = GetStdHandle(STD_OUTPUT_HANDLE)
    WriteFile TMP, ByVal sOut,  4 , TMP,  0 
    MsgBox  1 
    FreeConsole
End Function


Это то что не запустить, используя сторонний модуль, в проекте автора работает...
Код: plaintext
1.
2.
InitializeConsole
ConPrint "COOL"



Это модуль из примера
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
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.
510.
511.
512.
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
525.
526.
527.
528.
529.
530.
531.
532.
533.
534.
535.
536.
537.
538.
539.
540.
541.
542.
543.
544.
545.
546.
547.
548.
549.
550.
551.
552.
553.
554.
555.
556.
557.
558.
559.
560.
561.
562.
563.
564.
565.
566.
567.
568.
569.
570.
571.
572.
573.
574.
575.
576.
577.
578.
579.
580.
581.
582.
583.
584.
585.
586.
587.
588.
589.
590.
591.
592.
593.
594.
595.
596.
597.
598.
599.
600.
601.
602.
603.
604.
605.
606.
607.
608.
609.
610.
611.
612.
613.
614.
615.
616.
617.
618.
619.
620.
621.
622.
623.
624.
625.
626.
627.
628.
629.
630.
631.
632.
633.
634.
635.
636.
637.
638.
639.
640.
641.
642.
643.
644.
645.
646.
647.
648.
649.
650.
651.
652.
653.
654.
655.
656.
657.
658.
659.
660.
661.
662.
663.
664.
665.
666.
667.
668.
669.
670.
671.
672.
'///////////////////////////////////////////////////////////////////////////
'// Ìîäóëü äëÿ ðàáîòû ñ êîíñîëüþ                                          //
'// Copyright (c) 2004 Äìèòðèé Êîçûðåâ, me@mastershome.net.ru             //
'///////////////////////////////////////////////////////////////////////////
Option Explicit

Public Enum enmConsoleHandle
    chInput
    chOutput
    chError
End Enum

Public Enum enmBreakMode
    bmCtrlC =  0 
    bmCtrlBReak =  1 
    bmClose =  2 
    bmLogOff =  5 
    bmShutdown =  6 
    bmNoBrake = - 1 
End Enum

Public Enum enmColor
    clBlue =  1 
    clGreen =  2 
    clRed =  4 
    clIntensity =  8 
End Enum

Public Enum enmEventType
    etKeyEvent =  1 
    etMouseEvent =  2 
    etWindowBufferSizeEvent =  4 
    etMenuEvent =  8 
    etFocusEvent =  16 
    etNone =  0 
End Enum

Public Enum enmControlKeyState
    csRightAltPressed = &H1
    csLeftAltPressed = &H2
    csRightCtrlPressed = &H4
    csleftCtrlPressed = &H8
    csShiftPressed = &H10
    csNumlockOn = &H20
    csScrollLockOn = &H40
    csCapsLockOn = &H80
    csEnhancedKey = &H100
End Enum

Public Enum enmMouseEventFlags
    CLICK_OR_RELEASE =  0 
    MOUSE_MOVED =  1 
    DOUBLE_CLICK =  2 
    MOUSE_WHEELED =  4 
End Enum

Public Enum enmMouseButton
    FROM_LEFT_1ST_BUTTON_PRESSED =  1 
    RIGHTMOST_BUTTON_PRESSED =  2 
    FROM_LEFT_2ND_BUTTON_PRESSED =  4 
    FROM_LEFT_3RD_BUTTON_PRESSED =  8 
    FROM_LEFT_4TH_BUTTON_PRESSED =  16 
End Enum

Private bCtrlHandler() As Byte
Private mBrakeMode As Long

Private hStdIn      As Long
Private hStdOut     As Long
Private hStdErr     As Long

Private mReadBuffer As String

Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long

Private Declare Function GetStdHandle Lib "kernel32" _
    (ByVal nStdHandle As Long) As Long

Private Const STD_INPUT_HANDLE = - 10 &
Private Const STD_OUTPUT_HANDLE = - 11 &
Private Const STD_ERROR_HANDLE = - 12 &

Private Declare Function GetConsoleTitle Lib "kernel32" _
    Alias "GetConsoleTitleA" _
    (ByVal lpConsoleTitle As String, _
    ByVal nSize As Long) As Long
Private Declare Function SetConsoleTitle Lib "kernel32" _
    Alias "SetConsoleTitleA" _
    (ByVal lpConsoleTitle As String) As Long

Private Declare Function CharToOem Lib "user32" Alias "CharToOemA" _
    (ByVal lpszSrc As String, ByVal lpszDst As String) As Long
Private Declare Function OemToChar Lib "user32" Alias "OemToCharA" _
    (ByVal lpszSrc As String, ByVal lpszDst As String) As Long

Private Declare Function WriteFile Lib "kernel32" _
    (ByVal hFile As Long, _
    lpBuffer As Any, _
    ByVal nNumberOfBytesToWrite As Long, _
    lpNumberOfBytesWritten As Long, _
    lpOverlapped As Any) As Long

Private Declare Function ReadFile Lib "kernel32" _
    (ByVal hFile As Long, _
    lpBuffer As Any, _
    ByVal nNumberOfBytesToRead As Long, _
    lpNumberOfBytesRead As Long, _
    lpOverlapped As Any) As Long

Private Declare Function GetConsoleCursorInfo Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    lpConsoleCursorInfo As CONSOLE_CURSOR_INFO) As Long

Private Declare Function SetConsoleCursorInfo Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    lpConsoleCursorInfo As CONSOLE_CURSOR_INFO) As Long

Private Type CONSOLE_CURSOR_INFO
    dwSize As Long
    bVisible As Long
End Type

Private Declare Function GetNumberOfConsoleInputEvents Lib "kernel32" _
    (ByVal hConsoleInput As Long, _
    lpNumberOfEvents As Long) As Long

Private Const ERROR_INVALID_HANDLE =  6 &

Private Declare Function GetConsoleScreenBufferInfo Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    lpConsoleScreenBufferInfo As CONSOLE_SCREEN_BUFFER_INFO) As Long

Private Declare Function SetConsoleCursorPosition Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    ByVal Coord As Long) As Long

Private Type Coord
    X As Integer
    Y As Integer
End Type

Private Type SMALL_RECT
    Left As Integer
    Top As Integer
    Right As Integer
    Bottom As Integer
End Type

Private Type CONSOLE_SCREEN_BUFFER_INFO
    dwSize As Coord
    dwCursorPosition As Coord
    wAttributes As Integer
    srWindow As SMALL_RECT
    dwMaximumWindowSize As Coord
End Type

Private Declare Function SetConsoleScreenBufferSize Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    ByVal dwSize As Long) As Long

Private Declare Function SetConsoleCtrlHandler Lib "kernel32" _
    (ByVal HandlerRoutine As Long, _
    ByVal Add As Long) As Long

Private Declare Function FillConsoleOutputAttribute Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    ByVal wAttribute As Long, _
    ByVal nLength As Long, _
    ByVal dwWriteCoord As Long, _
    lpNumberOfAttrsWritten As Long) As Long

Private Declare Function FillConsoleOutputCharacter Lib "kernel32" _
    Alias "FillConsoleOutputCharacterA" _
    (ByVal hConsoleOutput As Long, _
    ByVal cCharacter As Byte, _
    ByVal nLength As Long, _
    ByVal dwWriteCoord As Long, _
    lpNumberOfCharsWritten As Long) As Long

Private Declare Function SetConsoleMode Lib "kernel32" _
    (ByVal hConsoleHandle As Long, _
    ByVal dwMode As Long) As Long

Private Declare Function GetConsoleMode Lib "kernel32" _
    (ByVal hConsoleHandle As Long, _
    lpMode As Long) As Long

Private Const ENABLE_LINE_INPUT = &H2
Private Const ENABLE_ECHO_INPUT = &H4
Private Const ENABLE_MOUSE_INPUT = &H10
Private Const ENABLE_PROCESSED_INPUT = &H1
Private Const ENABLE_WINDOW_INPUT = &H8
Private Const ENABLE_PROCESSED_OUTPUT = &H1
Private Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2

Private Declare Function ReadConsoleOutputCharacter Lib "kernel32" _
    Alias "ReadConsoleOutputCharacterA" _
    (ByVal hConsoleOutput As Long, _
    ByVal lpCharacter As String, _
    ByVal nLength As Long, _
    ByVal dwReadCoord As Long, _
    lpNumberOfCharsRead As Long) As Long

Private Declare Function ReadConsoleOutputAttribute Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    lpAttribute As Long, _
    ByVal nLength As Long, _
    ByVal dwReadCoord As Long, _
    lpNumberOfAttrsRead As Long) As Long

Private Declare Function SetConsoleTextAttribute Lib "kernel32" _
    (ByVal hConsoleOutput As Long, _
    ByVal wAttributes As Long) As Long

Private Declare Function ReadConsoleInput Lib "kernel32" Alias "ReadConsoleInputA" _
    (ByVal hConsoleInput As Long, _
    InputRecord As INPUT_RECORD, _
    ByVal nRecords As Long, _
    ByRef nEventsRead As Long) As Long

Private Declare Function PeekConsoleInput Lib "kernel32" Alias "PeekConsoleInputA" _
    (ByVal hConsoleInput As Long, _
    InputRecord As INPUT_RECORD, _
    ByVal nRecords As Long, _
    ByRef nEventsRead As Long) As Long

Private Type INPUT_RECORD
    EventType           As Integer
    Reserved            As Integer
    EventData( 0  To  15 )  As Byte
End Type

Public Type KEY_EVENT_RECORD
    bKeyDown            As Long
    wRepeatCount        As Integer
    wVirtualKeyCode     As Integer
    wVirtualScanCode    As Integer
    Char                As Byte
    Reserved            As Byte
    dwControlKeyState   As Long
End Type

Public Type MOUSE_EVENT_RECORD
    dwMousePosition As Coord
    dwButtonState As Long
    dwControlKeyState As Long
    dwEventFlags As Long
End Type

Public Type WINDOW_BUFFER_SIZE_RECORD
    dwSize As Coord
End Type

Private Declare Function FlushConsoleInputBuffer Lib "kernel32" _
    (ByVal hConsoleInput As Long) As Long

Private Declare Function MsgWaitForMultipleObjects Lib "user32" _
    (ByVal nCount As Long, _
    pHandles As Long, _
    ByVal fWaitAll As Long, _
    ByVal dwMilliseconds As Long, _
    ByVal dwWakeMask As Long) As Long

Private Const QS_ALLINPUT = &HFF&
Private Const WAIT_OBJECT_0 =  0 
Private Const INFINITE = &HFFFFFFFF

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)

Private Declare Function PeekNamedPipe Lib "kernel32" _
    (ByVal hNamedPipe As Long, _
    lpBuffer As Any, _
    ByVal nBufferSize As Long, _
    lpBytesRead As Long, _
    lpTotalBytesAvail As Long, _
    lpBytesLeftThisMessage As Long) As Long

Public Property Get BreakMode() As enmBreakMode
BreakMode = mBrakeMode
End Property

Public Property Get Caption() As String
Dim sCaption As String
sCaption = String$( 256 ,  0 )
sCaption = Left$(sCaption, GetConsoleTitle(sCaption, Len(sCaption)))
Caption = sCaption
End Property

Public Property Let Caption(ByVal NewCaption As String)
SetConsoleTitle NewCaption
End Property

Public Sub Clear()
FillWithChar  0 ,  0 , Width * Height,  0 , False
MoveCursor  0 ,  0 
End Sub

Public Sub ConPrint(Optional ByVal Text As String, _
    Optional ByVal EndLine As Boolean = True, _
    Optional ByVal AutoTranslate As Boolean = True, _
    Optional ByVal ToError As Boolean = False)
Dim sOut As String
sOut = String$(Len(Text),  0 )

If AutoTranslate Then CharToOem Text, sOut

If EndLine Then sOut = sOut & vbCrLf

Dim w As Long, h As Long
h = IIf(ToError, hStdErr, hStdOut)

WriteFile h, ByVal sOut, Len(sOut), w, ByVal  0 &
End Sub

Public Function ConRead( _
    Optional ByVal AutoTranslate As Boolean = True) As String
Dim sIn As String, sRet As String, r As Long, lAvail As Long

sIn = String$( 256 ,  0 )

Do While InStr(mReadBuffer, vbCrLf) =  0 
    If PeekNamedPipe(hStdIn, ByVal  0 &,  0 , ByVal  0 &, lAvail, ByVal  0 &) Then
        If lAvail =  0  Then Exit Do
    End If
    If ReadFile(hStdIn, ByVal sIn, Len(sIn), r, ByVal  0 &) Then
        mReadBuffer = mReadBuffer & Left$(sIn, r)
    Else
        Exit Do
    End If
Loop

Dim iLineEnd As Long
iLineEnd = InStr(mReadBuffer, vbCrLf)
If iLineEnd Then
    sRet = Left$(mReadBuffer, iLineEnd -  1 )
    mReadBuffer = Mid$(mReadBuffer, iLineEnd +  2 )
Else
    sRet = mReadBuffer
    mReadBuffer = vbNullString
End If

If AutoTranslate Then OemToChar sRet, sRet

ConRead = sRet
End Function

Public Property Get CursorVisible() As Boolean
Dim ci As CONSOLE_CURSOR_INFO
GetConsoleCursorInfo hStdOut, ci
CursorVisible = ci.bVisible
End Property

Public Property Let CursorVisible(ByVal NewVisibility As Boolean)
Dim ci As CONSOLE_CURSOR_INFO
GetConsoleCursorInfo hStdOut, ci

ci.bVisible = Abs(NewVisibility)

SetConsoleCursorInfo hStdOut, ci
End Property

Public Property Get CursorHeight() As Double
Dim ci As CONSOLE_CURSOR_INFO
GetConsoleCursorInfo hStdOut, ci
CursorHeight = CDbl(ci.dwSize) /  100 
End Property

Public Property Let CursorHeight(ByVal NewHeight As Double)
Dim ci As CONSOLE_CURSOR_INFO
GetConsoleCursorInfo hStdOut, ci

If NewHeight <  0 . 01  Then NewHeight =  0 . 01 
If NewHeight >  1  Then NewHeight =  1 

ci.dwSize = NewHeight *  100 

SetConsoleCursorInfo hStdOut, ci
End Property

Public Property Get CursorX() As Integer
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
CursorX = si.dwCursorPosition.X
End Property

Public Property Get CursorY() As Integer
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
CursorY = si.dwCursorPosition.Y
End Property

Public Property Let CursorX(ByVal NewX As Integer)
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
SetConsoleCursorPosition hStdOut, GetCoord(NewX, si.dwCursorPosition.Y)
End Property

Public Property Let CursorY(ByVal NewY As Integer)
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
SetConsoleCursorPosition hStdOut, GetCoord(si.dwCursorPosition.X, NewY)
End Property

Public Sub DiscardEvent()
Dim r As INPUT_RECORD
Dim lRead As Long
If PeekConsoleInput(hStdIn, r,  1 , lRead) And lRead >  0  Then
    ReadConsoleInput hStdIn, r,  1 , lRead
End If
End Sub

Public Property Get EndOfInput() As Boolean
Dim sIn As String, r As Long, lAvail As Long
sIn = String$( 256 ,  0 )

If PeekNamedPipe(hStdIn, ByVal  0 &,  0 , ByVal  0 &, lAvail, ByVal  0 &) Then
    EndOfInput = (lAvail =  0 )
ElseIf ReadFile(hStdIn, ByVal sIn, Len(sIn), r, ByVal  0 &) Then
    EndOfInput = (r =  0 )
    mReadBuffer = mReadBuffer & Left$(sIn, r)
Else
    EndOfInput = True
End If
End Property

Public Sub Fill(ByVal X As Integer, ByVal Y As Integer, _
    ByVal nCells As Long, ByVal ForeColor As enmColor, _
    ByVal BackColor As enmColor)
Dim lWritten As Long
FillConsoleOutputAttribute hStdOut, MakeColor(ForeColor, BackColor), _
    nCells, GetCoord(X, Y), lWritten
End Sub

Public Sub FillWithChar(ByVal X As Integer, ByVal Y As Integer, _
    ByVal nCells As Long, ByVal Character As Byte, _
    Optional ByVal AutoTranslate As Boolean = True)
Dim lWritten As Long
FillConsoleOutputCharacter hStdOut, Character, nCells, _
    GetCoord(X, Y), lWritten
End Sub

Public Sub FlushInputBuffer()
FlushConsoleInputBuffer hStdIn
End Sub

Public Property Get ForeColor() As enmColor
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
ForeColor = (si.wAttributes And &HF&)
End Property

Public Property Get BackColor() As enmColor
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
BackColor = ((si.wAttributes And &HF0&) \ &H10&)
End Property

Public Property Let ForeColor(ByVal NewColor As enmColor)
SetConsoleTextAttribute hStdOut, (NewColor And &HF) Or BackColor * &H10&
End Property

Public Property Let BackColor(ByVal NewColor As enmColor)
SetConsoleTextAttribute hStdOut, (NewColor And &HF) * &H10& Or ForeColor
End Property

Private Function GetCoord(ByVal X As Integer, ByVal Y As Integer) As Long
Dim lRes As Long
Dim c As Coord
c.X = X
c.Y = Y
CopyMemory lRes, c,  4 
GetCoord = lRes
End Function

Public Property Get HasBreak() As Boolean
HasBreak = (mBrakeMode <> bmNoBrake)
End Property

Public Function GetInputEventType() As enmEventType
Dim r As INPUT_RECORD
Dim lRead As Long
GetInputEventType = etNone
If PeekConsoleInput(hStdIn, r,  1 , lRead) Then
    If lRead >  0  Then
        GetInputEventType = r.EventType
    End If
End If
End Function

Public Function WaitForEvent() As enmEventType
Dim r As INPUT_RECORD
Dim lRead As Long

WaitForEvent = etNone

Do While MsgWaitForMultipleObjects( 1 , hStdIn,  0 , INFINITE, _
            QS_ALLINPUT) <> WAIT_OBJECT_0
    DoEvents
    If HasBreak Then Exit Do
Loop

If PeekConsoleInput(hStdIn, r,  1 , lRead) And lRead >  0  Then
    WaitForEvent = r.EventType
End If
End Function

Private Function MakeColor(ByVal ForeColor As enmColor, _
    ByVal BackColor As enmColor) As Integer
MakeColor = (ForeColor And &HF) + (BackColor And &HF) * &H10
End Function

Public Sub MoveCursor(ByVal X As Integer, ByVal Y As Integer)
Dim NewPos As Coord
NewPos.X = X
NewPos.Y = Y
SetConsoleCursorPosition hStdOut, GetCoord(X, Y)
End Sub

Public Property Get IsConsole(ByVal Handle As enmConsoleHandle) As Boolean
Dim b As Boolean
Select Case Handle
    Case chInput
        Dim l As Long
        b = CBool(GetNumberOfConsoleInputEvents(hStdIn, l))
        IsConsole = b And (Err.LastDllError <> ERROR_INVALID_HANDLE)
    Case chOutput, chError
        Dim h As Long, ci As CONSOLE_CURSOR_INFO
        If Handle = chOutput Then h = hStdOut Else h = hStdErr
        b = CBool(GetConsoleCursorInfo(h, ci))
        IsConsole = b And (Err.LastDllError <> ERROR_INVALID_HANDLE)
End Select
End Property

Public Function ReadDataFromOutput(ByVal X As Integer, ByVal Y As Integer, _
    ByVal nCells, Optional ByVal AutoTranslate As Boolean = True) As String
Dim s As String, lRead As Long
s = String$(nCells,  0 )
ReadConsoleOutputCharacter hStdOut, s, nCells, GetCoord(X, Y), lRead
s = Left$(s, lRead)

If AutoTranslate Then OemToChar s, s

ReadDataFromOutput = s
End Function

Public Function ReadForeColorFromOutput(ByVal X As Integer, _
    ByVal Y As Integer) As enmColor
Dim lColor As Long, lRead As Long
ReadConsoleOutputAttribute hStdOut, lColor,  1 , GetCoord(X, Y), lRead
ReadForeColorFromOutput = (lColor And &HF&)
End Function

Public Function ReadBackColorFromOutput(ByVal X As Integer, _
    ByVal Y As Integer) As enmColor
Dim lColor As Long, lRead As Long
ReadConsoleOutputAttribute hStdOut, lColor,  1 , GetCoord(X, Y), lRead
ReadBackColorFromOutput = ((lColor And &HF0&) \ &H10&)
End Function

Public Function ReadKey() As KEY_EVENT_RECORD
Dim r As INPUT_RECORD
Dim lRead As Long
Do While ReadConsoleInput(hStdIn, r,  1 , lRead)
    If r.EventType = etKeyEvent Then
        CopyMemory ReadKey, r.EventData( 0 ), Len(ReadKey)
        Exit Function
    End If
Loop
End Function

Public Function ReadMouse() As MOUSE_EVENT_RECORD
Dim r As INPUT_RECORD
Dim lRead As Long
Do While ReadConsoleInput(hStdIn, r,  1 , lRead)
    If r.EventType = etMouseEvent Then
        CopyMemory ReadMouse, r.EventData( 0 ), Len(ReadMouse)
        Exit Function
    End If
Loop
End Function

Public Function ReadWindowResize() As WINDOW_BUFFER_SIZE_RECORD
Dim r As INPUT_RECORD
Dim lRead As Long
Do While ReadConsoleInput(hStdIn, r,  1 , lRead)
    If r.EventType = etWindowBufferSizeEvent Then
        CopyMemory ReadWindowResize, r.EventData( 0 ), Len(ReadWindowResize)
        Exit Function
    End If
Loop
End Function

Public Property Get MouseInputEnabled() As Boolean
Dim lMode As Long
GetConsoleMode hStdIn, lMode
MouseInputEnabled = CBool(lMode And ENABLE_MOUSE_INPUT)
End Property

Public Property Let MouseInputEnabled(ByVal NewValue As Boolean)
Dim lMode As Long
GetConsoleMode hStdIn, lMode
lMode = lMode And (&HFFFFFFFF Xor ENABLE_MOUSE_INPUT)
If NewValue Then lMode = lMode Or ENABLE_MOUSE_INPUT
SetConsoleMode hStdIn, lMode
End Property

Public Property Let Width(ByVal NewWidth As Integer)
SetConsoleScreenBufferSize hStdOut, GetCoord(NewWidth, Height)
End Property

Public Property Let Height(ByVal NewHeight As Integer)
SetConsoleScreenBufferSize hStdOut, GetCoord(Width, NewHeight)
End Property

Public Property Get Width() As Integer
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
Width = si.dwSize.X
End Property

Public Property Get Height() As Integer
Dim si As CONSOLE_SCREEN_BUFFER_INFO
GetConsoleScreenBufferInfo hStdOut, si
Height = si.dwSize.Y
End Property

Public Sub InitializeConsole()
AllocConsole

hStdIn = GetStdHandle(STD_INPUT_HANDLE)
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
hStdErr = GetStdHandle(STD_ERROR_HANDLE)

Dim lMode As Long
GetConsoleMode hStdIn, lMode
lMode = lMode Or ENABLE_PROCESSED_INPUT Or ENABLE_WINDOW_INPUT Or _
    ENABLE_LINE_INPUT Or ENABLE_ECHO_INPUT
SetConsoleMode hStdIn, lMode
    
GetConsoleMode hStdOut, lMode
lMode = lMode Or ENABLE_WRAP_AT_EOL_OUTPUT Or ENABLE_PROCESSED_OUTPUT
SetConsoleMode hStdOut, lMode

MouseInputEnabled = True

mBrakeMode = bmNoBrake

ReDim bCtrlHandler( 0  To  13 )
bCtrlHandler( 0 ) = &H68                            ' push <variable address>
CopyMemory bCtrlHandler( 1 ), VarPtr(mBrakeMode),  4 
bCtrlHandler( 5 ) = &H5B                            ' pop ebx
bCtrlHandler( 6 ) = &H58                            ' pop eax
bCtrlHandler( 7 ) = &H8F                            ' pop dword ptr [ebx]
bCtrlHandler( 8 ) = &H3
bCtrlHandler( 9 ) = &H50                            ' push eax
bCtrlHandler( 10 ) = &H33                           ' xor eax, eax
bCtrlHandler( 11 ) = &HC0
bCtrlHandler( 12 ) = &H40                           ' inc eax
bCtrlHandler( 13 ) = &HC3                           ' ret

SetConsoleCtrlHandler VarPtr(bCtrlHandler( 0 )),  1 
End Sub

Public Sub TerminateConsole()
SetConsoleCtrlHandler VarPtr(bCtrlHandler( 0 )),  0 

FreeConsole
End Sub
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35715383
Фотография Игорь Горбонос
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
> Автор: Grayscale
> Это то что не удается запустить, как надо мне самому...
>
> Public Function WriteCon(s As String) As Long
> Dim info As STARTUPINFO
> Dim TMP As Long
> Dim result As Long
> Dim sOut As String
> AllocConsole
> GetStartupInfo info
> sOut = "cool" & Chr(0)

Если ты получил STARTUPINFO, так и бери оттуда хендл консоли
Зачем получать новый, к тому-же стандартный может отличатся от того, что получишь из структуры

> TMP = GetStdHandle(STD_OUTPUT_HANDLE)
> WriteFile TMP, ByVal sOut, 4, TMP, 0
> MsgBox 1
> FreeConsole
> End Function


Я все равно не понял, твоей проблемы :(

--
С уважением Горбонос Игорь Леонидович

Posted via ActualForum NNTP Server 1.4
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35715471
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
В startupinfo всегда, почему-то лежит -1(( А проблема в том что открывается вторая консоль...
...
Рейтинг: 0 / 0
Прошу помощи - консольная утилита
    #35715472
Grayscale
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
этот код
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Public Function WriteCon(s As String) As Long
Dim info As STARTUPINFO
Dim tmp As Long
Dim result As Long
Dim sOut As String
    AllocConsole
    GetStartupInfo info
    sOut = "cool" & Chr( 0 )
    tmp = GetStdHandle(STD_OUTPUT_HANDLE)
    WriteFile tmp, ByVal sOut,  4 , tmp,  0 
    MsgBox  1 
    FreeConsole
End Function
...
Рейтинг: 0 / 0
10 сообщений из 35, страница 2 из 2
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / Прошу помощи - консольная утилита
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]