Click to See Complete Forum and Search --> : Running files/closing window
How would you run a file through C++ code? And after done loading a file, how do you close the window that C++ is using?
Is this even possible?
Vlatko
Oct 6th, 2000, 05:50 AM
I don't fully understand your question.What do you mean run a file.Do you mean opening a file with ShellEx API function or opening some text file or bitmap.You can close a window using the Destroy Window API.
DestroyWindow(hWnd)
Shell a program...and after, destroy the window that is being used (not the shelled program). Understand?
Vlatko
Oct 6th, 2000, 12:07 PM
Well in that case you call an app for example notepad.After this in your code put:
ShellExecute(NULL,"open","c:\\bootlog.txt",NULL,NULL,SW_SHOW);
DestroyWindow(handle of your app main wnd);
This way the shelled app will stay and your app (the app that shelled it) will close.
Is that for C++?
I know how to do it all in VB. But it is C++ that I am new to and want to know how.
Vlatko
Oct 6th, 2000, 06:59 PM
Yes it is for C++.You can get the HWND of your window using the FindWindow Function.
HWND handle = ::FindWindow(NULL,"TitleBarText");
ShellExecute(NULL,"open","c:\\bootlog.txt",NULL,NULL,SW_SHOW);
DestroyWindow(handle);
This will open Notepad and Close your app.If you know VB than you know how to use the ShellExecite in some other way.
Hmm...don't I have to state something else? Like #include <iostream.h> (which I don't believe contains the ShellExecute and FindWindow or DestroyWindow functions.) So what would I shall I do?
Vlatko
Oct 7th, 2000, 06:11 AM
No.The iostream.h is for input-output operations.The ShellExecute,FindWindow and Destroy Window are available without including header files,like almost all API functions.
What do you mean "what would i shell i do".
Shell the app you want to activate,or like in my example some file which will open in its default viewer.Then you destroy your window and everything is set.
Why don't you try the code.It works.
It won't work for me though. I am using Turbo C++, not VC++.
It keeps selecting:
ShellExecute(NULL,"open","c:\\bootlog.txt",NULL,NULL,SW_SHOW);
Error messge:
Warning NONAME00.CPP 1: Style of function definition is now obsolete
Error NONAME00.CPP 1: ) expected
Vlatko
Oct 7th, 2000, 10:37 AM
Oh,why didn't you say that you use Turbo C++.In that case i can't help you.I am also a begginer in C++.This code works for me in VC++ but in Turbo C++...???
I have Visual Studio Professional. I guess VC++ doesn't come with it. How much did you buy it for? I assume the price is high :(.
parksie
Oct 7th, 2000, 11:10 AM
VC is definitely in VS.
You don't need to use FindWindow to get the handle of your window - you get it when you create the window to start with:
HWND hWnd_Main = CreateWindowEx(...);
// or
HWND hWnd_Main = CreateDialog(...);
Are you still at school, Matthew? Because you can then get it on academic pricing.
I am still in high skool parksie :rolleyes:.
I did buy the Visual Studio Professional Edition 6.0 from someone on the Forums.
Doesn't seem to contain C++ though :(.
Vlatko
Oct 7th, 2000, 12:45 PM
VC++ comes with VS.I am sure about that.When you install VS choose VC++.
I bought the whole VS for 5$.You know , in my country prices are the same for everything.1$ for 1CD.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.