954,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do you turn a command line application into a regular Windows application?

I want to know how you would go about adding a GUI to a command line application.

For example, I think uTorrent can be used in the command line? but it also has a regular Windows version.

ninjaface567
Newbie Poster
12 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

well, You cant simply do that. The developer of the program must provide GUI version of program. If you are developer, you have to write a code for GUI design...

khajvah
Junior Poster in Training
64 posts since Jan 2012
Reputation Points: 10
Solved Threads: 4
Infraction Points: 5
 

I want to know how you would go about adding a GUI to a command line application.

For example, I think uTorrent can be used in the command line? but it also has a regular Windows version.

You can create a 'batch-file', and then double-click on it (it will be executed by the command line). The extension used for this is .bat.
Not that hard to do. You can google a little bit around, and will learn quickly how to do this.
For example, visit this site: http://rancidtaste.hubpages.com/hub/How-to-create-a-batch-file

Pjieter
Junior Poster
125 posts since Jan 2012
Reputation Points: 3
Solved Threads: 7
 
For example, visit this site: http://rancidtaste.hubpages.com/hub/How-to-create-a-batch-file


Or not.

The page you linked is all too brief, misleading in some places, and flat out wrong in others. For example, the writer doesn't even know the purpose of@Echo Off in a batch file.

Type @echo off at the beginning of the file. This line prevents the spaces in the batch file to read during execution time.

Say what?

Here are a few far better resources: http://www.computerhope.com/batch.htm
http://www.ericphelps.com/batch/
http://users.cybercity.dk/~bse26236/home.html

Perhaps the writer of the page you linked could learn something there...

Cheers :)
PP

PhilliePhan
Central Scrutinizer
Moderator
1,942 posts since Dec 2006
Reputation Points: 184
Solved Threads: 110
 

Just my cent.
If you only will provide a gui for the application, you can add a form that will be the gui for it.

The form must contain the necessary info an controls to be able to call the right methods or functions you already defined.

Usually, on the main procedure, you will check if the environment is user interactive to show the form, unless a parameter in the call to the application asks for not to use the GUI.

If you must show the form, then show it as dialog, and end the application when the form is closed.

Hope this helps.

lolafuertes
Master Poster
788 posts since Oct 2008
Reputation Points: 120
Solved Threads: 166
 

Just my cent. If you only will provide a gui for the application, you can add a form that will be the gui for it.

The form must contain the necessary info an controls to be able to call the right methods or functions you already defined.

Usually, on the main procedure, you will check if the environment is user interactive to show the form, unless a parameter in the call to the application asks for not to use the GUI.

If you must show the form, then show it as dialog, and end the application when the form is closed.

Hope this helps.

Okay well I kind of know how to make Windows forms applications if that's what you mean. But most tutorials just show how to add buttons and stuff to the form and call functions with them. I guess you can make class files and include them in the main file, but where would you define functions?

ninjaface567
Newbie Poster
12 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

Some of this code is mine and some is not. It is an example of how to build a GUI for a console application. In this case, the application is md5sums.exe, which takes a file or folder name as an argument then calculates a checksum for the file, or all files in the folder. The controls on the form are

txtOutput - displays program output (stdout and stderr)
tstFile - for the user to enter a file or folder name
btnExecute - executes the command

Public Class Form1

    Private WithEvents MyProcess As Process
    Private Delegate Sub UpdateOutputDelegate(ByVal text As String)

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        MyProcess = New Process

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        MyProcess.Close()

    End Sub

    Private Sub btnExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecute.Click

        If My.Computer.FileSystem.FileExists(txtFile.Text) Or My.Computer.FileSystem.DirectoryExists(txtFile.Text) Then

            With MyProcess.StartInfo
                .FileName = "cmd.exe"
                .Arguments = "/c d:\utils\md5sums.exe " & txtFile.Text
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardInput = True
                .RedirectStandardOutput = True
                .RedirectStandardError = True
            End With

            MyProcess.Start()

            MyProcess.BeginErrorReadLine()      'start async read on stderr
            MyProcess.BeginOutputReadLine()     'start async read on stdout

        Else

            MsgBox("file or folder not found", vbOKOnly, txtFile.Text)

        End If

    End Sub

    Private Sub MyProcess_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.ErrorDataReceived

        'add stderr text to output display

        UpdateOutput(vbCrLf & "Error: " & e.Data)

    End Sub

    Private Sub MyProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.OutputDataReceived

        'add stdout text to output display

        UpdateOutput(vbCrLf & e.Data)

    End Sub

    Private Sub UpdateOutput(ByVal text As String)

        'add text to output display

        If txtOutput.InvokeRequired Then
            Dim myDelegate As New UpdateOutputDelegate(AddressOf UpdateOutput)
            Me.Invoke(myDelegate, text)
        Else
            txtOutput.AppendText(text)
        End If

    End Sub

End Class


Code could be added to parse the text in txtOutput and extract the checksum. Comments on how to improve this code are always appreciated.

Reverend Jim
Posting Shark
Moderator
1,161 posts since Aug 2010
Reputation Points: 253
Solved Threads: 158
 

What about in C++?

ninjaface567
Newbie Poster
12 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 
What about in C++?


Then that's a question for the C++ forum.

Reverend Jim
Posting Shark
Moderator
1,161 posts since Aug 2010
Reputation Points: 253
Solved Threads: 158
 
Then that's a question for the C++ forum.


But I'm talking about Windows applications specifically.

ninjaface567
Newbie Poster
12 posts since Jan 2012
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You