"Windows Application" vs. "Console Application" 
Author Message
 "Windows Application" vs. "Console Application"

Before I compile my project I have to choose the
OutputType which is Windows Application or Console
Application.
Is it possible to change that property during runtime? I
want to create an Windows application which should act as
Console application when I start it with a command line
argument like /nogui.

Thanks in advance
Thomas



Mon, 31 Jan 2005 00:41:22 GMT  
 "Windows Application" vs. "Console Application"
you could do the following:

Build your windows App. Then change the outtype to be "Console Application"
at compile time. Then you could add something like the following code and
make the Startup Object in your Project properties to be "Sub Main"

Module Module1
    Sub Main()
        Dim GUI As Boolean = True

        If InStr(Command, "/nogui", CompareMethod.Text) Then
            GUI = False
        End If

        If GUI Then
            StartGUI()
        Else
            Console.WriteLine("no GUI")
        End If
    End Sub

    Sub StartGUI()
        Dim Form As New Form1()
        Form.Show()
        Windows.Forms.Application.Run()
    End Sub
End Module

also note that in your Form, you need something like the following in order
to enable your application to close properly.

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Windows.Forms.Application.ExitThread()
    End Sub

thanks,
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Before I compile my project I have to choose the
> OutputType which is Windows Application or Console
> Application.
> Is it possible to change that property during runtime? I
> want to create an Windows application which should act as
> Console application when I start it with a command line
> argument like /nogui.

> Thanks in advance
> Thomas



Mon, 31 Jan 2005 04:37:58 GMT  
 "Windows Application" vs. "Console Application"
Thanks for your instant reply but unfortunately it is not
doing what I want. The nogui part is working perfectly
but when I start it with gui I have an open console
window in the background. Can I get rid of that?

Thomas

Quote:
>-----Original Message-----
>you could do the following:

>Build your windows App. Then change the outtype to

be "Console Application"
Quote:
>at compile time. Then you could add something like the
following code and
>make the Startup Object in your Project properties to
be "Sub Main"

>Module Module1
>    Sub Main()
>        Dim GUI As Boolean = True

>        If InStr(Command, "/nogui", CompareMethod.Text)
Then
>            GUI = False
>        End If

>        If GUI Then
>            StartGUI()
>        Else
>            Console.WriteLine("no GUI")
>        End If
>    End Sub

>    Sub StartGUI()
>        Dim Form As New Form1()
>        Form.Show()
>        Windows.Forms.Application.Run()
>    End Sub
>End Module

>also note that in your Form, you need something like the
following in order
>to enable your application to close properly.

>    Private Sub Form1_Closing(ByVal sender As Object,
ByVal e As
>System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
>        Windows.Forms.Application.ExitThread()
>    End Sub

>thanks,
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.



>> Before I compile my project I have to choose the
>> OutputType which is Windows Application or Console
>> Application.
>> Is it possible to change that property during runtime?
I
>> want to create an Windows application which should act
as
>> Console application when I start it with a command line
>> argument like /nogui.

>> Thanks in advance
>> Thomas

>.



Mon, 31 Jan 2005 05:17:41 GMT  
 "Windows Application" vs. "Console Application"
you could try the following to get rid of the console window. But note that
it will pop up for an instant initially before it vanishes. This code uses
win32 apis to accomplish this.

Module Module1
    Private Declare Function GetConsoleWindow Lib "kernel32" () As Integer
    Private Declare Function CloseWindow Lib "user32" (ByVal hwnd As
Integer) As Integer
    Private Declare Function FreeConsole Lib "kernel32" () As Integer

    Sub Main()
        Dim GUI As Boolean = True

        If InStr(Microsoft.VisualBasic.Command, "/nogui",
CompareMethod.Text) Then
            GUI = False
        End If

        If GUI Then
            CloseConsole()
            StartGUI()
        Else
            Console.WriteLine("no GUI")
        End If
    End Sub

    Sub StartGUI()
        Dim Form As New Form1()
        Form.Show()
        Windows.Forms.Application.Run()
    End Sub

    Sub CloseConsole()
        Dim ActiveWindowHandle As Integer = GetConsoleWindow
        FreeConsole()
        CloseWindow(ActiveWindowHandle)
    End Sub
End Module

thanks,
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Thanks for your instant reply but unfortunately it is not
> doing what I want. The nogui part is working perfectly
> but when I start it with gui I have an open console
> window in the background. Can I get rid of that?

> Thomas

> >-----Original Message-----
> >you could do the following:

> >Build your windows App. Then change the outtype to
> be "Console Application"
> >at compile time. Then you could add something like the
> following code and
> >make the Startup Object in your Project properties to
> be "Sub Main"

> >Module Module1
> >    Sub Main()
> >        Dim GUI As Boolean = True

> >        If InStr(Command, "/nogui", CompareMethod.Text)
> Then
> >            GUI = False
> >        End If

> >        If GUI Then
> >            StartGUI()
> >        Else
> >            Console.WriteLine("no GUI")
> >        End If
> >    End Sub

> >    Sub StartGUI()
> >        Dim Form As New Form1()
> >        Form.Show()
> >        Windows.Forms.Application.Run()
> >    End Sub
> >End Module

> >also note that in your Form, you need something like the
> following in order
> >to enable your application to close properly.

> >    Private Sub Form1_Closing(ByVal sender As Object,
> ByVal e As
> >System.ComponentModel.CancelEventArgs) Handles
> MyBase.Closing
> >        Windows.Forms.Application.ExitThread()
> >    End Sub

> >thanks,
> >VB Team

> >--
> >This posting is provided "AS IS" with no warranties, and
> confers no rights.



> >> Before I compile my project I have to choose the
> >> OutputType which is Windows Application or Console
> >> Application.
> >> Is it possible to change that property during runtime?
> I
> >> want to create an Windows application which should act
> as
> >> Console application when I start it with a command line
> >> argument like /nogui.

> >> Thanks in advance
> >> Thomas

> >.



Tue, 01 Feb 2005 03:44:43 GMT  
 "Windows Application" vs. "Console Application"
Thanks for your help.
Thomas

Quote:
>-----Original Message-----
>you could try the following to get rid of the console

window. But note that
Quote:
>it will pop up for an instant initially before it

vanishes. This code uses
Quote:
>win32 apis to accomplish this.

>Module Module1
>    Private Declare Function GetConsoleWindow

Lib "kernel32" () As Integer
Quote:
>    Private Declare Function CloseWindow Lib "user32"
(ByVal hwnd As
>Integer) As Integer
>    Private Declare Function FreeConsole Lib "kernel32"
() As Integer

>    Sub Main()
>        Dim GUI As Boolean = True

>        If InStr(Microsoft.VisualBasic.Command, "/nogui",
>CompareMethod.Text) Then
>            GUI = False
>        End If

>        If GUI Then
>            CloseConsole()
>            StartGUI()
>        Else
>            Console.WriteLine("no GUI")
>        End If
>    End Sub

>    Sub StartGUI()
>        Dim Form As New Form1()
>        Form.Show()
>        Windows.Forms.Application.Run()
>    End Sub

>    Sub CloseConsole()
>        Dim ActiveWindowHandle As Integer =
GetConsoleWindow
>        FreeConsole()
>        CloseWindow(ActiveWindowHandle)
>    End Sub
>End Module

>thanks,
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.



>> Thanks for your instant reply but unfortunately it is
not
>> doing what I want. The nogui part is working perfectly
>> but when I start it with gui I have an open console
>> window in the background. Can I get rid of that?

>> Thomas

>> >-----Original Message-----
>> >you could do the following:

>> >Build your windows App. Then change the outtype to
>> be "Console Application"
>> >at compile time. Then you could add something like the
>> following code and
>> >make the Startup Object in your Project properties to
>> be "Sub Main"

>> >Module Module1
>> >    Sub Main()
>> >        Dim GUI As Boolean = True

>> >        If InStr(Command, "/nogui",
CompareMethod.Text)
>> Then
>> >            GUI = False
>> >        End If

>> >        If GUI Then
>> >            StartGUI()
>> >        Else
>> >            Console.WriteLine("no GUI")
>> >        End If
>> >    End Sub

>> >    Sub StartGUI()
>> >        Dim Form As New Form1()
>> >        Form.Show()
>> >        Windows.Forms.Application.Run()
>> >    End Sub
>> >End Module

>> >also note that in your Form, you need something like
the
>> following in order
>> >to enable your application to close properly.

>> >    Private Sub Form1_Closing(ByVal sender As Object,
>> ByVal e As
>> >System.ComponentModel.CancelEventArgs) Handles
>> MyBase.Closing
>> >        Windows.Forms.Application.ExitThread()
>> >    End Sub

>> >thanks,
>> >VB Team

>> >--
>> >This posting is provided "AS IS" with no warranties,
and
>> confers no rights.



>> >> Before I compile my project I have to choose the
>> >> OutputType which is Windows Application or Console
>> >> Application.
>> >> Is it possible to change that property during
runtime?
>> I
>> >> want to create an Windows application which should
act
>> as
>> >> Console application when I start it with a command
line
>> >> argument like /nogui.

>> >> Thanks in advance
>> >> Thomas

>> >.

>.



Tue, 01 Feb 2005 20:36:45 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. GetObject("","InternetExplorer.Application") fails in Excel VBA

2. GetObject("","InternetExplorer.Application") fails in Excel VBA

3. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

4. SysCmd 603, "path","path"

5. Disabling "BACK"/"FORWARD" buttons

6. Loop print "VARIABLE", "VARIABLE"

7. DLL or something like "#"#ยค#"!"#

8. Disabling "BACK"/"FORWARD" buttons

9. CreateObject("Excel","//server"), MsgBox output

10. Problem With "window.showmodaldialog("")"

11. CreateObject("Excel","//server"), MsgBox output

12. "Cannot load """

 

 
Powered by phpBB® Forum Software