473,395 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Console in Windows project

I got a project called "Forms" that hold some forms and stuff in my
solution.

A argument at startup defines wether to use a From or Console.

My plan was to create a myConsole class that would also allow my application
to display a Console, but i don't seem to be allowed to do this.

I don't see any References that i need to add, so how do i do this.
Nov 20 '05 #1
12 3713
In article <68******************************@news.teranews.co m>, Jarod_24 wrote:
I got a project called "Forms" that hold some forms and stuff in my
solution.

A argument at startup defines wether to use a From or Console.

My plan was to create a myConsole class that would also allow my application
to display a Console, but i don't seem to be allowed to do this.

I don't see any References that i need to add, so how do i do this.


You might try creating your application as a regular forms application.
Then if you recieve the command line argument to run in a console, you
can call AllocConsole via p/invoke to allocate a console window. After
that, the System.Console class should work....

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds
Nov 20 '05 #2
"Tom Shelton" <to*@mtogden.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
In article <68******************************@news.teranews.co m>, Jarod_24

wrote:
I got a project called "Forms" that hold some forms and stuff in my
solution.

A argument at startup defines wether to use a From or Console.

My plan was to create a myConsole class that would also allow my application to display a Console, but i don't seem to be allowed to do this.

I don't see any References that i need to add, so how do i do this.


You might try creating your application as a regular forms application.
Then if you recieve the command line argument to run in a console, you
can call AllocConsole via p/invoke to allocate a console window. After
that, the System.Console class should work....

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds

It worked!
I now got a console window in my forms-based project.

I can use the Console.ReadLine to get whatever the user types in the
console, but the Console.WriteLine dosen't work.
So whatever i try to write to the console window, dosen't show up.

Do i have to use the API for reading/writing properly to/from the console

Got any more tricks up your sleeve?
Nov 20 '05 #3
In article <a2******************************@news.teranews.co m>, Jarod_24 wrote:
"Tom Shelton" <to*@mtogden.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
In article <68******************************@news.teranews.co m>, Jarod_24

wrote:
> I got a project called "Forms" that hold some forms and stuff in my
> solution.
>
> A argument at startup defines wether to use a From or Console.
>
> My plan was to create a myConsole class that would also allow my application > to display a Console, but i don't seem to be allowed to do this.
>
> I don't see any References that i need to add, so how do i do this.
>
>


You might try creating your application as a regular forms application.
Then if you recieve the command line argument to run in a console, you
can call AllocConsole via p/invoke to allocate a console window. After
that, the System.Console class should work....

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds

It worked!
I now got a console window in my forms-based project.

I can use the Console.ReadLine to get whatever the user types in the
console, but the Console.WriteLine dosen't work.
So whatever i try to write to the console window, dosen't show up.

Do i have to use the API for reading/writing properly to/from the console

Got any more tricks up your sleeve?


Hmmm, doesn't work... Interesting that readline does and writeline
doesn't. Are you running it with the Debugger attached (F5)? If you are, it
without (Ctrl+F5).

If that doesn't work, let me know and I'll play around with some code :)
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 1 Hours, 38 Minutes, 49 Seconds
Nov 20 '05 #4

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24 wrote:
"Tom Shelton" <to*@mtogden.com> wrote in message
news:eI**************@TK2MSFTNGP12.phx.gbl...
In article <68******************************@news.teranews.co m>,
Jarod_24 wrote:
> I got a project called "Forms" that hold some forms and stuff in my
> solution.
>
> A argument at startup defines wether to use a From or Console.
>
> My plan was to create a myConsole class that would also allow my

application
> to display a Console, but i don't seem to be allowed to do this.
>
> I don't see any References that i need to add, so how do i do this.
>
>

You might try creating your application as a regular forms application.
Then if you recieve the command line argument to run in a console, you
can call AllocConsole via p/invoke to allocate a console window. After
that, the System.Console class should work....

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds

It worked!
I now got a console window in my forms-based project.

I can use the Console.ReadLine to get whatever the user types in the
console, but the Console.WriteLine dosen't work.
So whatever i try to write to the console window, dosen't show up.

Do i have to use the API for reading/writing properly to/from the console
Got any more tricks up your sleeve?


Hmmm, doesn't work... Interesting that readline does and writeline
doesn't. Are you running it with the Debugger attached (F5)? If you are,

it without (Ctrl+F5).

If that doesn't work, let me know and I'll play around with some code :)
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 1 Hours, 38 Minutes, 49 Seconds


Didn't work with F5 or Ctrl+F5

And another thing:
How do you detect key-press'es in the console (special-keys) ?
I'd want to detect when the user presses for example "F3" and then paste the
previous command he typed.
If he press "F6", the previous typed command should be copied to the
clipboard, and "F5" will reload some settings for the app...
Nov 20 '05 #5
In article <ac******************************@news.teranews.co m>, Jarod_24 wrote:

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24 wrote:
> "Tom Shelton" <to*@mtogden.com> wrote in message
> news:eI**************@TK2MSFTNGP12.phx.gbl...
>> In article <68******************************@news.teranews.co m>, Jarod_24 > wrote:
>> > I got a project called "Forms" that hold some forms and stuff in my
>> > solution.
>> >
>> > A argument at startup defines wether to use a From or Console.
>> >
>> > My plan was to create a myConsole class that would also allow my
> application
>> > to display a Console, but i don't seem to be allowed to do this.
>> >
>> > I don't see any References that i need to add, so how do i do this.
>> >
>> >


<snip>
Didn't work with F5 or Ctrl+F5
Very strange... Well, you might have to use WriteConsole...
And another thing:
How do you detect key-press'es in the console (special-keys) ?
I'd want to detect when the user presses for example "F3" and then paste the
previous command he typed.
If he press "F6", the previous typed command should be copied to the
clipboard, and "F5" will reload some settings for the app...


Hey, now your definately getting into the relm of the API... I'll try
to put together a little something tonight. But, you'll probably want
to be looking into the ReadConsoleInput function to get that kind of
information.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 3 Hours, 8 Minutes, 47 Seconds
Nov 20 '05 #6

"Tom Shelton" <to*@mtogden.com> wrote in message
news:eS*************@TK2MSFTNGP12.phx.gbl...
In article <ac******************************@news.teranews.co m>, Jarod_24

wrote:

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24
wrote:
> "Tom Shelton" <to*@mtogden.com> wrote in message
> news:eI**************@TK2MSFTNGP12.phx.gbl...
>> In article <68******************************@news.teranews.co m>,

Jarod_24
> wrote:
>> > I got a project called "Forms" that hold some forms and stuff in
my >> > solution.
>> >
>> > A argument at startup defines wether to use a From or Console.
>> >
>> > My plan was to create a myConsole class that would also allow my
> application
>> > to display a Console, but i don't seem to be allowed to do this.
>> >
>> > I don't see any References that i need to add, so how do i do this. >> >
>> >


<snip>
Didn't work with F5 or Ctrl+F5


Very strange... Well, you might have to use WriteConsole...
And another thing:
How do you detect key-press'es in the console (special-keys) ?
I'd want to detect when the user presses for example "F3" and then paste

the previous command he typed.
If he press "F6", the previous typed command should be copied to the
clipboard, and "F5" will reload some settings for the app...


Hey, now your definately getting into the relm of the API... I'll try
to put together a little something tonight. But, you'll probably want
to be looking into the ReadConsoleInput function to get that kind of
information.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 3 Hours, 8 Minutes, 47 Seconds


I think i can use Console.Read() to get the integer value of the key
pressed. This can be compared with Keys.F1 for example.
Hmmm.
What data types do i use for the argument to WriteConsole?
BOOL WriteConsole(HANDLE hConsoleOutput, const VOID* lpBuffer, DWORD
nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved);

hConsoleOutput is a IntPtr in VB (i got the handle using GetStdHandle)
lpBuffer is what?
nNumberOfCharsToWrite is a Int32 in VB
lpNumberOfCharsWritten is a adress to an Int32 variable that is getting
written to by the API?
lpReserved is supposed to be NULL, would "Nothing" work with this?

ref:
http://msdn.microsoft.com/library/de...iteconsole.asp
Nov 20 '05 #7
"Tom Shelton" <to*@mtogden.com> wrote in message
news:eS*************@TK2MSFTNGP12.phx.gbl...
In article <ac******************************@news.teranews.co m>, Jarod_24

wrote:

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24
wrote:
> "Tom Shelton" <to*@mtogden.com> wrote in message
> news:eI**************@TK2MSFTNGP12.phx.gbl...
>> In article <68******************************@news.teranews.co m>,

Jarod_24
> wrote:
>> > I got a project called "Forms" that hold some forms and stuff in
my >> > solution.
>> >
>> > A argument at startup defines wether to use a From or Console.
>> >
>> > My plan was to create a myConsole class that would also allow my
> application
>> > to display a Console, but i don't seem to be allowed to do this.
>> >
>> > I don't see any References that i need to add, so how do i do this. >> >
>> >


<snip>
Didn't work with F5 or Ctrl+F5


Very strange... Well, you might have to use WriteConsole...
And another thing:
How do you detect key-press'es in the console (special-keys) ?
I'd want to detect when the user presses for example "F3" and then paste

the previous command he typed.
If he press "F6", the previous typed command should be copied to the
clipboard, and "F5" will reload some settings for the app...


Hey, now your definately getting into the relm of the API... I'll try
to put together a little something tonight. But, you'll probably want
to be looking into the ReadConsoleInput function to get that kind of
information.

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 3 Hours, 8 Minutes, 47 Seconds


I think i can use Console.Read() to get the integer value of the key
pressed. This can be compared with Keys.F1 for example.
Hmmm.
What data types do i use for the argument to WriteConsole?
BOOL WriteConsole(HANDLE hConsoleOutput, const VOID* lpBuffer, DWORD
nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved);

hConsoleOutput is a IntPtr in VB (i got the handle using GetStdHandle)
lpBuffer is what?
nNumberOfCharsToWrite is a Int32 in VB
lpNumberOfCharsWritten is a adress to an Int32 variable that is getting
written to by the API?
lpReserved is supposed to be NULL, would "Nothing" work with this?

ref:
http://msdn.microsoft.com/library/de...iteconsole.asp

Nov 20 '05 #8


"Jarod_24" <ja******@hotmail.com> wrote in message
news:ac******************************@news.teranew s.com...

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24 wrote:
> "Tom Shelton" <to*@mtogden.com> wrote in message
> news:eI**************@TK2MSFTNGP12.phx.gbl...
>> In article <68******************************@news.teranews.co m>, Jarod_24 > wrote:
>> > I got a project called "Forms" that hold some forms and stuff in my
>> > solution.
>> >
>> > A argument at startup defines wether to use a From or Console.
>> >
>> > My plan was to create a myConsole class that would also allow my
> application
>> > to display a Console, but i don't seem to be allowed to do this.
>> >
>> > I don't see any References that i need to add, so how do i do this.
>> >
>> >
>>
>> You might try creating your application as a regular forms
>> application.
>> Then if you recieve the command line argument to run in a console, you
>> can call AllocConsole via p/invoke to allocate a console window.
>> After
>> that, the System.Console class should work....
>>
>> --
>> Tom Shelton [MVP]
>> OS Name: Microsoft Windows XP Professional
>> OS Version: 5.1.2600 Service Pack 1 Build 2600
>> System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds
>
>
> It worked!
> I now got a console window in my forms-based project.
>
> I can use the Console.ReadLine to get whatever the user types in the
> console, but the Console.WriteLine dosen't work.
> So whatever i try to write to the console window, dosen't show up.
>
> Do i have to use the API for reading/writing properly to/from the console >
> Got any more tricks up your sleeve?
>
>


Hmmm, doesn't work... Interesting that readline does and writeline
doesn't. Are you running it with the Debugger attached (F5)? If you
are,

it
without (Ctrl+F5).

If that doesn't work, let me know and I'll play around with some code :)
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 1 Hours, 38 Minutes, 49 Seconds


Didn't work with F5 or Ctrl+F5

This is very strange.. And another thing:
How do you detect key-press'es in the console (special-keys) ?
I'd want to detect when the user presses for example "F3" and then paste
the
previous command he typed.
If he press "F6", the previous typed command should be copied to the
clipboard, and "F5" will reload some settings for the app...

--
Tom Shelton [MVP]
Nov 20 '05 #9


"Jarod_24" <ja******@hotmail.com> wrote in message
news:ac******************************@news.teranew s.com...

"Tom Shelton" <to*@mtogden.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
In article <a2******************************@news.teranews.co m>, Jarod_24

wrote:
> "Tom Shelton" <to*@mtogden.com> wrote in message
> news:eI**************@TK2MSFTNGP12.phx.gbl...
>> In article <68******************************@news.teranews.co m>, Jarod_24 > wrote:
>> > I got a project called "Forms" that hold some forms and stuff in my
>> > solution.
>> >
>> > A argument at startup defines wether to use a From or Console.
>> >
>> > My plan was to create a myConsole class that would also allow my
> application
>> > to display a Console, but i don't seem to be allowed to do this.
>> >
>> > I don't see any References that i need to add, so how do i do this.
>> >
>> >
>>
>> You might try creating your application as a regular forms
>> application.
>> Then if you recieve the command line argument to run in a console, you
>> can call AllocConsole via p/invoke to allocate a console window.
>> After
>> that, the System.Console class should work....
>>
>> --
>> Tom Shelton [MVP]
>> OS Name: Microsoft Windows XP Professional
>> OS Version: 5.1.2600 Service Pack 1 Build 2600
>> System Up Time: 9 Days, 0 Hours, 52 Minutes, 41 Seconds
>
>
> It worked!
> I now got a console window in my forms-based project.
>
> I can use the Console.ReadLine to get whatever the user types in the
> console, but the Console.WriteLine dosen't work.
> So whatever i try to write to the console window, dosen't show up.
>
> Do i have to use the API for reading/writing properly to/from the console >
> Got any more tricks up your sleeve?
>
>


Hmmm, doesn't work... Interesting that readline does and writeline
doesn't. Are you running it with the Debugger attached (F5)? If you
are,

it
without (Ctrl+F5).

If that doesn't work, let me know and I'll play around with some code :)
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 0 Days, 1 Hours, 38 Minutes, 49 Seconds


Didn't work with F5 or Ctrl+F5


That is very strange... The following code works just fine in a winforms
app - as long as I use Ctrl+F5 (VS.NET 2003 Framework 1.1)

Option Strict On
Option Explicit On

Imports System.Runtime.InteropServices

Namespace FireAnt.Demo

Module Main

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

Public Sub Main()
AllocConsole()
Console.WriteLine("Hello, World")
Console.ReadLine()
FreeConsole()
End Sub
End Module

End Namespace
--
Tom Shelton [MVP]
Nov 20 '05 #10

"Jarod_24" <ja******@hotmail.com> wrote in message
news:4f******************************@news.teranew s.com...

<snip>

I think i can use Console.Read() to get the integer value of the key
pressed. This can be compared with Keys.F1 for example.

Maybe... But the problem I see is that Console.Read and Console.ReadLine
both wait for the user to hit the enter key before they return. You will
have to call SetConsoleMode to disable line input (ENABLE_LINE_INPUT) and
echo input (ENABLE_ECHO_INPUT).


Hmmm.
What data types do i use for the argument to WriteConsole?
BOOL WriteConsole(HANDLE hConsoleOutput, const VOID* lpBuffer, DWORD
nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved);

hConsoleOutput is a IntPtr in VB (i got the handle using GetStdHandle)
lpBuffer is what?
nNumberOfCharsToWrite is a Int32 in VB
lpNumberOfCharsWritten is a adress to an Int32 variable that is getting
written to by the API?
lpReserved is supposed to be NULL, would "Nothing" work with this?

ref:
http://msdn.microsoft.com/library/de...iteconsole.asp

Here are my interop definitions... The are in C#, but should be fairly easy
to translate to VB.NET:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace FireAnt.ConsoleLib
{
#region "Enumerations
[Flags()]
public enum ControlKeyState
{
RightAltPressed = 0x0001,
LeftAltPressed = 0x0002,
RightCtrlPressed = 0x0004,
LeftCtrlPressed = 0x0008,
ShiftPressed = 0x0010,
NumLockOn = 0x0020,
ScrollLockOn = 0x0040,
CapsLockOn = 0x0080,
EnhancedKey = 0x0100,
}

[Flags()]
public enum MouseButtonState
{
FromLeft1stButtonPressed = 0x0001,
RightMostButtonPressed = 0x0002,
FromLeft2ndButtonPressed = 0x0004,
FromLeft3rdButtonPressed = 0x0008,
FromLeft4thButtonPressed = 0x0010,
}

[Flags()]
public enum MouseEventFlags
{
MouseMoved = 0x0001,
DoubleClick = 0x0002,
MouseWheeled = 0x0004,
}

public enum InputEventType : short
{
KeyEvent = 0x0001,
MouseEvent = 0x0002,
WindowBufferSizeEvent = 0x004,
MenuEvent = 0x0008,
FocusEvent = 0x0010,
}

[Flags()]
public enum CharAttributes : short
{
ForegroundBlue = 0x0001,
ForegroundGreen = 0x0002,
ForegroundRed = 0x0004,
ForegroundIntensity = 0x0008,
BackgroundBlue = 0x0010,
BackgroundGreen = 0x0020,
BackgroundRed = 0x0040,
BackgroundIntensity = 0x0080,
}

[Flags()]
public enum SelectionFlags
{
NoSelection = 0x0000,
SelectionInProgress = 0x0001,
SelectionNotEmpty = 0x0002,
MouseSelection = 0x0004,
MouseDown = 0x0008,
}

public enum ControlEvents
{
CtrlC = 0,
CtrlBreak = 1,
Close = 2,
LogOff = 5,
Shutdown = 6,
}

[Flags()]
public enum InputModeFlags
{
EnableProcessedInput = 0x0001,
EnableLineInput = 0x0002,
EnableEchoInput = 0x0004,
EnableWindowInput = 0x0008,
EnableMouseInput = 0x0010,
}

[Flags()]
public enum OutputModeFlags
{
EnableProcessedOutput = 0x0001,
EnableWrapAtEolOutput = 0x0002,
}

public enum StandardHandle
{
Input = -10,
Output = -11,
Error = -12,
}

#endregion

#region "Structures"
[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
public short X;
public short Y;
}

[StructLayout(LayoutKind.Sequential)]
public struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}

[StructLayout(LayoutKind.Explicit)]
public struct CHAR
{
[FieldOffset(0)] public byte AsciiChar;
[FieldOffset(0)] public short UnicodeChar;
}

[StructLayout(LayoutKind.Sequential)]
public struct KEY_EVENT_RECORD
{
public bool bKeyDown;
public short wRepeatCount;
public short wVirtualKeyCode;
public short wVirtualScanCode;
public CHAR uChar;
public ControlKeyState dwControlKeyState;
}

[StructLayout(LayoutKind.Sequential)]
public struct MOUSE_EVENT_RECORD
{
public COORD dwMousePosition;
public MouseButtonState dwButtonState;
public ControlKeyState dwControlKeyState;
public MouseEventFlags dwEventFlags;
}

[StructLayout(LayoutKind.Sequential)]
public struct WINDOW_BUFFER_SIZE_RECORD
{
public COORD dwSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct MENU_EVENT_RECORD
{
public uint dwCommandId;
}

[StructLayout(LayoutKind.Sequential)]
public struct FOCUS_EVENT_RECORD
{
public bool bSetFocus;
}

[StructLayout(LayoutKind.Explicit)]
public struct EVENT_UNION
{
[FieldOffset(0)] public KEY_EVENT_RECORD KeyEvent;
[FieldOffset(0)] public MOUSE_EVENT_RECORD MouseEvent;
[FieldOffset(0)] public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
[FieldOffset(0)] public MENU_EVENT_RECORD MenuEvent;
[FieldOffset(0)] public FOCUS_EVENT_RECORD FocusEvent;
}

[StructLayout(LayoutKind.Sequential)]
public struct INPUT_RECORD
{
public InputEventType EventType;
public EVENT_UNION Event;
}

[StructLayout(LayoutKind.Sequential)]
public struct CHAR_INFO
{
public CHAR Char;
public CharAttributes Attributes;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public CharAttributes wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_CURSOR_INFO
{
int dwSize;
bool bVisible;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_FONT_INFO
{
int nFont;
COORD dwFontSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SELECTION_INFO
{
public SelectionFlags dwFlags;
public COORD dwSelectionAnchor;
public SMALL_RECT srSelection;
}
#endregion

#region "Delegates"
public delegate bool HandlerRoutineDelegate (ControlEvents dwCtrlType);
#endregion

/// <summary>
/// Summary description for ConsoleAPI.
/// </summary>
public class ConsoleApi
{
[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PeekConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutput (
IntPtr hConsoleOutput,
out CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCord,
ref SMALL_RECT lpReadRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutput (
IntPtr hConsoleOutput,
CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCoord,
ref SMALL_RECT lpWriteRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputCharacter (
IntPtr hConsoleOutput,
StringBuilder lpCharacter,
int nLength,
COORD dwReadCoord,
out int lpNumberOfCharsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwReadCoord,
out int lpNumberOfAttrsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputCharacter (
IntPtr hConsoleOutput,
string lpCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool FillConsoleOutputCharacter (
IntPtr hConsoleOupt,
CHAR cCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FillConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleInput,
out InputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleOutput,
out OutputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleInputEvents (
IntPtr hConsoleInput,
out int lpNumberOfEvents);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleScreenBufferInfo (
IntPtr hConsoleInput,
out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetLargestConsoleWindowSize (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleCursorInfo (
IntPtr hConsoleOutput,
out CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetCurrentConsoleFont (
IntPtr hConsoleOutput,
bool bMaximumWindow,
out CONSOLE_FONT_INFO lpConsoleCurrentFont);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetConsoleFontSize (
IntPtr hConsoleOutput,
int nFont);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleSelectionInfo (out
CONSOLE_SELECTION_INFO lpConsoleSelectionInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleMouseButtons (out int
lpNumberOfMouseButtons);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleInput,
InputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleOutput,
OutputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleActiveScreenBuffer (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FlushConsoleInputBuffer (IntPtr hConsoleInput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleScreenBufferSize (
IntPtr hConsoleOutput,
COORD dwSize);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorPosition (
IntPtr hConsoleOutput,
COORD dwCursorPostion);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorInfo (
IntPtr hConsoleOutput,
ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ScrollConsoleScreenBuffer (
IntPtr hConsoleOutput,
ref SMALL_RECT lpScrollRectangle,
ref SMALL_RECT lpClipRectangle,
COORD dwDestinationOrigin,
ref CHAR_INFO lpFill);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleWindowInfo (
IntPtr hConsoleOutput,
bool bAbsolute,
ref SMALL_RECT lpConsoleWindow);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleTextAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttributes);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCtrlHandler (
HandlerRoutineDelegate HandlerRoutine,
bool Add);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GenerateConsoleCtrlEvent (
ControlEvents dwCtrlEvent,
int dwProcessGroupId);

[DllImport("kernel32", SetLastError=true)]
public static extern bool AllocConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool FreeConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool AttachConsole (int dwProcessId);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetConsoleTitle (
StringBuilder lpConsoleTitle,
int nSize);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool SetConsoleTitle (
string lpConsoleTitle);

[DllImport("kernel32", SetLastError=true)]
public static extern IntPtr GetStdHandle (StandardHandle nStdHandle);

private ConsoleApi() {}
}
}
and here is a little class that uses some of them (it is a converted and
modified MSDN sample)...

using System;
using System.Threading;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

using FireAnt.ConsoleLib;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
private static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
//Console.WriteLine(Marshal.SizeOf(typeof(INPUT_RECO RD)));
IntPtr hStdin;
int cNumRead, i;
InputModeFlags fdwMode, fdwSaveOldMode;
INPUT_RECORD[] irInBuf = new INPUT_RECORD[128];

// Get the standard input handle.

hStdin = ConsoleApi.GetStdHandle(StandardHandle.Input);
if (hStdin == INVALID_HANDLE_VALUE)
MyErrorExit("GetStdHandle");

// Save the current input mode, to be restored on exit.
if (! ConsoleApi.GetConsoleMode(hStdin, out fdwSaveOldMode) )
MyErrorExit("GetConsoleMode");

// Enable the window and mouse input events.
fdwMode = InputModeFlags.EnableWindowInput |
InputModeFlags.EnableMouseInput;
if (! ConsoleApi.SetConsoleMode(hStdin, fdwMode) )
MyErrorExit("SetConsoleMode");

IntPtr hStdout = ConsoleApi.GetStdHandle(StandardHandle.Output);
COORD size = ConsoleApi.GetLargestConsoleWindowSize(hStdout);
ConsoleApi.SetConsoleScreenBufferSize(hStdout, size);
Console.WriteLine("size.X = {0}, size.Y = {1}", size.X, size.Y);

// Loop to read and handle the input events.
while (true)
{

// Wait for the events.
if (! ConsoleApi.ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
out cNumRead) ) // number of records read
MyErrorExit("ReadConsoleInput");

// Dispatch the events to the appropriate handler.

for (i = 0; i < cNumRead; i++)
{
switch(irInBuf[i].EventType)
{
case InputEventType.KeyEvent: // keyboard input
KeyEventProc(ref irInBuf[i].Event.KeyEvent);
break;

case InputEventType.MouseEvent: // mouse input
MouseEventProc(ref irInBuf[i].Event.MouseEvent);
break;

case InputEventType.WindowBufferSizeEvent: // scrn buf. resizing
ResizeEventProc(ref irInBuf[i].Event.WindowBufferSizeEvent);
break;

case InputEventType.FocusEvent: // disregard focus events

case InputEventType.MenuEvent: // disregard menu events
break;

default:
MyErrorExit("unknown event type");
break;
}
}
}
}

private static void MouseEventProc(ref MOUSE_EVENT_RECORD MouseEvent)
{
Console.WriteLine("Button State = {0}", MouseEvent.dwButtonState);
}

private static void ResizeEventProc(ref WINDOW_BUFFER_SIZE_RECORD
WindowEvent)
{
Console.WriteLine("Resize");
}

private static void KeyEventProc(ref KEY_EVENT_RECORD KeyEvent)
{
Console.WriteLine(KeyEvent.wVirtualKeyCode);
}

private static void MyErrorExit(string msg)
{
Console.WriteLine(msg);
System.Environment.Exit(1);
}
}
}
This doesn't test all of them, and I haven't tested all of them yet - but
your welcome to 'em...

HTH

Tom Shelton [MVP]

PS: Man OE sucks... Now I realize why I started using slrn...
Nov 20 '05 #11

"Tom Shelton" <to*@mtogden.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...

"Jarod_24" <ja******@hotmail.com> wrote in message
news:4f******************************@news.teranew s.com...

<snip>

I think i can use Console.Read() to get the integer value of the key
pressed. This can be compared with Keys.F1 for example.

Maybe... But the problem I see is that Console.Read and Console.ReadLine
both wait for the user to hit the enter key before they return. You will
have to call SetConsoleMode to disable line input (ENABLE_LINE_INPUT) and
echo input (ENABLE_ECHO_INPUT).

Here's the code i used. Havent's exaclty tested it though...

Dim intIn As Integer, bChar As Boolean = False

Do 'loop until we got a key
intIn = Console.In.Peek()
If (intIn <> -1) Then bChar = True
Loop Until bChar

Select Case intIn
Case Keys.F1
Call about()
End Select

Hmmm.
What data types do i use for the argument to WriteConsole?
BOOL WriteConsole(HANDLE hConsoleOutput, const VOID* lpBuffer, DWORD
nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved);
hConsoleOutput is a IntPtr in VB (i got the handle using GetStdHandle)
lpBuffer is what?
nNumberOfCharsToWrite is a Int32 in VB
lpNumberOfCharsWritten is a adress to an Int32 variable that is getting
written to by the API?
lpReserved is supposed to be NULL, would "Nothing" work with this?

ref:
http://msdn.microsoft.com/library/de...iteconsole.asp

Here are my interop definitions... The are in C#, but should be fairly easy to translate to VB.NET:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace FireAnt.ConsoleLib
{
#region "Enumerations
[Flags()]
public enum ControlKeyState
{
RightAltPressed = 0x0001,
LeftAltPressed = 0x0002,
RightCtrlPressed = 0x0004,
LeftCtrlPressed = 0x0008,
ShiftPressed = 0x0010,
NumLockOn = 0x0020,
ScrollLockOn = 0x0040,
CapsLockOn = 0x0080,
EnhancedKey = 0x0100,
}

[Flags()]
public enum MouseButtonState
{
FromLeft1stButtonPressed = 0x0001,
RightMostButtonPressed = 0x0002,
FromLeft2ndButtonPressed = 0x0004,
FromLeft3rdButtonPressed = 0x0008,
FromLeft4thButtonPressed = 0x0010,
}

[Flags()]
public enum MouseEventFlags
{
MouseMoved = 0x0001,
DoubleClick = 0x0002,
MouseWheeled = 0x0004,
}

public enum InputEventType : short
{
KeyEvent = 0x0001,
MouseEvent = 0x0002,
WindowBufferSizeEvent = 0x004,
MenuEvent = 0x0008,
FocusEvent = 0x0010,
}

[Flags()]
public enum CharAttributes : short
{
ForegroundBlue = 0x0001,
ForegroundGreen = 0x0002,
ForegroundRed = 0x0004,
ForegroundIntensity = 0x0008,
BackgroundBlue = 0x0010,
BackgroundGreen = 0x0020,
BackgroundRed = 0x0040,
BackgroundIntensity = 0x0080,
}

[Flags()]
public enum SelectionFlags
{
NoSelection = 0x0000,
SelectionInProgress = 0x0001,
SelectionNotEmpty = 0x0002,
MouseSelection = 0x0004,
MouseDown = 0x0008,
}

public enum ControlEvents
{
CtrlC = 0,
CtrlBreak = 1,
Close = 2,
LogOff = 5,
Shutdown = 6,
}

[Flags()]
public enum InputModeFlags
{
EnableProcessedInput = 0x0001,
EnableLineInput = 0x0002,
EnableEchoInput = 0x0004,
EnableWindowInput = 0x0008,
EnableMouseInput = 0x0010,
}

[Flags()]
public enum OutputModeFlags
{
EnableProcessedOutput = 0x0001,
EnableWrapAtEolOutput = 0x0002,
}

public enum StandardHandle
{
Input = -10,
Output = -11,
Error = -12,
}

#endregion

#region "Structures"
[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
public short X;
public short Y;
}

[StructLayout(LayoutKind.Sequential)]
public struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}

[StructLayout(LayoutKind.Explicit)]
public struct CHAR
{
[FieldOffset(0)] public byte AsciiChar;
[FieldOffset(0)] public short UnicodeChar;
}

[StructLayout(LayoutKind.Sequential)]
public struct KEY_EVENT_RECORD
{
public bool bKeyDown;
public short wRepeatCount;
public short wVirtualKeyCode;
public short wVirtualScanCode;
public CHAR uChar;
public ControlKeyState dwControlKeyState;
}

[StructLayout(LayoutKind.Sequential)]
public struct MOUSE_EVENT_RECORD
{
public COORD dwMousePosition;
public MouseButtonState dwButtonState;
public ControlKeyState dwControlKeyState;
public MouseEventFlags dwEventFlags;
}

[StructLayout(LayoutKind.Sequential)]
public struct WINDOW_BUFFER_SIZE_RECORD
{
public COORD dwSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct MENU_EVENT_RECORD
{
public uint dwCommandId;
}

[StructLayout(LayoutKind.Sequential)]
public struct FOCUS_EVENT_RECORD
{
public bool bSetFocus;
}

[StructLayout(LayoutKind.Explicit)]
public struct EVENT_UNION
{
[FieldOffset(0)] public KEY_EVENT_RECORD KeyEvent;
[FieldOffset(0)] public MOUSE_EVENT_RECORD MouseEvent;
[FieldOffset(0)] public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
[FieldOffset(0)] public MENU_EVENT_RECORD MenuEvent;
[FieldOffset(0)] public FOCUS_EVENT_RECORD FocusEvent;
}

[StructLayout(LayoutKind.Sequential)]
public struct INPUT_RECORD
{
public InputEventType EventType;
public EVENT_UNION Event;
}

[StructLayout(LayoutKind.Sequential)]
public struct CHAR_INFO
{
public CHAR Char;
public CharAttributes Attributes;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public CharAttributes wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_CURSOR_INFO
{
int dwSize;
bool bVisible;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_FONT_INFO
{
int nFont;
COORD dwFontSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SELECTION_INFO
{
public SelectionFlags dwFlags;
public COORD dwSelectionAnchor;
public SMALL_RECT srSelection;
}
#endregion

#region "Delegates"
public delegate bool HandlerRoutineDelegate (ControlEvents dwCtrlType);
#endregion

/// <summary>
/// Summary description for ConsoleAPI.
/// </summary>
public class ConsoleApi
{
[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PeekConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutput (
IntPtr hConsoleOutput,
out CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCord,
ref SMALL_RECT lpReadRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutput (
IntPtr hConsoleOutput,
CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCoord,
ref SMALL_RECT lpWriteRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputCharacter (
IntPtr hConsoleOutput,
StringBuilder lpCharacter,
int nLength,
COORD dwReadCoord,
out int lpNumberOfCharsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwReadCoord,
out int lpNumberOfAttrsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputCharacter (
IntPtr hConsoleOutput,
string lpCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool FillConsoleOutputCharacter (
IntPtr hConsoleOupt,
CHAR cCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FillConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleInput,
out InputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleOutput,
out OutputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleInputEvents (
IntPtr hConsoleInput,
out int lpNumberOfEvents);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleScreenBufferInfo (
IntPtr hConsoleInput,
out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetLargestConsoleWindowSize (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleCursorInfo (
IntPtr hConsoleOutput,
out CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetCurrentConsoleFont (
IntPtr hConsoleOutput,
bool bMaximumWindow,
out CONSOLE_FONT_INFO lpConsoleCurrentFont);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetConsoleFontSize (
IntPtr hConsoleOutput,
int nFont);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleSelectionInfo (out
CONSOLE_SELECTION_INFO lpConsoleSelectionInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleMouseButtons (out int
lpNumberOfMouseButtons);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleInput,
InputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleOutput,
OutputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleActiveScreenBuffer (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FlushConsoleInputBuffer (IntPtr hConsoleInput);
[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleScreenBufferSize (
IntPtr hConsoleOutput,
COORD dwSize);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorPosition (
IntPtr hConsoleOutput,
COORD dwCursorPostion);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorInfo (
IntPtr hConsoleOutput,
ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ScrollConsoleScreenBuffer (
IntPtr hConsoleOutput,
ref SMALL_RECT lpScrollRectangle,
ref SMALL_RECT lpClipRectangle,
COORD dwDestinationOrigin,
ref CHAR_INFO lpFill);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleWindowInfo (
IntPtr hConsoleOutput,
bool bAbsolute,
ref SMALL_RECT lpConsoleWindow);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleTextAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttributes);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCtrlHandler (
HandlerRoutineDelegate HandlerRoutine,
bool Add);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GenerateConsoleCtrlEvent (
ControlEvents dwCtrlEvent,
int dwProcessGroupId);

[DllImport("kernel32", SetLastError=true)]
public static extern bool AllocConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool FreeConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool AttachConsole (int dwProcessId);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetConsoleTitle (
StringBuilder lpConsoleTitle,
int nSize);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool SetConsoleTitle (
string lpConsoleTitle);

[DllImport("kernel32", SetLastError=true)]
public static extern IntPtr GetStdHandle (StandardHandle nStdHandle);

private ConsoleApi() {}
}
}
and here is a little class that uses some of them (it is a converted and
modified MSDN sample)...

using System;
using System.Threading;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

using FireAnt.ConsoleLib;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
private static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
//Console.WriteLine(Marshal.SizeOf(typeof(INPUT_RECO RD)));
IntPtr hStdin;
int cNumRead, i;
InputModeFlags fdwMode, fdwSaveOldMode;
INPUT_RECORD[] irInBuf = new INPUT_RECORD[128];

// Get the standard input handle.

hStdin = ConsoleApi.GetStdHandle(StandardHandle.Input);
if (hStdin == INVALID_HANDLE_VALUE)
MyErrorExit("GetStdHandle");

// Save the current input mode, to be restored on exit.
if (! ConsoleApi.GetConsoleMode(hStdin, out fdwSaveOldMode) )
MyErrorExit("GetConsoleMode");

// Enable the window and mouse input events.
fdwMode = InputModeFlags.EnableWindowInput |
InputModeFlags.EnableMouseInput;
if (! ConsoleApi.SetConsoleMode(hStdin, fdwMode) )
MyErrorExit("SetConsoleMode");

IntPtr hStdout = ConsoleApi.GetStdHandle(StandardHandle.Output);
COORD size = ConsoleApi.GetLargestConsoleWindowSize(hStdout);
ConsoleApi.SetConsoleScreenBufferSize(hStdout, size);
Console.WriteLine("size.X = {0}, size.Y = {1}", size.X, size.Y);

// Loop to read and handle the input events.
while (true)
{

// Wait for the events.
if (! ConsoleApi.ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
out cNumRead) ) // number of records read
MyErrorExit("ReadConsoleInput");

// Dispatch the events to the appropriate handler.

for (i = 0; i < cNumRead; i++)
{
switch(irInBuf[i].EventType)
{
case InputEventType.KeyEvent: // keyboard input
KeyEventProc(ref irInBuf[i].Event.KeyEvent);
break;

case InputEventType.MouseEvent: // mouse input
MouseEventProc(ref irInBuf[i].Event.MouseEvent);
break;

case InputEventType.WindowBufferSizeEvent: // scrn buf. resizing
ResizeEventProc(ref irInBuf[i].Event.WindowBufferSizeEvent);
break;

case InputEventType.FocusEvent: // disregard focus events

case InputEventType.MenuEvent: // disregard menu events
break;

default:
MyErrorExit("unknown event type");
break;
}
}
}
}

private static void MouseEventProc(ref MOUSE_EVENT_RECORD MouseEvent)
{
Console.WriteLine("Button State = {0}", MouseEvent.dwButtonState);
}

private static void ResizeEventProc(ref WINDOW_BUFFER_SIZE_RECORD
WindowEvent)
{
Console.WriteLine("Resize");
}

private static void KeyEventProc(ref KEY_EVENT_RECORD KeyEvent)
{
Console.WriteLine(KeyEvent.wVirtualKeyCode);
}

private static void MyErrorExit(string msg)
{
Console.WriteLine(msg);
System.Environment.Exit(1);
}
}
}
This doesn't test all of them, and I haven't tested all of them yet - but
your welcome to 'em...

HTH

Tom Shelton [MVP]

PS: Man OE sucks... Now I realize why I started using slrn...

Nov 20 '05 #12
I tried for a long time with the enums and struct's that you posted.

Then when i called the method with a regular String variable and Int32's it
worked!!!!
I need to press Ctrl+F5 to get the text in the console to be displayed, but
other than that everything works perfect.

<DllImport("Kernel32")> _
Public Shared Function WriteConsole(ByVal hConsoleOutput As IntPtr, ByVal
lpBuffer As String, ByVal nNumberOfCharsToWrite As Int32, ByRef
lpNumberOfCharsWritten As Int32, ByRef lpReserved As Int32) As Boolean
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/ba
se/writeconsole.asp
End Function
"Tom Shelton" <to*@mtogden.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...

"Jarod_24" <ja******@hotmail.com> wrote in message
news:4f******************************@news.teranew s.com...

<snip>

I think i can use Console.Read() to get the integer value of the key
pressed. This can be compared with Keys.F1 for example.

Maybe... But the problem I see is that Console.Read and Console.ReadLine
both wait for the user to hit the enter key before they return. You will
have to call SetConsoleMode to disable line input (ENABLE_LINE_INPUT) and
echo input (ENABLE_ECHO_INPUT).


Hmmm.
What data types do i use for the argument to WriteConsole?
BOOL WriteConsole(HANDLE hConsoleOutput, const VOID* lpBuffer, DWORD
nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved);
hConsoleOutput is a IntPtr in VB (i got the handle using GetStdHandle)
lpBuffer is what?
nNumberOfCharsToWrite is a Int32 in VB
lpNumberOfCharsWritten is a adress to an Int32 variable that is getting
written to by the API?
lpReserved is supposed to be NULL, would "Nothing" work with this?

ref:

http://msdn.microsoft.com/library/de...iteconsole.asp

Here are my interop definitions... The are in C#, but should be fairly easy to translate to VB.NET:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace FireAnt.ConsoleLib
{
#region "Enumerations
[Flags()]
public enum ControlKeyState
{
RightAltPressed = 0x0001,
LeftAltPressed = 0x0002,
RightCtrlPressed = 0x0004,
LeftCtrlPressed = 0x0008,
ShiftPressed = 0x0010,
NumLockOn = 0x0020,
ScrollLockOn = 0x0040,
CapsLockOn = 0x0080,
EnhancedKey = 0x0100,
}

[Flags()]
public enum MouseButtonState
{
FromLeft1stButtonPressed = 0x0001,
RightMostButtonPressed = 0x0002,
FromLeft2ndButtonPressed = 0x0004,
FromLeft3rdButtonPressed = 0x0008,
FromLeft4thButtonPressed = 0x0010,
}

[Flags()]
public enum MouseEventFlags
{
MouseMoved = 0x0001,
DoubleClick = 0x0002,
MouseWheeled = 0x0004,
}

public enum InputEventType : short
{
KeyEvent = 0x0001,
MouseEvent = 0x0002,
WindowBufferSizeEvent = 0x004,
MenuEvent = 0x0008,
FocusEvent = 0x0010,
}

[Flags()]
public enum CharAttributes : short
{
ForegroundBlue = 0x0001,
ForegroundGreen = 0x0002,
ForegroundRed = 0x0004,
ForegroundIntensity = 0x0008,
BackgroundBlue = 0x0010,
BackgroundGreen = 0x0020,
BackgroundRed = 0x0040,
BackgroundIntensity = 0x0080,
}

[Flags()]
public enum SelectionFlags
{
NoSelection = 0x0000,
SelectionInProgress = 0x0001,
SelectionNotEmpty = 0x0002,
MouseSelection = 0x0004,
MouseDown = 0x0008,
}

public enum ControlEvents
{
CtrlC = 0,
CtrlBreak = 1,
Close = 2,
LogOff = 5,
Shutdown = 6,
}

[Flags()]
public enum InputModeFlags
{
EnableProcessedInput = 0x0001,
EnableLineInput = 0x0002,
EnableEchoInput = 0x0004,
EnableWindowInput = 0x0008,
EnableMouseInput = 0x0010,
}

[Flags()]
public enum OutputModeFlags
{
EnableProcessedOutput = 0x0001,
EnableWrapAtEolOutput = 0x0002,
}

public enum StandardHandle
{
Input = -10,
Output = -11,
Error = -12,
}

#endregion

#region "Structures"
[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
public short X;
public short Y;
}

[StructLayout(LayoutKind.Sequential)]
public struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}

[StructLayout(LayoutKind.Explicit)]
public struct CHAR
{
[FieldOffset(0)] public byte AsciiChar;
[FieldOffset(0)] public short UnicodeChar;
}

[StructLayout(LayoutKind.Sequential)]
public struct KEY_EVENT_RECORD
{
public bool bKeyDown;
public short wRepeatCount;
public short wVirtualKeyCode;
public short wVirtualScanCode;
public CHAR uChar;
public ControlKeyState dwControlKeyState;
}

[StructLayout(LayoutKind.Sequential)]
public struct MOUSE_EVENT_RECORD
{
public COORD dwMousePosition;
public MouseButtonState dwButtonState;
public ControlKeyState dwControlKeyState;
public MouseEventFlags dwEventFlags;
}

[StructLayout(LayoutKind.Sequential)]
public struct WINDOW_BUFFER_SIZE_RECORD
{
public COORD dwSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct MENU_EVENT_RECORD
{
public uint dwCommandId;
}

[StructLayout(LayoutKind.Sequential)]
public struct FOCUS_EVENT_RECORD
{
public bool bSetFocus;
}

[StructLayout(LayoutKind.Explicit)]
public struct EVENT_UNION
{
[FieldOffset(0)] public KEY_EVENT_RECORD KeyEvent;
[FieldOffset(0)] public MOUSE_EVENT_RECORD MouseEvent;
[FieldOffset(0)] public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
[FieldOffset(0)] public MENU_EVENT_RECORD MenuEvent;
[FieldOffset(0)] public FOCUS_EVENT_RECORD FocusEvent;
}

[StructLayout(LayoutKind.Sequential)]
public struct INPUT_RECORD
{
public InputEventType EventType;
public EVENT_UNION Event;
}

[StructLayout(LayoutKind.Sequential)]
public struct CHAR_INFO
{
public CHAR Char;
public CharAttributes Attributes;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public CharAttributes wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_CURSOR_INFO
{
int dwSize;
bool bVisible;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_FONT_INFO
{
int nFont;
COORD dwFontSize;
}

[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SELECTION_INFO
{
public SelectionFlags dwFlags;
public COORD dwSelectionAnchor;
public SMALL_RECT srSelection;
}
#endregion

#region "Delegates"
public delegate bool HandlerRoutineDelegate (ControlEvents dwCtrlType);
#endregion

/// <summary>
/// Summary description for ConsoleAPI.
/// </summary>
public class ConsoleApi
{
[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PeekConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleInput (
IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutput (
IntPtr hConsoleOutput,
out CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCord,
ref SMALL_RECT lpReadRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutput (
IntPtr hConsoleOutput,
CHAR_INFO[] lpBuffer,
COORD dwBufferSize,
COORD dwBufferCoord,
ref SMALL_RECT lpWriteRegion);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputCharacter (
IntPtr hConsoleOutput,
StringBuilder lpCharacter,
int nLength,
COORD dwReadCoord,
out int lpNumberOfCharsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ReadConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwReadCoord,
out int lpNumberOfAttrsRead);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputCharacter (
IntPtr hConsoleOutput,
string lpCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool WriteConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes[] lpAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool FillConsoleOutputCharacter (
IntPtr hConsoleOupt,
CHAR cCharacter,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfCharsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FillConsoleOutputAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttribute,
int nLength,
COORD dwWriteCoord,
out int lpNumberOfAttrsWritten);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleInput,
out InputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleMode (
IntPtr hConsoleOutput,
out OutputModeFlags lpMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleInputEvents (
IntPtr hConsoleInput,
out int lpNumberOfEvents);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleScreenBufferInfo (
IntPtr hConsoleInput,
out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetLargestConsoleWindowSize (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleCursorInfo (
IntPtr hConsoleOutput,
out CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetCurrentConsoleFont (
IntPtr hConsoleOutput,
bool bMaximumWindow,
out CONSOLE_FONT_INFO lpConsoleCurrentFont);

[DllImport("kernel32", SetLastError=true)]
public static extern COORD GetConsoleFontSize (
IntPtr hConsoleOutput,
int nFont);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetConsoleSelectionInfo (out
CONSOLE_SELECTION_INFO lpConsoleSelectionInfo);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GetNumberOfConsoleMouseButtons (out int
lpNumberOfMouseButtons);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleInput,
InputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleMode (
IntPtr hConsoleOutput,
OutputModeFlags dwMode);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleActiveScreenBuffer (IntPtr
hConsoleOutput);

[DllImport("kernel32", SetLastError=true)]
public static extern bool FlushConsoleInputBuffer (IntPtr hConsoleInput);
[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleScreenBufferSize (
IntPtr hConsoleOutput,
COORD dwSize);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorPosition (
IntPtr hConsoleOutput,
COORD dwCursorPostion);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCursorInfo (
IntPtr hConsoleOutput,
ref CONSOLE_CURSOR_INFO lpConsoleCursorInfo);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool ScrollConsoleScreenBuffer (
IntPtr hConsoleOutput,
ref SMALL_RECT lpScrollRectangle,
ref SMALL_RECT lpClipRectangle,
COORD dwDestinationOrigin,
ref CHAR_INFO lpFill);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleWindowInfo (
IntPtr hConsoleOutput,
bool bAbsolute,
ref SMALL_RECT lpConsoleWindow);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleTextAttribute (
IntPtr hConsoleOutput,
CharAttributes wAttributes);

[DllImport("kernel32", SetLastError=true)]
public static extern bool SetConsoleCtrlHandler (
HandlerRoutineDelegate HandlerRoutine,
bool Add);

[DllImport("kernel32", SetLastError=true)]
public static extern bool GenerateConsoleCtrlEvent (
ControlEvents dwCtrlEvent,
int dwProcessGroupId);

[DllImport("kernel32", SetLastError=true)]
public static extern bool AllocConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool FreeConsole();

[DllImport("kernel32", SetLastError=true)]
public static extern bool AttachConsole (int dwProcessId);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetConsoleTitle (
StringBuilder lpConsoleTitle,
int nSize);

[DllImport("kernel32", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool SetConsoleTitle (
string lpConsoleTitle);

[DllImport("kernel32", SetLastError=true)]
public static extern IntPtr GetStdHandle (StandardHandle nStdHandle);

private ConsoleApi() {}
}
}
and here is a little class that uses some of them (it is a converted and
modified MSDN sample)...

using System;
using System.Threading;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

using FireAnt.ConsoleLib;

namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
private static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
//Console.WriteLine(Marshal.SizeOf(typeof(INPUT_RECO RD)));
IntPtr hStdin;
int cNumRead, i;
InputModeFlags fdwMode, fdwSaveOldMode;
INPUT_RECORD[] irInBuf = new INPUT_RECORD[128];

// Get the standard input handle.

hStdin = ConsoleApi.GetStdHandle(StandardHandle.Input);
if (hStdin == INVALID_HANDLE_VALUE)
MyErrorExit("GetStdHandle");

// Save the current input mode, to be restored on exit.
if (! ConsoleApi.GetConsoleMode(hStdin, out fdwSaveOldMode) )
MyErrorExit("GetConsoleMode");

// Enable the window and mouse input events.
fdwMode = InputModeFlags.EnableWindowInput |
InputModeFlags.EnableMouseInput;
if (! ConsoleApi.SetConsoleMode(hStdin, fdwMode) )
MyErrorExit("SetConsoleMode");

IntPtr hStdout = ConsoleApi.GetStdHandle(StandardHandle.Output);
COORD size = ConsoleApi.GetLargestConsoleWindowSize(hStdout);
ConsoleApi.SetConsoleScreenBufferSize(hStdout, size);
Console.WriteLine("size.X = {0}, size.Y = {1}", size.X, size.Y);

// Loop to read and handle the input events.
while (true)
{

// Wait for the events.
if (! ConsoleApi.ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
out cNumRead) ) // number of records read
MyErrorExit("ReadConsoleInput");

// Dispatch the events to the appropriate handler.

for (i = 0; i < cNumRead; i++)
{
switch(irInBuf[i].EventType)
{
case InputEventType.KeyEvent: // keyboard input
KeyEventProc(ref irInBuf[i].Event.KeyEvent);
break;

case InputEventType.MouseEvent: // mouse input
MouseEventProc(ref irInBuf[i].Event.MouseEvent);
break;

case InputEventType.WindowBufferSizeEvent: // scrn buf. resizing
ResizeEventProc(ref irInBuf[i].Event.WindowBufferSizeEvent);
break;

case InputEventType.FocusEvent: // disregard focus events

case InputEventType.MenuEvent: // disregard menu events
break;

default:
MyErrorExit("unknown event type");
break;
}
}
}
}

private static void MouseEventProc(ref MOUSE_EVENT_RECORD MouseEvent)
{
Console.WriteLine("Button State = {0}", MouseEvent.dwButtonState);
}

private static void ResizeEventProc(ref WINDOW_BUFFER_SIZE_RECORD
WindowEvent)
{
Console.WriteLine("Resize");
}

private static void KeyEventProc(ref KEY_EVENT_RECORD KeyEvent)
{
Console.WriteLine(KeyEvent.wVirtualKeyCode);
}

private static void MyErrorExit(string msg)
{
Console.WriteLine(msg);
System.Environment.Exit(1);
}
}
}
This doesn't test all of them, and I haven't tested all of them yet - but
your welcome to 'em...

HTH

Tom Shelton [MVP]

PS: Man OE sucks... Now I realize why I started using slrn...

Nov 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MuZZy | last post by:
HI I just wonder if someone can help me with this: I have a windows app project developed on VC++ 6.0. I need to adapt it to be able to compile as a console app as well (So it would call main()...
2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
5
by: Mullin Yu | last post by:
i want to build an application of both gui and batch interface by using windows application project. i check either passing any args or not. if no, then open the gui application. if yes, use the...
7
by: ajikoe | last post by:
Hello All, It is said that : Enabling the console window is easy. From Microsoft Visual Studio®, right-click on the project and choose Properties. Change the output type from Windows Application...
6
by: carbon_dragon | last post by:
Ok, so here is the problem. I'm working on a headless server program implemented as a .NET C# Console project. There is a UPS mounted to this server (though not a windows compliant UPS). I can only...
8
by: Alison | last post by:
Hi, Al I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window...
0
by: Maxwell | last post by:
Hello, I recently completed a MC++ (VS2003) DLL that wraps a non MFC C++ DLL and need to use it in a MC++ Console Application (no forms/guis of any kind just output to console). Trouble is...
15
by: Michael C | last post by:
Is it possible to have an app that is both a console app and a windows app? If there are no command line switches then it will run as a console app, if there are command line switches then it will...
0
by: Stephen Thomas | last post by:
Hi there I wonder if any one has encountered this problem or can suggest what is wrong. I am trying the a procedure from the msn site but get the following message: Error 1 The type or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.