Re: How to close app and reopen it again
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 08/25/04
- Next message: Scott McPhillips [MVP]: "Re: Display a CListCtrl in a CScrollView"
- Previous message: Joseph M. Newcomer: "Re: Message unknown: "Warning: initial dialog data is out of range.""
- In reply to: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Next in thread: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Reply: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 25 Aug 2004 18:30:25 -0400
No, I really mean the OnExitInstance of the app, since that is the override you would have
to write. You cannot write CWinThread::ExitInstance, because that function is already
defined by the MFC library.
atexit seems a quaint hangover from the days of the PDP-11. I generally try to ignore its
existence.
It is not clear why an intermediary process needs to be created to create a new instance,
as one reply suggested.
joe
On Wed, 25 Aug 2004 13:02:28 -0700, "Michael K. O'Neill"
<MikeAThon2000@nospam.hotmail.com> wrote:
>Rather than running the ShellExecute code in OnExitInstance (incidentally,
>do you mean "CWinThread::ExitInstance"?), it might be better to register a
>function that runs the code with the c-runtime using the atexit() function:
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_atexit.asp
>
>The advantage is that functions registered using atexit() are executed by
>the crt after the return from main()
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:rgcpi01s93cjpd94dktuoqic3g8vu7t003@4ax.com...
>> Sounds pretty easy.
>>
>> To close it, just
>> AfxGetMainWnd()->PostMessage(WM_CLOSE);
>>
>> and it closes. To re-run it, I'd suggest adding the following code to the
>OnExitInstance
>> handler:
>>
>> TCHAR exe[MAX_STRING];
>> ::GetModuleFileName(NULL, MAX_STRING, exe); // or some order of parameters
>>
>> ::ShellExecute(NULL , _T("open"), exe, NULL, NULL, SW_SHOWNORMAL);
>>
>> error checking is left as an Exercise For The Reader.
>> joe
>>
>> On Wed, 25 Aug 2004 12:05:52 +0200, "Janusz Grabis" <erfan@poczta.onet.pl>
>wrote:
>>
>> >Hello
>> >
>> >I need my application to close and reopen itself. Could you please direct
>me
>> >to any site/post describing such problem.
>> >
>> >Thanks
>> >Janusz
>> >
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Scott McPhillips [MVP]: "Re: Display a CListCtrl in a CScrollView"
- Previous message: Joseph M. Newcomer: "Re: Message unknown: "Warning: initial dialog data is out of range.""
- In reply to: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Next in thread: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Reply: Michael K. O'Neill: "Re: How to close app and reopen it again"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|