![]() |
Windows API design
Hi ppl,
I have some design questions about windows API, actually I'm quite new to windows API, really hope u guyz can give me some help, 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? 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!! :D |
hi Frankly,
You have various ways for communication between processes, for example OLE, COM, messaging .... or just creating DLL's instead of EXE files. I would propose a simple messaging via SendMessage from/to the C program. In this case You have to modify the source of the C programs to tell them the handle of the associated Delphi program's form (e.g. via runtime parameter). Another way is to call FindWindow from the C program to get the correct form handle. Then send a message to the other form by calling SendMessage(WM_CopyData, handle, hwnd, pcds) where handle is address handle hwnd is handle of sending window pcds points to a structure to transfer regards Roderich |
Oh thank you sooo much for your reply, Roderich, I'm very desperately to get some replies bcoz I'm totally stuck here... :(
I think that FindWindow thing is quite interesting :D bcoz I don't think I'm gonna modify those codes for the 6 programs bcoz they are supposed to be like this...and this GUI is only trying to let ppl to better understand what I'm doing. Like if I integrate the codes of these 6 programs, it will lose the orginial purpose and meanings. So I'll try to avoid making and changes. As little as possible I mean. So I have to use FindWindow in these 6 programs to ge the handle first? Is it the child's handle? hehe sorry for the stupid questions...me very new to Windows API :lol: |
Hi,
i shifted the Thread after Win-API. The section General-Programming is only for other programming languages. Bye, Daniel :hi: |
Oh cool thanz hehe :D
me can't read German very well...sorry... :oops: |
OK I have some progress now :hello:
I have created 6 child windows and trying to execute the C executable in these child windows 8) 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? :shock: Thanz :D [edit] Oh....or should I be using CreateProcess() to get the handle? :shock: |
First of all you should not use WinExec because it's obsolete. use instead Shelllexecite or CreateProcess.
Now my idea would be: Pass the Window-Handle as a parameter, when you start your process. |
a very dunb question...bcoz I usually set all the attributes to NULL, so which one should I set now for the handle? I couldn't find one suits the meaning "handle"...or did I missed something? :shock:
|
I don't know what your c-programs accept for parameters and how they handle them.
But I still wonder what you mean when you say, "execute the C executable in these child windows". As a matter of fact you have two processes: Your own and the c-program you started from within your application (process). Now tell me what do you want to do with the second process you started from within your application. I'm afraid you try do something that can't be done or there is a better solution than yours. |
Oh yes, I have 6 programs written in C and they communicate with each other using TCP connections. So one can simply execute them and then they would automatically send predefined messages to each other.
But one of these 6 programs require an input when running and then it will go back to run and then run till the end. These programs will end properly. I mean you can just leave it there after entering the input. I created a main window and created 6 child windows now. And I want each of these child windows to display the "printf" that is outputted by the 6 programs. So the child windows are like some screens display messages. And as I mentioned above, one of them will need input so one of these windows need to accept input. So what I want to do is to execute these 6 programs in the main window, I want to make a menu option "execute", and once it is clicked, the 6 programs will be called and executed. This is why I'm thinking of WinExec...but now I think I have to use CreateProcess(). So when this "execute" option is chosen, my program should call the 6 .exe to run the programs. And I am still messing with the attributes... :( Hope this would help you to understand more of my program, I appreciate very much that you're trying to help me as best as you could. Just want to say a BIG thank you to you :hello: |
Aaaah. Now I understand. You need to communicate with an console application (You mentioned the function printf.)?
Well if that's what you want to do you should make yourself familiar with Pipes: ![]() |
Oh actually I don't want console hehe, I want an application window...like the one we're using here. "Microsoft look" :mrgreen:
Bcoz apart from those input and ouputs I want some buttons there. And yse I mentioned printf bcoz I wrote the console proram. I think I'll simply replace all those printf with TextOut But I don't know how to deal with the inputs... :shock: And pipes...what are they for? Actually I have those two stevens book on UNIX programming, I have read some little on pipes. But how can I use it here? :shock: I know what I want to do now but I'm not quite sure how should I do it...hope you can give me some guidlines Thans really!! :D [edit] pipes are for two parties to communicate one writes to a pipe amd the other reads from the pipe so...which are the two parties concerned here? :shock: |
Did you follow the link I gave you? And did you read what is written there? These Pipes are different from them you know from your bash.
All right. Next try. :mrgreen: You can get the text of an TEdit or a TMemo with the message WM_GETTEXT, you can put text into these controlls with the message WM_SETTEXT. You can click a botton on a windows by sending the message BM_CLICK to it. But in all cases you need the handles of these controlls. With FindWindow you can get the handle of any mainapplication window and with FindWindowEx you can retrieve the handles of childwindows like TEdits, TButtons and so on. Alternitivly you can use GetDlgItem if you know the ID of these childwindows. You can look up any of these messages and functions here: ![]() But that's all I can provide to help you. Sorry. |
Actually me still reading the MSDN library
sooooooo many things there...but I have to finish all these by tomorrow.. :? Well...think it's ok hehe :mrgreen: Oh but isn't GetDigItem only for dialog boxes? :shock: I won't be having any dialog boxes in the program I'll simply make it like a console window, but with one or two little buttons :mrgreen: |
By tomorrow? :shock: Good luck, guy. :?
You can use GetDlgItem with windows as well. Zitat:
|
Zitat:
damn...ahhhh :( well....I'll show you!! hehe with your help maybe....:mrgreen:... ok me back to read the named pipes :coder: by the way, I should use named pipes right? Not Anonymous Pipes right? :shock: [edit] Oh and actually it's 5pm here in Hong Kong hehe, it's midnight over you there, haha of coz can't make it...so I stand a higher chance then do I? :wink: tell me yes... :? [edit] Oh and yes, actually how should I use the pipes? I read a few pages and I think it is "about" the same as the one I know :shock: |
With my help? Maybe, but I will get some sleep now, even if it's here a quarter past eleven before noon. :wink:
Well I never worked with pipes. I just know that it is a way to communicate. And if you can make ist in time? Hard to tell. Say good-bye to your bed, say good-bye to your wife or girlfriend for the rest of the evening and night, don't eat and just work as hard as you can. But if you want to deliver a good work, a stable program with the minimum of bugs, you will need at least three days or even a hole week. Because there's a lot to learn and if you don't understand what you are actually doing, you will fail. |
But me and all the others will try to help as best as possible. Maybe we can help you if you provide some code or something we can work with to help you.
|
11am?!?!?!?! :shock: :shock: :shock:
HOLY SH!T :!: OH MY GOD.......I'm not gonna make it....is there any simpler methods? Or this is the simplest already? I am already quitting all the usual things...no girls here...as always :? Not eating anything...o...damn.....it sounds very bad... :shock: |
Ok. Here is another idea: You can send data from one application to another by using WM_COPYDATA.
And don't worry we'll make it. :wink: |
Zitat:
Codings? The 6 programs are very long and as I am just executing them in the windows API program I'll simply supply the windows API main program, is that ok? :shock: Bcoz those 6 programs are real real long and if you want them of coz it is ok, anything you say actually, I can send them to you :shock: I need to finish this...I have to.. :( |
What does the "application" means? :shock:
But hey I don't quite understand...I have all the 6 programs comunicate with each othe already, I mean they can work very fine already. So I still have to use pipes or WM_COPYDATA? What are the communications for? :shock: Zitat:
|
Please don't send me any code. I wont have the time to do your work. Just post the relavent code. But I found some code for WM_COPYDATA. But again you will have to modify your c-programs:
First program, the sender:
Delphi-Quellcode:
Second program, the receiver:
function FindWindowByTitle(WindowTitle : string) : Hwnd;
var NextHandle : Hwnd; NextTitle : array[0..260] of char; begin NextHandle := GetWindow(Application.Handle,GW_HWNDFIRST); while (NextHandle > 0) do begin GetWindowText(NextHandle,NextTitle,255); if (pos(WindowTitle,StrPas(NextTitle)) <> 0) then begin result := NextHandle; exit; end else NextHandle := GetWindow(NextHandle,GW_HWNDNEXT); end; result := 0; end; procedure TForm1.Button1Click(Sender: TObject); var struct: CopyDataStruct; begin struct.cbData := Length(Edit1.Text); struct.lpData := PChar(Edit1.Text + #0); SendMessage(FindWindowByTitle('Form2'), WM_COPYDATA, handle, Integer(@struct)); end;
Delphi-Quellcode:
type
TForm1 = class(TForm) Label1: TLabel; procedure GetData(var msg: TMessage); message WM_COPYDATA; ... procedure TForm1.GetData(var msg: TMessage); var struct: PCopyDataStruct; begin struct := Ptr(msg.LParam); Form1.Label1.Caption := PChar(struct^.lpData); end; |
Zitat:
Zitat:
Zitat:
And if you want your c-program to communicate (receive and send data) you will have to modify your c-program. |
Oh actually I just want one of the 6 programs to get input and output from the screen. So...this is what you mean? the communication? :shock:
Oh but...can't this C program just output something to the screen and then get it back, and having all these done inside the C program itself? Or you're saying I just have to do the pipes in order to do this? :shock: Bcoz I thought the inputs and outputs can all be done inside the C program. And the GUI program (windows API) is simply creating the child windows and then execute the C programs. So it is not that easy? :shock: |
Zitat:
Zitat:
Zitat:
|
Zitat:
Zitat:
And then I thought it'll be better to make a windows GUI...so yes...it's vesy messy...so do you think it'll help you to learn better if you can see the windows API codings? Or you have to see also the C programs? :shock: And what changes are needed for that C program? You mentioned it has to be changed in order to communicate right? And yes, the other 5 C programs, they don't have to be changed right? :shock: They will just display outputs to the screen. [edit] Oh I'm terribly sorry, I didn't see your message before Zitat:
|
Oh I think I get a better idea of what you mean now
I have 6 C programs and I have a windows API program the pipes are for the 6 C programs to communicate with the API program, bcoz the C programs have to pass parameters to the API program, am I right? Oh...that would be real nasty then...I thought I'll only have to write a little program. And now I think it's another big program... So these 6 C programs, I have to make them to be "application window" when I create a project right? Bcoz I was making "console window" before for the UNIX running [edit] Oh sorry, one more thing, do I have to use named pipes or anonymous pipes? :shock: Thanz!! :D |
Oh I'm terribly sorry, I didn't see your message before :oops:
Zitat:
So where did you get the codes? Can you send me the link? I want to got there to have a look too. Bcoz I don't know what is the function pos(), I searched through MSDN but couldn't find much details on that. Thanz :P [edit] Oh yes, that is not a C function... :shock: |
Oh unbelievable!! I jsut found this link while searching for refernce of WM_COPYDATA
what do you think? :D ![]() [edit by Admin]link fixed.[/edit] |
Looks good.
|
I'm looking up the
![]() |
OK...I think I have resorted to use a individual window for a program :?
I mean one window application for one console program... :( But I still have problems even making that....how do I ouput the text? :shock: I know I have to use the function TextOut but ...should I simply replace all the "printf" with "TextOut" or there is extra workings? :shock: Thanz!! :D |
Anyone got any idea of how to group these windows together? Like the "tile" action of the window or sth...I really want to group the 6 windows...at least closer I mean...it's really ugly and messy to have 6 console windows spreading all over the screen.... :(
Thanz really!! :D |
Have you ever thouhgt about a MDI-Application?
|
MDI? Yes that's what I thought of that before. All I wanted to do yesterday was to make MDI. Actually I have already created 6 child windows, just that I dunno how to make the outputs and inputs of the C programs to link with the child window's screens.
Do you have any idea on this? Thanz!! :D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz