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?
Printable View
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?
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.
Code:DestroyWindow(hWnd)
Shell a program...and after, destroy the window that is being used (not the shelled program). Understand?
Well in that case you call an app for example notepad.After this in your code put:
This way the shelled app will stay and your app (the app that shelled it) will close.Code:ShellExecute(NULL,"open","c:\\bootlog.txt",NULL,NULL,SW_SHOW);
DestroyWindow(handle of your app main wnd);
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.
Yes it is for C++.You can get the HWND of your window using the FindWindow Function.
This will open Notepad and Close your app.If you know VB than you know how to use the ShellExecite in some other way.Code:HWND handle = ::FindWindow(NULL,"TitleBarText");
ShellExecute(NULL,"open","c:\\bootlog.txt",NULL,NULL,SW_SHOW);
DestroyWindow(handle);
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?
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
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 :(.
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:
Are you still at school, Matthew? Because you can then get it on academic pricing.Code:HWND hWnd_Main = CreateWindowEx(...);
// or
HWND hWnd_Main = CreateDialog(...);
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 :(.
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.