|
Wow, you make it so easy. It is exact what I need ... I thought it must be hard to do it!
By the way, is there any method to make the MS DOS stay (not disappear) but in MINIMIZE mode (stay in the task bar)?
Many thanks Steve, I am really appreciate it! :->
|
|
|
|
|
The easiest was would be to lanuch your application via a shortcut and set the details on the shortcut.
Steve
|
|
|
|
|
The application is minimized as you suggested, but the MS DOS Window disappears after 0.5 second following each command system("...");
- Is it very difficulty to have MS DOS Window stay? Because I need to verify what it shows after a command excecuting!
|
|
|
|
|
You could try something like this:
#include "StdAfx.h"
#include <process.h>
#include <conio.h>
int main()
{
system("echo Hello world!");
system("dir");
system("tree");
system("echo Press any key...");
getch();
return 0;
}
Steve
|
|
|
|
|
It is the same, I did try system("pause"); It is pause but the previous MS DOS Window still disappear! So it shows an empty MS DOS Window ... but it stay there until I press a key!
|
|
|
|
|
Can you describe your application a little. For example, is it a console application or a Win32 application?
Steve
|
|
|
|
|
It is a WIN32 MFC application
|
|
|
|
|
Try this:
#include "stdafx.h"
#include <process.h>
#include <conio.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
AllocConsole();
system("dir");
system("tree");
getch();
FreeConsole();
return 0;
}
Steve
|
|
|
|
|
Once again you save my day, it works perfectly!
Many thanks, I am really really appreciate it!
|
|
|
|
|
|
You can execute the command prompt using CreateProcess or ShellExecute and use the "/K" option in the command prompt's arguments.
|
|
|
|
|
I try
ShellExecute(this->m_hWnd,"dir/k", "","","", SW_SHOW ); <br />
it does not work!
Can you give a typical DOS command?
Thanks
|
|
|
|
|
Please stop saying DOS!
First, did you search for previous answers? It is nearly certain that this question has been asked and answered many times before.
When I said command shell, I meant command-interpreter.
Look at the documentation of the system function. It is useful because it describes how the filename of the "command-interpreter file" is determined. For NT type versions of Windows, the command-interpreter file is Cmd.exe. For 95 versions of Windows, the command-interpreter file is Command.com. Those names might change for future version so it is better to get the filename from the environment.
You need to execute the command-interpreter and pass the options and command on the command line. Note that this will create a new window for the command; if that is not what you need, then I am sorry for misleading you.
|
|
|
|
|
While you're correct you seem to be being a little pedantic; I think we both know what he meant by the question.
Steve
|
|
|
|
|
I did not know what was meant by the initial question and the answer could have depended on the difference.
People trying to help often waste their time answering a misunderstood question. People asking questions should try to be clear. In this situation, this person is not trying. It is now not important for this question, but this person will likely waste people's time in the future.
My guess is that this person is not using the best solution for their fundamental problem. They probably think that this solution is the easiest, but then they will need to enhance it some more and the final solution is likely to be more work than if they considered all their requirements initially and asked for solutions for all the requirements.
|
|
|
|
|
I understood what he meant. Sometimes people do be vague and it annoyes me, but in this instance I didn't have any problems.
Steve
|
|
|
|
|
I have not been very active in CodeProject, but in the CodeGuru forums I was the first to hit 10,000 posts and about 99% of them were efforts to help others. So I have seen quite a few vague questions and such. People often spend less time asking a question than we spend answering them. In this situation, my guess is that there are better answers if the person were to take the time to be clear about requirements.
|
|
|
|
|
I can't argue with you there.
Steve
|
|
|
|
|
I am a rank amateur fighting scope creep and finalizing (one can always hope!) a general educational program in MFC/C++ Document/View after years of "bang your head on the wall" programming. It is good to allow multiple instances of the program, and extensive testing using multiple instances has uncovered only one apparent issue - the ability of multiple instances of the program to open and edit the same file. When switching with Alt-Tab between two instances of the program with the same file open, it is possible to overwrite the file from either instance, resulting in the ability to lose work by overwriting with an earlier version.
How can I use a semaphore (or anything else) to prevent the user from opening a file that is already open, or at least give the user a warning on file open or save? I am having trouble understanding how to use the semaphore (or anything else) to lock the file when I open it or test to see if it is locked when I try to open it again because there just do not seem to be many examples out there due to the apparently prevalent desire to prevent multiple instances of an application.
Thanks in advance for your time and consideration.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
A named Mutex object would work if you want to synchronize access to the file at the thread level
across processes.
An easier method would be to open the file in a share mode that doesn't allow others to open the
file (or at least denies write access).
lctrncs wrote: a general educational program in MFC/C++ Document/View after years of "bang your head on the wall" programming.
Some would say with MFC Doc/View you can expect many more years of the same.
|
|
|
|
|
Mark Salsbery wrote: Some would say with MFC Doc/View you can expect many more years of the same.
As a biochemistry type, I find programming to be like an incredibly difficult puzzle. You can move the parts around and try them here and there, and eventually they fit. I am trying to learn what the parts are and how they fit together, but my numb biologist's brain may not be correctly configured for such endeavors.
Thank you for the nice clue.
Including a CreateFile function passing a dwSharedMode 0 in my OnOpenDocument allows me to open a file when I use the lpszPathName of OnOpenDocument as the first argument in the CreateFile function.
If I then try to open the file a second time using a different instance of my app, a "sharing violation" message appears.
If I try to save the first instance of the file using the first instance of my app, a First Chance Exception occurs that passes "access denied" back to the program.
I have tried various file attributes, but am probably doing something more basic wrong.
Any suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: If I try to save the first instance of the file using the first instance of my app, a First Chance Exception occurs that passes "access denied" back to the program.
How are you saving the file? Have you overridden OnSaveDocument() as well? If not, then you
should, and use CloseHandle() to close the file handle returned by CreateFile() in your
OnOpenDocument() override.
lctrncs wrote: As a biochemistry type, I find programming to be like an incredibly difficult puzzle. You can move the parts around and try them here and there, and eventually they fit. I am trying to learn what the parts are and how they fit together, but my numb biologist's brain may not be correctly configured for such endeavors.
Thanks for reminding me that questions can come from a different point of view. Apparently I'm
bitter about the Doc/View architecture. I used it for years with both Borland's OWL framework
and MFC (even had an article published on the subject). Because of the direction my user
interface code ended up going, Doc/View became more and more of a nuisance and at this point
I still have code using it a bit but not completeley. Some day I hope to have the time to remove
it. It's actually a great model and well implemented in MFC for RAD but I've found that extending
it gets complex unless one knows the MFC code intimately. I guess I have a love/hate relationship
with Doc/View. Way off topic, I know, but my comment in the first reply was really unnecessary
and you reminded me of that, so thanks
|
|
|
|
|
Thanks for another clue.
I added an OnSaveDocument by hand since the classwizard stopped allowing me to add new member functions a while back.
Sadly, overriding OnSaveDocument and using CloseHandle to close the file handle resulted in no change in the program's behavior (I did not check how a second instance of the application's attempt to open the file). I still receive the access denied messge in the primary program when I try to save. I defined a handle in the Doc.h file so both functions could see it. Since I do not understand how CreateFile is working in concert with OnOpen/SaveDocument (and have precious little time to learn) it is difficult for me to proceed.
I can probably release my new version as is with it's numerous cosmetic and operational improvements (you can see the current version at www.studypartnernow.com) and just warn users about this issue.
I hate to take your time. Any other suggestions?
Mark Salsbery wrote: Apparently I'm
bitter about the Doc/View architecture.
I used to be a Microsoft evangelist - until I worked on the launch of Windows 95 as a "Remote Service Engineer." Microsoft technology COULD have been mega cool, but it appears to me that at some point money became the primary motivation for operations, and everything has been downhill ever since on the technical side, especially in the absence of viable competition.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Oops - getting crispy in crunch mode.
I added and overrode (I think) an OnSaveDocument function, not an OnSaveFunction or OnSaveRecord.
Thanks for all your help.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
I'm trying to figure out where the access denied message would even come from. It's a message
box that pops up? Can you post the code for your CreateFile() call, especially all the
flag/security params you are passing?
Also, you're not calling the base class OnOpenDocument/OnSaveDocument I hope.
lctrncs wrote: I used to be a Microsoft evangelist
That always reminds me of "Cup-o-Joe", an evangelist on the worldwide live broadcast of the
rollout/introduction of Windows 95 (I think).
|
|
|
|