Solved

Quiting an app from a CFormView button

Posted on 1998-06-15
8
293 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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
 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 110
only14 challenge 19 81
Fibonacci challenge 11 133
Problem to App source 6 73
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

828 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