Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to identify that an MFC application is starting by PC rebooting or by user click on application shortcut?

Tags:

c++

windows

mfc

I have an MFC application. This application run with PC rebooting and obviously by user click on application icon. When user will click application icon application will launch It's a normal scenario. But if application run from PC rebooting, i want to minimize the application system tray. System has been implemented but i don't know the way to detect whether application is launched by PC or User click. Is there any way to detect these scenarios in MFC application?

Every help is highly appreciable. Thank you.

///////////////////////////////////////////////////////////////////////////////

Update: Hello Mr. @michael-chourdakis thank you so much for your valuable suggestion. I'm updating my solution below. Someone may get help from this.

Command Line parameter value has been set as "autorun" and registered this value with my application name in the registry like below:

CString strFilePath = ApplicationFilePath + _T(" ") + _T("--autorun");

Here below is the commandline parameter getting process from MFC application InitInstance:

CString strAutoRun = _T("");

if(AfxGetApp()->m_lpCmdLine != NULL && AfxGetApp()->m_lpCmdLine[0] == _T('\0'))
{
     strAutoRun = AfxGetApp()->m_lpCmdLine;
}

if(strAutoRun.CompareNoCase(_T("--autorun")) == 0)
{
    // Application start from PC Rebooting....  
}
like image 669
yeasir007 Avatar asked Sep 12 '25 13:09

yeasir007


1 Answers

When registering the application to run on login (via registry, explorer startup or any other method you may have used), pass a command line parameter to indicate startup by that way.

And on app's startup, check if that parameter was used.

You may want to pass an extreme value so no one accidentally starts your app in that mode, for example, a CLSID.

like image 92
Michael Chourdakis Avatar answered Sep 14 '25 04:09

Michael Chourdakis