I couldn't find a compelete console class for VB, and most of the good ones are in C#. So I just converted some code to vb.net to add it to my library. It's mainly from a project called ExtendedConsole which is written in C#. But I made some changed.... and I think I combined some other programs from C# and VB6 to make this
Also see the next post for the rest of the code
Last edited by MrPolite; Jun 5th, 2005 at 04:43 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
' Echo Input would let the program to receive each key stroke.
Friend Const ENABLE_LINE_INPUT As Short = &H2S
Friend Const ENABLE_ECHO_INPUT As Short = &H4S
' Color codes
Friend Const FOREGROUND_BLUE As Integer = &H1&
Friend Const FOREGROUND_GREEN As Integer = &H2&
Friend Const FOREGROUND_RED As Integer = &H4&
Friend Const FOREGROUND_INTENSIFY As Integer = &H8&
Friend Const BACKGROUND_BLUE As Integer = &H10&
Friend Const BACKGROUND_GREEN As Integer = &H20&
Friend Const BACKGROUND_INTENSIFY As Integer = &H80&
Public Enum BACKGROUNDCOLOR
bBLUE = &H10& 'BACKGROUND_BLUE
bGREEN = &H20& 'BACKGROUND_GREEN
bRED = &H40& 'BACKGROUND_RED
bBRIGHT = &H80& 'BACKGROUND_INTENSITY
End Enum
<StructLayout(LayoutKind.Sequential)> _
Friend Structure COORD
Friend x, y As Short
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure RECT
Dim Left, Top, Right, Bottom As Short
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure CONSOLE_INFO
Friend Size As COORD
Friend CursorPosition As COORD
Friend Attribute As Short
Friend Window As RECT
Friend MaxSize As COORD
End Structure
<StructLayout(LayoutKind.Sequential)> _
Friend Structure CURSOR_INFO
Friend Size As Integer
Friend Visible As Boolean
End Structure
<DllImport("kernel32")> _
Public Shared Sub SetConsoleTitle(ByVal lpTitleStr As String)
End Sub
<DllImport("kernel32")> _
Public Shared Sub GetConsoleTitle(ByVal lpBuff As StringBuilder, ByVal buffSize As Integer)
End Sub
<DllImport("kernel32")> _
Public Shared Function SetConsoleTextAttribute(ByVal hConsoleOutput As IntPtr, ByVal wAttributes As Integer) As Integer
End Function
<DllImport("kernel32")> _
Public Shared Function FillConsoleOutputCharacter(ByVal Handle As IntPtr, ByVal uChar As Char, _
ByVal Len As Integer, ByVal start As COORD, ByRef written As Integer) As Integer
End Function
<DllImport("kernel32")> _
Public Shared Function FillConsoleOutputAttribute(ByVal Handle As IntPtr, ByVal att As Short, _
ByVal Len As Integer, ByVal start As COORD, _
ByRef writted As Integer) As Boolean
End Function
<DllImport("kernel32")> _
Public Shared Sub GetConsoleScreenBufferInfo(ByVal Handle As IntPtr, _
ByRef info As CONSOLE_INFO)
End Sub
<DllImport("kernel32")> _
Public Shared Function SetConsoleCursorInfo(ByVal Handle As IntPtr, ByRef info As CURSOR_INFO) As Boolean
End Function
<DllImport("kernel32")> _
Public Shared Function SetConsoleCursorPosition(ByVal handle As IntPtr, ByVal coord As Integer) As Boolean
End Function
<DllImport("kernel32")> _
Public Shared Function GetStdHandle(ByVal nStdHandle As Integer) As IntPtr
End Function
<DllImport("kernel32")> _
Public Shared Sub GetConsoleMode(ByVal hConsoleHandle As IntPtr, ByRef lpMode As Integer)
End Sub
<DllImport("kernel32")> _
Public Shared Sub SetConsoleMode(ByVal hConsoleHandle As IntPtr, ByVal dwMode As Integer)
End Sub
<DllImport("kernel32")> _
Public Shared Function CloseHandle(ByVal hObject As IntPtr) As Integer
End Function
<DllImport("kernel32")> _
Public Shared Function AllocConsole() As Integer
End Function
<DllImport("kernel32")> _
Public Shared Function FreeConsole() As Integer
End Function
End Class
Last edited by MrPolite; Jun 5th, 2005 at 04:44 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Btw is there a way to create a console in a windows forms project, using the default System.Console class?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by Pirate What benefit would someone gets from this code ??
Lets you:
-change the foreground or background color of the text
-change the background color of the console (call SetCLSColor, and then the Clear function)
-Change or read the title of the console
-clear a console window
-change the input mode of the console (call SetMode - whether it should read the input line by line, or to read every key stroke one by one)
-move the cursor to any random position
-enable/disable showing what the user types in the console ( call EchoInput )
-get the size of the console window (number of columns and rows)
-get the current position of the cursor
-change the cursor type (the carret)
-close the console whenever you want (FreeConsole() )
-create a console by calling this class (althought it doesnt let you read/write.... it may not be necessary if someone can answer my previous post in this thread)
only one of these is enough reason for me to use this class. You don't have to use this instead of the Console class. In a console app, you just define an instance of this class and you can use it as a "tool". I dont know, but if it's necessary I can add the Read/Readline/Write functions to it and make it like a stand-alone console so you wouldn't need the system.console at all. I just need to know if it's possible to create a System.Console window in a windows forms project (and I believe it should be)
Last edited by MrPolite; May 25th, 2003 at 05:42 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
aah forgot a peice.... added a new function. Lets you change the background color of the console as well as the background color of the text.
VB Code:
Public Sub SetClsColor(ByVal backColor As ConsoleColor)
backgroundAttrib = CShort(backColor) * &H10S
End Sub
You call this and choose a backcolor, and then you call the Clear function. It will change the backcolor of the console.
What I don't understand is that the C# version of this function received a backcolor AND a forecolor, while the forecolor seems quite useless (since it doesnt affect the text color). So I just removed the forecolor from the function. In case I'm wrong, here's the original function:
VB Code:
static public void SetClsColor(ConsoleColor back, ConsoleColor fore)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by MrPolite Btw is there a way to create a console in a windows forms project, using the default System.Console class?
At first glance, it looks like you can't. It looks like, in a windows forms project, you have to use api calls, even to write to the console, and you probably have to call the AllocConsole API to make a console window for your process first. Maybe I'll test this further later, but that's how it looks.
Right now, I don't have much time, but I do know how to use the console api functions, if you need help, as I had to write a similar class like this for myself, which actually does far more than this one you posted does..
Last edited by MrPolite; Jun 5th, 2005 at 04:51 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
and here's the code of it, if you dont wanna download it.... put this in a console project, as sub main. Put the consoleEx class and Win32Native in the project also
VB Code:
Module Module1
Sub Main()
Dim conEx As New ConsoleEx
Console.WriteLine("Hello world... changing the title")
conEx.Title = "New Title!"
Console.WriteLine("The new title is: " & conEx.Title)
Console.WriteLine()
Console.WriteLine("Type something. Everything will be shown in upper-case. Press enter to stop:")
' Change the input mode to receive every key stroke
conEx.SetMode(ConsoleEx.InputMode.EchoInput)
Do
Dim asciiCode As Integer
Dim aChar As Char
' Note that I'm not calling the Readline method, I'm calling the Read method in this mode
asciiCode = CInt(Console.Read()) ' Returns the ascii code of the entered character
' 13 is the code for enter
If asciiCode = 13 Then
Exit Do
End If
' Convert the asciicode to its character
aChar = Chr(asciiCode)
aChar = Char.ToUpper(aChar)
Console.Write(aChar)
Loop
Console.WriteLine()
Console.WriteLine("Press anykey to clear the screen...")
Console.WriteLine("Turning off the echo, type something and press enter...")
conEx.EchoInput(False)
Dim tmpStr As String = Console.ReadLine()
Console.WriteLine("You typed: " & tmpStr)
conEx.EchoInput(True)
conEx.SetMode(ConsoleEx.InputMode.EchoInput)
Console.WriteLine("Press any key to continue...")
Console.Read()
conEx.SetMode(ConsoleEx.InputMode.LineInput)
conEx.Clear()
' (1 is the smallest position, not 0)
conEx.MoveCursor(1, 10)
conEx.SetColor(ConsoleEx.ConsoleColor.Red)
Console.WriteLine("RED")
conEx.SetColor(ConsoleEx.ConsoleColor.Blue)
Console.WriteLine("Type in blue: ")
Console.ReadLine()
' Original color
conEx.SetColor(ConsoleEx.ConsoleColor.White)
conEx.SetMode(ConsoleEx.InputMode.EchoInput)
Console.WriteLine("Press any key to continue...")
Console.Read()
End Sub
End Module
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by wayneh Thanks for the upload, but I can't get any of it to work!
I don't use .NET - I use VB6.
heheh, you cant use it unless someone compiles it in a way to work with vb6, and I don't really know how they do that.... it's quit easy to find something like this written in vb6, I think
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
I'll still hang on to the code and see if I can use it.
hehe you do VB6 and you're trying to use the code, the people on the VB.NET forum do VB.NET and I don't think anyone has tried to use this yet
Good luck... Just in case you don't know, convert the integer datatypes to long if you wanna convert it to vb6
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Originally posted by PT Exorcist then you shouldn't be watching this forum
lol ...
wayneh , In order to run the project , you need the .NET Framework . It would be quite difficult to convert that to VB6 (since this proj is based on the base Console Class of .NET Framework) .
2) I'm pretty sure there's no law against checking out any forum I wish
3) Were you born a jerk - or have you just grown into one?
of course u can watch this forum..but its more than obvious than a vb.net class wouldnt compile in vb6 as it is not totally oop..then asking for a way to use it (in vb.net) wasnt the smartest question to ask
Originally posted by Iamthewalrus15 OMG that is so lame, the IDE wont even let me OPEN your project since im on 02 instead of 03.. rediculus
you dont really need to CONVERT it back... just start a new solution (console class), remove the main module and add the classes from my project
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
uuh I'm just trying to upload some files for this post... you can safely ignore this
Last edited by MrPolite; Jun 5th, 2005 at 04:52 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Last edited by MrPolite; Jun 5th, 2005 at 04:53 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!
Last edited by MrPolite; Jun 5th, 2005 at 04:49 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB ) VB.NET to C# conversion tips!!