Solved

Quiting an app from a CFormView button

Posted on 1998-06-15
8
277 Views
Last Modified: 2013-11-20
I have a SDI app consisting of a CFormView main window...I added a button to exit the program, how do I get
the app to quit when I click on the button (i.e., I know that I need to close the main frame window...but what is
the best way to do this)?
0
Comment
Question by:veltkamp
8 Comments
 
LVL 2

Accepted Solution

by:
rayb earned 50 total points
ID: 1317976
Simply call the Win32 function: PostQuitMessage()
0
 

Author Comment

by:veltkamp
ID: 1317977
While the above response will work...I get the following trace dump:

SENDING command id 0x03FE to CConvView target
PumpMessage - Received WM_QUIT
Warning: destroying CSingleDocTemplate with live document
Detected memory leaks!
Dumping objects ->
{19} strcore1.cpp(82) : non-object block at $3DB70BA8, 6 bytes long
{17} plex.cpp(29) : non-object block at $3DB709DE, 128 bytes long
{16} strcore1.cpp(82) : non-object block at $3DB709B2, 11 bytes long
{15} strcore1.cpp(82) : non-object block at $3DB70988, 9 bytes long
{14} File Conversion Utility: File wincore.cpp, Line 475, Assertion Failed!
ASSERT_VALID fails with illegal pointer
: File , Line 15183

So I was actually looking for an approach that follows the MFC  framework exit procedure
0
 

Author Comment

by:veltkamp
ID: 1317978
While the above response will work...I get the following trace dump:

SENDING command id 0x03FE to CConvView target
PumpMessage - Received WM_QUIT
Warning: destroying CSingleDocTemplate with live document
Detected memory leaks!
Dumping objects ->
{19} strcore1.cpp(82) : non-object block at $3DB70BA8, 6 bytes long
{17} plex.cpp(29) : non-object block at $3DB709DE, 128 bytes long
{16} strcore1.cpp(82) : non-object block at $3DB709B2, 11 bytes long
{15} strcore1.cpp(82) : non-object block at $3DB70988, 9 bytes long
{14} File Conversion Utility: File wincore.cpp, Line 475, Assertion Failed!
ASSERT_VALID fails with illegal pointer
: File , Line 15183

So I was actually looking for an approach that follows the MFC  framework exit procedure
0
 

Expert Comment

by:engllf
ID: 1317979
The cleanest way is to set the button ID to ID_APP_EXIT.
It follows the framework exit procedure.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:engllf
ID: 1317980
If you use PostQuitMessage, it will exits the message loop immediately and there is no proper cleanup.
0
 

Expert Comment

by:kalaru
ID: 1317981
In u'r view source file , add the foll code
void CFormTestView::OnButton2()
{
      // TODO: Add your control notification handler code here

      AfxGetMainWnd()->SendMessage(WM_CLOSE);
      
}

Button2 is the button in u'r FormView , on pressing which, WM_CLOSE is sent to the MainFrame. This will close the Appln on clicking the button in a Formview.
And there're no memory leaks also.

Hope this helps u.
Hope this works.
0
 

Author Comment

by:veltkamp
ID: 1317982
I was going to give this a "C" untill the comment by kalaru was added...his response was to the point and complete, earlier responses by engllf were a little off-the-cuff and not as well thought out.  If I know how to give 100 "A" points to kalaru, I'd do it!!

Thaks for both your help on this simple question.
0
 

Author Comment

by:veltkamp
ID: 1317983
Sorry engllf...I ment my earlier comment to apply mostly to rayb (the original responder) but didn't scoll up far enough to see his name when composing my message.  BTY, setting the button ID to ID_APP_EXIT has no effect...presses on the button were not handled and there was no action.  But thanks for trying to help!!.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
WinWaitActive parameters 12 31
canBalance challenge 34 69
Excel file not created as expected 7 46
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now