简体   繁体   中英

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

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....  
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM