Processing the 'X' button in a SDI
-
Hello, I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed. In a Dialog box we process the
WM_CLOSE
message. Please can you tell me how to do it in a SDI document? Thanks._
Fortitudine Vincimus!_
Process the WM_SYSCOMMAND[^] notification; look for
wParam
set toSC_CLOSE
.
Software Zen:
delete this;
-
Process the WM_SYSCOMMAND[^] notification; look for
wParam
set toSC_CLOSE
.
Software Zen:
delete this;
-
Thank you for your reply. I tried to process the WM_SYSCOMMAND in MyAppDoc.cpp and then in MyAppView.cpp, but it is not working. The command is not even listed in the class wizard. What do i do?
_
Fortitudine Vincimus!_
You'll need to add an
OnSysCommand()
[^] handler to your view class, and look for thenID
value to be set toSC_CLOSE
. If you're writing an SDI application, you can also process this command in yourCFrameWnd
-derived[^] class.
Software Zen:
delete this;
-
You'll need to add an
OnSysCommand()
[^] handler to your view class, and look for thenID
value to be set toSC_CLOSE
. If you're writing an SDI application, you can also process this command in yourCFrameWnd
-derived[^] class.
Software Zen:
delete this;
-
The view is a CFormView. Would that be any problem. I added OnSysCommand() in my CFomView class. I put a message box there. But it seems like the control just does not go there. Sigh!!
_
Fortitudine Vincimus!_
The 'X' button is on the frame window not the form window. Try handling it in the frame window class instead. Mark
-
The 'X' button is on the frame window not the form window. Try handling it in the frame window class instead. Mark
I added the
WM_CLOSE
command in my MainFrame class. But now the problem is that I am not able to retrive data from the input boxes of myCMyFormView.
The program Asserts whenGetWindowText
is called.void CMainFrame::OnClose()
{
CMyFormView pFV;
pFV.OnAppExit();
// the function OnAppExit in the CFormView derived class, CMyFormView
// has the codes for taking and saving in data form many input boxes using GetWindowText
// the program Asserts when GetWindowText is called in CMyFormView
CFrameWnd::OnClose();
}_
Fortitudine Vincimus!_
-
I added the
WM_CLOSE
command in my MainFrame class. But now the problem is that I am not able to retrive data from the input boxes of myCMyFormView.
The program Asserts whenGetWindowText
is called.void CMainFrame::OnClose()
{
CMyFormView pFV;
pFV.OnAppExit();
// the function OnAppExit in the CFormView derived class, CMyFormView
// has the codes for taking and saving in data form many input boxes using GetWindowText
// the program Asserts when GetWindowText is called in CMyFormView
CFrameWnd::OnClose();
}_
Fortitudine Vincimus!_
How about this...
void CMainFrame::OnClose()
{
CMyFormView *pFV = (CMyFormView *)GetActiveView();
pFV->OnAppExit();
CFrameWnd::OnClose();
} -
How about this...
void CMainFrame::OnClose()
{
CMyFormView *pFV = (CMyFormView *)GetActiveView();
pFV->OnAppExit();
CFrameWnd::OnClose();
} -
Hello, I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed. In a Dialog box we process the
WM_CLOSE
message. Please can you tell me how to do it in a SDI document? Thanks._
Fortitudine Vincimus!_
Tara14 wrote:
I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed.
What's wrong with the app's
ExitInstance()
method? You could also handle it in the frame'sDestroyWindow()
method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Tara14 wrote:
I have created a SDI with CFormView as the view (VC++6). I would like to add some code to do something when the 'X' button of the document is pressed.
What's wrong with the app's
ExitInstance()
method? You could also handle it in the frame'sDestroyWindow()
method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
DavidCrow wrote:
What's wrong with the app's ExitInstance() method?
Dont know about that.
DavidCrow wrote:
You could also handle it in the frame's DestroyWindow() method.
The problem with DestroyWindow is that it closes off the application. I put a MessageBox there and checked how it worked. The application closes and then the MessageBox is displayed. Whereas I need to give the user some choises before the application closes.
_
Fortitudine Vincimus!_
-
Yipee!! It worked!! Thanks a billion!! GetActiveView() - so thats the way. Create an object of the view and then set the focus on it. Thank you once again.
_
Fortitudine Vincimus!_
Tara14 wrote:
Yipee!! It worked!! Thanks a billion!!
Cool! :)
Tara14 wrote:
GetActiveView() - so thats the way. Create an object of the view and then set the focus on it.
The view object already existed. You just needed a pointer to the one in existence, not a new object. The assertion was from the uncreated new object (no HWNDs). Glad it's working! Mark
-
Yipee!! It worked!! Thanks a billion!! GetActiveView() - so thats the way. Create an object of the view and then set the focus on it. Thank you once again.
_
Fortitudine Vincimus!_
By the way, if you want to give the user choices before closing then give the user the choices BEFORE calling CFrameWnd::OnClose(). Only call the base class if the user chooses to exit the app. If the user cancels or chooses to continue, just return from your OnClose() method. Mark
-
By the way, if you want to give the user choices before closing then give the user the choices BEFORE calling CFrameWnd::OnClose(). Only call the base class if the user chooses to exit the app. If the user cancels or chooses to continue, just return from your OnClose() method. Mark