Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Creating GUI (http://www.programmingforums.org/showthread.php?t=8951)

jcdf Mar 20th, 2006 11:02 AM

Creating GUI
 
Hello I am new in this forum.
I am currently trying to create a GUI (graphical user interface) to act as a front end for a number of other applications using C++. The requirements for this is that the GUI is able to start up the other applications and interact with them through the command line. I am not sure how to do this.

Could anybody point me to a website which gives advice on this. I understand the basics of how the command line works ie that when a programme starts it can receive varaibles from the command line and often when a programme ends it returns variable to the command line like:

return 0;
}

But beyond this I do not know much else. How do you code a programme to interact with anouther programme. for example: start paint.exe and instruct it to load a specfic file.

Infinite Recursion Mar 20th, 2006 11:55 AM

For GUI development in C++, I'm leaning more towards wxWidgets these days.

"paint" is deprecated on my box, I have "pbrush" (which is basically the same thing)...

To open an image as soon as pbrush is loaded, just pass the image filename in as a parameter to the command.

c:\start pbrush "c:\images\myImage.png"

Ooble Mar 20th, 2006 1:22 PM

I just answered the GUI question in this thread.

jcdf Apr 4th, 2006 6:00 AM

Infinite Recursion
I am not really asking about the GUI. That was just to put my project in context. I know most of how to create a GUI.

What I really want to know is how to: pass the image (or any other) filename in as a parameter to the command.

Do you know of any good websites that explain all the aspects of what you can do with the "command line" and perhaps provide some examples and tutorials as well? Using the C++ language.

Ooble Apr 4th, 2006 6:59 AM

When you write the main function, you'll often write it like this:
:

int main ()
{
        ...
}


While correct, that's shorthand for this:
:

int main (int argc, char* argv[])
{
        ...
}


You have two variables here, argc and argv. The former is the number of parameters you pass to the application, and the latter the parameters themselves. Put another way, if we start our program like this:
:

program.exe My name "is Fred"
We have four parameters, so argc == 4. The first is stored in argv[0], and is the name of the program itself: program.exe. The second, in argv[1], is My. The last two, in argv[2] and argv[3] respectively, are name and is Fred.

That's all a bit abstract, so we'll write a program to demonstrate. Compile and run this - call it "params.exe" or something:
:

#include <iostream>

int main (int argc, char* argv[])
{
        std::cout << "argc = " << argc << std::endl << std::endl;
       
        for (int i = 0; i < argc; i++)
        {
                std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
        }
}

Run it with parameters - for example, params.exe 10 foo "I like sausages" or something equally retarded - and see what happens. If you have any more questions, let us know. :)

jcdf Apr 5th, 2006 8:44 AM

Not exactly what I was looking for.
 
Thanks Ooblo

But I already knew how to do that. I know how you can start a program and pass a number of parameters to it via the command line from the Dos prompt as you have demonstrated. I also know that when a program shuts down it can pass parameters back to the command line. e.g.

int main(void)
{
int x =3;
return x;
}

What I really want to know is how to code a program so that it sents parameters to the command line without having to shut down. Some sort of function call. Also how to code a program to read messages off the command line after the program was started running.

void main (void)
{
code to send to command line: (program.exe My name "is Fred")
code to read from command line: ("whatever happons to be on command line")
}

grumpy Apr 5th, 2006 9:11 AM

What you're asking for is a means of communicating with a running program. That is not achieved via any form of command line. A program accesses data on a command line when it starts, and there is no trivial way to change that command line and force the running program to reread it. There is also no trivial way that a program can change it's command line, and use that to communicate with some other program (eg the shell that started it).

To achieve what you want, you need to use some means of interprocess communication, and both programs need to be designed to allow that. Let's say that program A starts program B, and wants to exchange data with program B. A simple option would be for program A to write a data file while Program B periodically checks if that file exists and, if the file exists, reads it and then deletes it. If program B wants to send data back to program A, it can use the same technique (probably with a different filename), and program A needs to poll for and read that file.

Other means of interprocess communication include sockets, mailboxes, dedicated windows messages (eg WM_COPYDATA), etc. But one common feature of all of them; if you want two programs to communicate, BOTH programs need to be specifically designed to cooperate.

bl00dninja Apr 6th, 2006 8:02 PM

thanks for explaining what a GUI was, i had no fucking idea until you showed up. when main returns 0, it does that for a reason, older programs that suck return a value to the operating system for error codes, if you've documented what error 319 might be, then you'll know something about your app when it runs.


All times are GMT -5. The time now is 5:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC