Re: Command Line Interface
From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 02/07/05
- Next message: Ajay Kalra: "Re: Incorporating AVI files in VC++ application"
- Previous message: Scott McPhillips [MVP]: "Re: Effective CMainFrame client area"
- In reply to: Mark Randall: "Re: Command Line Interface"
- Next in thread: Andy Mortimer [MS]: "RE: Command Line Interface"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 07 Feb 2005 08:21:56 -0500
Mark Randall wrote:
> Hmm, fair read thanks for that
>
> This is somewhat I am aiming for, to be honest my idea for this is Java
> Netbean's 'console window' which it uses for user input and output. I
> understand the problem is tho that Java is a interpretted language and I
> wish to have compiled code.
>
> I have a project I have written myself with between 10 and 15 thousand lines
> of code and containing several configurable options, rather than creating a
> GUI for them I wanted to impliment a streamed command line mode to edit them
> in the apps GUI' instead of having to provide dialogs for all of them.
>
> For example, I have a global defined class with some data in it, and I want
> the user to be able to change some settings via a command-line like
> interface for it, but in a structured way in my code, for example:
>
> flw -config
> flw> Enter Target: [user enters string]
> flw> Enter Speed: [user enters string and conv to double]
> [global class updated]
>
> Now in a console application I would write this as
>
> void SomeSub(void)
> {
> char target[128] = { 0 };
> double speed = 0.0;
> char happy[8] = { 0 };
>
> cout << "Enter Target: ";
> cin >> target;
> cout << "Enter Speed";
> cin >> speed;
>
> However, I want this to be implimented in a CEdit, or preferably, a
> CRichEditCtrl... I can write functions to read a string from the end of a
> line by using CString::Mid from the last length, to the new length once
> return is pressed.
>
> What I want my 'command line' like interface to do, is wait while the user
> enters a string, and then it continues once return has been pressed,
The existing procedural code will have to be run in a secondary thread
so the GUI will remain responsive while the code is waiting for user
intput. That can be done by putting all that code under a single
function, say "ThreadMain", then calling AfxBeginThread(ThreadMain, param).
Then to achieve I/O in the GUI you could impliment a few helper
functions to provide the equivalent of cin, cout, etc. to your thread.
These functions would use interthread communication to accomplish the
I/O in the GUI thread. Each helper function would use
WaitForSingleObject() to pause the worker thread until the user response
is available. The GUI thread uses SetEvent to signal the worker thread
when to resume.
-- Scott McPhillips [VC++ MVP]
- Next message: Ajay Kalra: "Re: Incorporating AVI files in VC++ application"
- Previous message: Scott McPhillips [MVP]: "Re: Effective CMainFrame client area"
- In reply to: Mark Randall: "Re: Command Line Interface"
- Next in thread: Andy Mortimer [MS]: "RE: Command Line Interface"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|