Thanks a lot, Tom. I got the idea now. I will start from what you provided here. I believe I will have more questions concerning this. I will ask for more help later
Thanks agai
Aliso
----- Tom Shelton wrote: ----
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 available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a console window run together with menus and toolbars
Aliso
I'm playing with this a little bit still... So, far what I have wil
only work on 2K up, but it could be modified to use a more genera
technique to get the console window handle. I think that if I was t
play with the windows style bits, I could get a more attractiv
integration (that's what I'm starting to play with now)
ption Explicit On
Option Strict O
Imports Syste
Imports System.Runtime.InteropService
Imports System.Windows.Form
Public Class Form
Inherits System.Windows.Forms.For
#Region " Windows Form Designer generated code
Public Sub New(
MyBase.New(
'This call is required by the Windows Form Designer
InitializeComponent(
'Add any initialization after the InitializeComponent() cal
End Su
'Form overrides dispose to clean up the component list
Protected Overloads Overrides Sub Dispose(ByVal disposing A
Boolean
If disposing The
If Not (components Is Nothing) The
components.Dispose(
End I
End I
MyBase.Dispose(disposing
End Su
'Required by the Windows Form Designe
Private components As System.ComponentModel.IContaine
'NOTE: The following procedure is required by the Windows For
Designe
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMen
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBa
Friend WithEvents Panel1 As System.Windows.Forms.Pane
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuIte
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuIte
Friend WithEvents Timer1 As System.Windows.Forms.Time
<System.Diagnostics.DebuggerStepThrough()> Private Su
InitializeComponent(
Me.components = New System.ComponentModel.Containe
Me.MainMenu1 = New System.Windows.Forms.MainMen
Me.MenuItem1 = New System.Windows.Forms.MenuIte
Me.MenuItem2 = New System.Windows.Forms.MenuIte
Me.StatusBar1 = New System.Windows.Forms.StatusBa
Me.Panel1 = New System.Windows.Forms.Pane
Me.Timer1 = New System.Windows.Forms.Timer(Me.components
Me.SuspendLayout(
'MainMenu
Me.MainMenu1.MenuItems.AddRange(Ne
System.Windows.Forms.MenuItem() {Me.MenuItem1}
'MenuItem
Me.MenuItem1.Index =
Me.MenuItem1.MenuItems.AddRange(Ne
System.Windows.Forms.MenuItem() {Me.MenuItem2}
Me.MenuItem1.Text = "&File
'MenuItem
Me.MenuItem2.Index =
Me.MenuItem2.Text = "E&xit
'StatusBar
Me.StatusBar1.Location = New System.Drawing.Point(0, 323)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size(552, 22)
Me.StatusBar1.TabIndex = 0
Me.StatusBar1.Text = "StatusBar1"
'
'Panel1
'
Me.Panel1.AutoScroll = True
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(552, 323)
Me.Panel1.TabIndex = 1
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1000
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(552, 345)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.StatusBar1)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
' this function only works on 2k up...
Private Declare Function GetConsoleWindow Lib "kernel32" () As
IntPtr
Private Declare Function AllocConsole Lib "kernel32" () As Boolean
Private Declare Function FreeConsole Lib "kernel32" () As Boolean
Private Declare Function SetParent Lib "user32" _
(ByVal hWndChild As IntPtr, _
ByVal hWndNewParent As IntPtr) As IntPtr
Private allocated As Boolean
Private hConsoleWindow As IntPtr
Private hOldParent As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not allocated Then
allocated = AllocConsole()
hConsoleWindow = GetConsoleWindow()
If Not hConsoleWindow.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hConsoleWindow, Me.Panel1.Handle)
End If
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If allocated Then
If Not hOldParent.Equals(IntPtr.Zero) Then
hOldParent = SetParent(hOldParent, hConsoleWindow)
End If
FreeConsole()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Static count As Integer = 0
count += 1
Console.WriteLine(count)
End Sub
End Class
I'll post again if I get this working better...