SDI main frame and WM_ENDSESSION

Posted on 2004-10-10
Medium Priority
Last Modified: 2013-11-20
I added WM_ENDSESSION handler to CMainFrame class of SDI application:

void CMainFrame::OnEndSession(BOOL bEnding)

    if ( bEnding )
        Beep(300, 300);

When I reboot/log off while program is running, this function is not called. If I do the same in MDI application, it works - I hear beep. How can I handle computer shitdown/log off event in SDI application?
Question by:AlexFM
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 12272304
The reason seems to lie in the call to


because it does

// when Windows session ends, close all documents
void CFrameWnd::OnEndSession(BOOL bEnding)
    if (!bEnding)

    CWinApp* pApp = AfxGetApp();
    if (pApp != NULL && pApp->m_pMainWnd == this)
        AfxOleSetUserCtrl(TRUE);    // keeps from randomly shutting down

        // allow application to save settings, etc.

call ExitInstance() directly. You'll hear the beep if you call the base class' implementation after your code.


>>How can I handle computer shitdown/log off event in SDI application?

I *love* that typo, it made my day :o)
LVL 48

Author Comment

ID: 12305732
Thanks :-)

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question