LITTLEBLACKDOG.COM Forum Index LITTLEBLACKDOG.COM

 
LWD LWD   FAQ FAQ   Memberlist Memberlist   Usergroups Usergroups   Active Topics Active Topics   Register Register  
  Profile Profile   Log in to check your private messages Log in to check your private messages   Log in Log in  
  Who is Online Who is Online   Image Gallery Image Gallery   Chat Chat   Search Search  
  LWDGear       LBDGear  

View next topic
View previous topic
Post new topic     Reply to topic   LITTLEBLACKDOG.COM Forum Index » Code Warriors
Author Message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Mon May 05, 2003 4:39 am   Post subject: Windows API design Reply with quote Back to top  

Hi ppl,

I'm quite new to windows API and want u guyz to give me some help here, thanz really!!

I have a main window now and I created 6 child windows, each for running an executable C program.
I have 6 C programs which are actually socket programs. They talk to each other using TCP .

What I'm doing now is simply use a child window to display the input and output messages of these 6 C programs (like TextOut and input for these 6 programs).

The main window there is just for grouping the 6 child windows together to make it more convenient. So I think there won't be any message loop for the main window. Just creating the child windows. And the child windows will execute the C programs. These C programs will run and output messages to their own child window like a screen and get input from their corresponding child window.

So If I have A B C D E F for the executable C programs. I will also have child windows A B C D E F and these 6 child windows will be created by the main window. And the input and ouput of messages on the screen of child window A will be all handled by the .exe of program A.

What I wanna ask is...is this possible at all? And how do I actually implement this? I think the complicated part is how do those 6 programs handle the in and out of messages on the screen of their own child window? Shocked

Not sure I make it clear coz I am always lack of organization, so if you don't understand my design, just drop me a few lines, thanz so much!! Very Happy

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
hohlecow
Tail-Wagger
Tail-Wagger


Joined: 17 May 2002
Posts: 2151
Location: hungary for turkey and chile

Post Posted: Mon May 05, 2003 6:30 am   Post subject: Reply with quote Back to top  

are you using threads for each separate program? have you written these separate programs, or are they precompiled? are you using MFC, Win32, or what to build your GUI? are you capturing standard output, or are you writing to some other buffer?

_________________
give as much as you can, and take nothing

sometimes i think if zombies were attacking us, liberals would be fighting for thier rights, "they eat brains for fuel, it's part of who they are" or "we can't descriminate against them, that's just the way they were reanimated."


trying it again: POTD (picture of the day)
View user's profile Send private message Send e-mail Visit poster's website AIM Address
hohlecow
Tail-Wagger
Tail-Wagger


Joined: 17 May 2002
Posts: 2151
Location: hungary for turkey and chile

Post Posted: Mon May 05, 2003 6:31 am   Post subject: Reply with quote Back to top  

is this the same program as before, or a new program?

_________________
give as much as you can, and take nothing

sometimes i think if zombies were attacking us, liberals would be fighting for thier rights, "they eat brains for fuel, it's part of who they are" or "we can't descriminate against them, that's just the way they were reanimated."


trying it again: POTD (picture of the day)
View user's profile Send private message Send e-mail Visit poster's website AIM Address
hohlecow
Tail-Wagger
Tail-Wagger


Joined: 17 May 2002
Posts: 2151
Location: hungary for turkey and chile

Post Posted: Mon May 05, 2003 6:33 am   Post subject: Reply with quote Back to top  

you could always write a batch file:
Code: Select all
a &
b &
c &
d &
e &
f &


and use explorer as your "single window"

_________________
give as much as you can, and take nothing

sometimes i think if zombies were attacking us, liberals would be fighting for thier rights, "they eat brains for fuel, it's part of who they are" or "we can't descriminate against them, that's just the way they were reanimated."


trying it again: POTD (picture of the day)
View user's profile Send private message Send e-mail Visit poster's website AIM Address
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Mon May 05, 2003 6:49 am   Post subject: Reply with quote Back to top  

I am not using therad for the separate program, actually it's just I want to run these 6 executable C programs (that's after compiled, producing .exe) in the child windows. You can suggest me to do in some other ways. Very Happy

But I would love to separate these programs as much as possible as I said they are representing different parties, talking to each other through TCP. Having them inside a main window is not that good already, blurring the orginial idea, if more connections are made between the programs, then the orginial purpose will be lost... Shocked

Yes I have written these separate programs, I have all the source codes, so I can change them, but I want to limit the changes only to the I/Os to the screen of child windows. Like in the command prompt mode for tehse 6 programs, I use printf for output and getchar for input. Then in the GUI, I might be using TextOut for output..but I dunno what should be used for input.. Confused

And yes I am using Win32. capturing standard output? Can I still do that in Win32? Shocked I really dunno hehe. I wanna hear what u suggest me to do Very Happy

The program...same as before?..um...hard to say...I guess we better treat it as some different ones bcoz I have made changes afterwards.

And I don't get the batch file method, hehe Mr. Green, can you elaborate more? Thanz really!! Very Happy

_________________
fRaNkLy i'm FrAnKy

Last edited by frankly on Mon May 05, 2003 7:24 am; edited 1 time in total
View user's profile Send private message
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 27
Posts: 12393
Location: The Constitution State

Post Posted: Mon May 05, 2003 7:06 am   Post subject: Reply with quote Back to top  

Each child window will have to call "CreateProcess()" to launch the executable program it's associated with, and then in the child window's message loop it'll read from the console's output. The child window will be in charge of starting and stopping that new process.

So no, you won't be using threads, you'll be using child processes. It'll be just as if you manually started each of the six programs but the child windows are the ones who actually do that work for you. That way you can get a hook between the child window and the console for reading the output.

It's most likely open a new command window which you can hide, but using FindWindow() passing it the text you see in the console window's title bar. That returns an HWND which you can then send it a WM_SHOWWINDOW message with SW_HIDE parameter to hide it. Keep the HWND if you need to use it again later.

When cleaning up and destroying the child window, the child window's destructor should kill the associated process (you C program you attached) if it hasn't ended yet.

Go on MSDN website and read up on the Win32 API functions I've mentioned here.

CreateProcess()
FindWindow()

_________________
Bright, Vibrant, Blue - Lycander's webcomic

Don't fwoosh me bro.
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Mon May 05, 2003 7:18 am   Post subject: Reply with quote Back to top  

Lycander wrote:
Each child window will have to call "CreateProcess()" to launch the executable program it's associated with, and then in the child window's message loop it'll read from the console's output. The child window will be in charge of starting and stopping that new process.

So no, you won't be using threads, you'll be using child processes. It'll be just as if you manually started each of the six programs but the child windows are the ones who actually do that work for you. That way you can get a hook between the child window and the console for reading the output.

COOOOOOL!!! Mr. Green yes yes that's more like it, I think this is just what I need!! Mr. Green
Quote:
It's most likely open a new command window which you can hide, but using FindWindow() passing it the text you see in the console window's title bar. That returns an HWND which you can then send it a WM_SHOWWINDOW message with SW_HIDE parameter to hide it. Keep the HWND if you need to use it again later.

But don't quite get what you mean here Shocked

[edit] Oh...but hold on...you mean I should create child process for those child windows? But I have already created them using MDI Shocked

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 27
Posts: 12393
Location: The Constitution State

Post Posted: Mon May 05, 2003 10:13 am   Post subject: Reply with quote Back to top  

No what I mean is: you said you have 6 different C programs, and they seem to be command line programs which you want 6 child windows to monitor and display output from. So you create a seperate child process for each of those C programs, and in each child window it would monitor that corresponding process.

When you create a new process you get a handle to it, with which you can read from stdout, that's the bit I said to hook up to each corresponding child window. Using MDI as you are now is fine.

_________________
Bright, Vibrant, Blue - Lycander's webcomic

Don't fwoosh me bro.
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Mon May 05, 2003 3:34 pm   Post subject: Reply with quote Back to top  

So u mean the child process will monitor the input and the parent process will display output? Shocked But I only allow input at some given times.

Actually it's like this:
I printf "Please enter sth"
and I get the input keyed in by user as "sth"

So it's like those command-line window but it's just I wanna make it an application window coz I wanna add one or two buttons there to make the programs start hehe Mr. Green

Oh but did I misunderstand you? Actually can you list some functions used in a flow? Mr. Green Think that will make me easier to understand coz I'm not good at logic Laughing

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Mon May 05, 2003 11:16 pm   Post subject: Reply with quote Back to top  

OK I have some progress now Cool

I have created 6 child windows and trying to execute the C executable in these child windows

I am using WinExec but there are only two parameters so how do I pass the child window handle to the command to make the .exe to be run in the specified child window? Shocked

Thanz Very Happy

[edit] Oh yes....Lycander told me to use CreateProcess().. Shocked
Let me try...

[edit]
Oh...I think what the problem is now, I just made a menu item which is "execute" Lycander should know hehe. and the .exe are called only when the menu is clicked. so...can't start to execute the files right away...so what do u guyz suggest me to do? Shocked

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Tue May 06, 2003 1:03 am   Post subject: Reply with quote Back to top  

Oh Lycander, got a question here, do I have to use pipes for the processes? Or just create the processes? So the child is to execute the 6 C programs right? But what are the parents doing? Shocked

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 27
Posts: 12393
Location: The Constitution State

Post Posted: Tue May 06, 2003 6:27 am   Post subject: Reply with quote Back to top  

The parents are watching over the children of course Wink Ok, beyond that pun, the parent window (your MDI parent window) controls any messages not handled by the child windows. And if the parent window is closed, then it sends a destroy message to each of the child window. That's when the child window is responsible for terminating the process which it created.

I believe pipes are go inter-process communications, like reading and writing to each other's console (stdin, stdout).

I uploaded 2 files to my webserver which I've linked below. It's a WinHelp file and the table of contents file. Download them and keep them together in the same folder. It's a great reference that I use from time to time to look up Win32 API functions. I looked breifly thru it and there's some info on creating processes, and how to create/use pipes. Go into the index and type "Pipe" and read all the topics related to it.

http://www.ly-tech.com/win32/WIN32.HLP (~24 MB)
http://www.ly-tech.com/win32/WIN32.CNT (~100 KB)

Rather large download, but worth it!

EDIT: I just realized that clicking on the link and my browser tries to open it in a new window. So just to be sure, you should right click on the link and "Save As..."

_________________
Bright, Vibrant, Blue - Lycander's webcomic

Don't fwoosh me bro.
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Tue May 06, 2003 6:35 am   Post subject: Reply with quote Back to top  

Quote:
The parents are watching over the children of course Ok, beyond that pun, the parent window (your MDI parent window) controls any messages not handled by the child windows. And if the parent window is closed, then it sends a destroy message to each of the child window. That's when the child window is responsible for terminating the process which it created.

Oh so you mean the CreateProcess is for creating child windows? Shocked
But I have already created the child windows Very Happy Or...I misunderstand again... Shocked hehe Mr. Green

ahhhhhhhh so I really have to use pipes? Sounds like a really hard one...I plan to finish the GUI within a couple of hrs from now...oh...not sure if I have time... Shocked

Actually I don't quite know where to use the pipes....yes I know it's for my little C programs to communicate with my little Windows API program but...well...maybe after I read your help files I'd be more clear hehe

And thanz soooooooooooo much for the files haha Very Happy Very Happy
me still downloading....really a big file...it's 6X% now.... Mr. Green
But the "win32.cnt" is it just a html? Shocked
[edit] oh...I just read your edit hehe Mr. Green

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
frankly
Stray Dog


Joined: 20 Mar 2003
Posts: 41

Post Posted: Tue May 06, 2003 6:45 am   Post subject: Reply with quote Back to top  

Oh cool me looking up the help file now
but hey, do you know where I can look at some source codes? Bcoz that would certainly help a lot too, to see how functions are called Mr. Green

_________________
fRaNkLy i'm FrAnKy
View user's profile Send private message
Lycander
Lead Dog
Lead Dog


Joined: 24 May 2002
Age: 27
Posts: 12393
Location: The Constitution State

Post Posted: Tue May 06, 2003 7:37 am   Post subject: Reply with quote Back to top  

www.programmersheaven.com

www.codeproject.com

_________________
Bright, Vibrant, Blue - Lycander's webcomic

Don't fwoosh me bro.
View user's profile Send private message
Display posts from previous:   
Post new topic     Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
phpBB SEO
All times are GMT - 8 Hours

Help us keep advertisements off this site. Donate today!