Hi folks, I am looking to restart my application, is this possible?
What I mean is this; I have a check happening in main() and when that is false a "pin" window is opened. When a pin number is entered then I would like to restart the application. I just don't know how and I can't seem to find any resource here on that topic either.
Many thanks
Restarting the application? Topic is solved
-
- Knows some wx things
- Posts: 42
- Joined: Wed Apr 22, 2015 5:42 pm
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: Restarting the application?
Hello, To achieve this (auto-restart), you can create a launcher beside your main app. The main app calls the launcher and exits itself. The only goal of the launcher is to start the main app.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
-
- Knows some wx things
- Posts: 42
- Joined: Wed Apr 22, 2015 5:42 pm
Re: Restarting the application?
I'm not sure what you mean, a launcher? Is there an example? Many thanks
Re: Restarting the application?
Hi,
What eranon means is that you should have a shell script which have just one line in it.
Thank you.
What eranon means is that you should have a shell script which have just one line in it.
Thank you.
-
- Knows some wx things
- Posts: 42
- Joined: Wed Apr 22, 2015 5:42 pm
Re: Restarting the application?
I really appreciate the help guys but I am a little lost as to what you are both recommending
Shell script? Launcher? Excuse my ignorance folks.
Shell script? Launcher? Excuse my ignorance folks.
Re: Restarting the application?
It is all the same.
Thank you.
Thank you.
Re: Restarting the application?
With "launcher" Eranon meant a small program that starts the main application.
However, you can also just start the same executable again and then terminate the old one. That means that for a short period of time, two instances of your program will be running. Therefore you should perform the restart only after you have closed all files etc. so that there are no conflicts.
I'm adding a modified version of the "minimal" sample that shows how to do it.
However, you can also just start the same executable again and then terminate the old one. That means that for a short period of time, two instances of your program will be running. Therefore you should perform the restart only after you have closed all files etc. so that there are no conflicts.
I'm adding a modified version of the "minimal" sample that shows how to do it.
- Attachments
-
- minimal.cpp
- (7.3 KiB) Downloaded 218 times
Use the source, Luke!
- eranon
- Can't get richer than this
- Posts: 867
- Joined: Sun May 13, 2012 11:42 pm
- Location: France
- Contact:
Re: Restarting the application?
Yep, I meant as ONEEYEMAN and doublemax said... Through a shell script or a compiled executable, no matter.
Here a quick example (here, the app generates its launcher on fly -- not optimized, just for the concept):
Otherwise, the doublemax's solution may be easier; depends on your app constraints (if it allows several instances, mainly).
Here a quick example (here, the app generates its launcher on fly -- not optimized, just for the concept):
Code: Select all
#include "wx/wx.h"
#include <wx/stdpaths.h>
#include <wx/filename.h>
#include <wx/textfile.h>
static const long ID_GO = wxNewId();
class MinDialog : public wxDialog
{
public:
MinDialog() : wxDialog(NULL, wxID_ANY, wxString("Minimal Dialog"),
wxDefaultPosition, wxSize(300, 300)){
wxButton* btn = new wxButton(this, ID_GO, "RESTART");
wxBoxSizer* szr = new wxBoxSizer(wxVERTICAL);
szr->Add(btn, 1, wxEXPAND);
this->SetSizer(szr);
Connect(ID_GO, wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&MinDialog::OnGo);};
private:
void OnGo(wxCommandEvent& WXUNUSED(event))
{
// Example of auto-restart
// NB: w/o error handling and any precaution (e.g. batch filename could be unavail, console should be hidden, antivirus may hurt, etc.)
wxString strLauncher = wxFileName::GetTempDir() + "/mindlg_launcher.bat";
wxTextFile f(strLauncher);
f.Create();
f.AddLine("timeout 2 /nobreak > nul");
f.AddLine(wxString::Format("start %s", wxStandardPaths::Get().GetExecutablePath()));
f.AddLine("exit");
f.Write();
f.Close();
if (wxExecute(strLauncher, wxEXEC_ASYNC) > 0) Close(true);
};
};
class MinApp : public wxApp{
bool OnInit(){
MinDialog dlg;
dlg.ShowModal();
return false;};};
DECLARE_APP(MinApp)
IMPLEMENT_APP(MinApp)
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
-
- Knows some wx things
- Posts: 42
- Joined: Wed Apr 22, 2015 5:42 pm
Re: Restarting the application?
Thanks loads for the solution! The file doublemax attached is perfect, although the other solution works too doublemax's fits perfectly and I understand it.
Thanks folks
Thanks folks