|
I have seen this type of problem.
If it is a Document.View app then look at CDocument::CanCloseFrame().
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
So I inserted the function into my code but nothing happens. It doesn't seem to call the function when [X] is clicked just like OnClose. What I am doing wrong?
BOOL CClass1::CanCloseFrame(CFrameWnd* pFrame)
{
...more code...
return TRUE;
}
|
|
|
|
|
Is CClass1 your CDocument class? ie. Is it derived from CDocument.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
|
And in your CClass1 it is virtual? ie.
virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
|
Time to hop into the Debugger and look at the code for the FrameWindow's OnClose() which calls this function. All should become clear then.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Do you mean the CMainFrame::OnClose() calls the document view's OnClose function? How does that work?
|
|
|
|
|
Look at the MFC Source code for CFrameWnd::OnClose(). ED tells me this is in WINFRM.CPP
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I created CanCloseFrame()in the document class. Within that function, how can I call the calling frame view's close function. For example, when I close CClass1 document view using [X], CanCloseFrame() from the document class is called. How do I know which frame or view called it so that I can call its corresponding OnClose function?
|
|
|
|
|
elephantstar wrote:
How do I know which frame or view called it so that I can call its corresponding OnClose function?
I don't think you can find this out. You need to go back and work out why the views OnClose() isn't being called. Again the MFC Source and VC++ Debugger are your friends here. Start by setting a breakpoint on CWnd::OnClose(), then CView::OnClose() etc.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I have both OnSysCommand and CanCloseFrame but none of them work. When the window is closed, it calls CanCloseFrame, CFrameWnd::OnClose, and then CDocument::OnCloseDocument. I've been using the debugger but it's not helping at the moment. I'm back where I started.
|
|
|
|
|
You could try using CMyView::OnNcLButtonDown() to work out if the close button is pressed or code like:
BOOL
CMyView::IsMouseOnCloseButton()
{
BOOL bStat = FALSE;
if ( IsWindowVisible() )
{
CWnd* pFrameWnd;
POINT point;
GetCursorPos( &point );
if ( ( pFrameWnd = WindowFromPoint( point ) )->IsChild( this ) )
{
UINT nHitPos = pFrameWnd->SendMessage( WM_NCHITTEST, 0, MAKELPARAM( point.x, point.y ) );
bStat = nHitPos == HTCLOSE;
}
}
return bStat;
}
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Handle WM_SYSCOMMAND for the FrameWindow(MainFrame or ChildFrame).
|
|
|
|
|
I tried that already when you had first suggested it but it doesn't work. I had the OnSysCommand() in both the CMainFrame and the document view class but it doesn't seem to call it.
By inserting CanCloseFrame() in the document class, the document view does call that function to determine if the view should be closed. My problem now lies in the many views that are attached to that document. How can I find out what the calling view was and from there, call its OnClose function that will perform some type of save before closing it.
|
|
|
|
|
One has to wonder why the "View" has data that needs to be saved. That's what the document is for.
If that is all you want to do then use CMyView::OnDestroy()
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I used the View to transfer data to and from a struct. This is how I was told to do it but is it bad programming?
|
|
|
|
|
If the data pertains only to the view, such as its size and position then that is ok. If it is related to the underlying document then it should be stored with the document. Can the document be used without this data is a reasonable question to ask.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
MSDN specifically states that OnSysCommand() is called when the user selects a command from the Control (i.e., System) menu, or when the user selects the Maximize or the Minimize button. No mention of the "X" (i.e., Close) button.
So, what is it that you are really wanting to do?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I want to ask the user if they would like to save changes when they click on Close [X]. How do I do that for formviews? There is CanCloseWindow() that gets called when you insert it into the document class. But if I do it that way, I can't figure out which view called it to perform the correct action for that specific view.
|
|
|
|
|
elephantstar wrote:
I want to ask the user if they would like to save changes when they click on Close [X]. How do I do that...
It's done automatically by the document, if you've taken the necessary steps. When the document is modidfied, you simply need to call SetModifiedFlag(TRUE) , and the document will prompt the user to save no matter how the application is shut down.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
hi. . . .
I have a problem in select() function. In the server, this is part of code that handle the setuation of data socket which is checked by select() fn. and it handle closing the client socket "GRACEFULLY OR NUT" so it continue to receive connect()fn. from the client "OR SO I WANT TO DO". but when I do that, the first time the client connect() and closesocket(), it work well. But in the second time the error ((10048: Only one usage of each socket address (protocol/network address/port) is normally permitted)) appeares in the client program. I did not know if the problem from server or the client. This error maybe mean that the socket was not removed from the socket table.
for(sockPos=socketArray.GetStartPosition(); sockPos!=NULL;)
{
socketArray.GetNextAssoc(sockPos,sockArrayKey,(void*&)clientConnection);//CMapStringtoPtr socketArray;
//this is the select(): select(10,&socketReadFD,NULL,&socketErrorFD,&selectTimeout);
//where socketReadFD and socketErrorFD are fd_set type
if(FD_ISSET(clientConnection,&socketReadFD))
{
iRet = recv(clientConnection,msgData,sizeof(msgData), 0);
if(iRet == SOCKET_ERROR)
errorMsgHandler(data->mainHandler, WSAGetLastError());
else if(iRet == 0)
{
//errorMsgHandler(data->mainHandler, WSAGetLastError());
FD_CLR(clientConnection,&mainReadFD);
iRet = closesocket(clientConnection);
if(iRet == SOCKET_ERROR)
errorMsgHandler(data->mainHandler, WSAGetLastError());
socketArray.RemoveKey(sockArrayKey);
}//if close socket from the client Gracefully
else if(iRet >0)
{
CString tmp;
tmp=sockArrayKey;
tmp+=": ";
tmp += msgData;
::PostMessage(data->mainHandler,WM_DATA_MSG,(WPARAM)AllocBuffer(tmp),(LPARAM)AllocBuffer(sockArrayKey));
memset(msgData,'\0',sizeof(msgData));
}//END RECV CONNECTION
}//if FD_ISSET socketReadFD
if(FD_ISSET(clientConnection,&socketErrorFD))
{
errorMsgHandler(data->mainHandler, WSAGetLastError());
FD_CLR(clientConnection,&mainReadFD);
closesocket(clientConnection);
socketArray.RemoveKey(sockArrayKey);
}//if FD_ISSET socketErrorFD
}//sockArray Loop
I wish you to help me in this complex setuation. . .
thanks. . . .
ABO OSAMA
|
|
|
|
|
Hi,
I have problems by adding a Com-Addin to Outlook.
I´m getting this error:
"MyPath" is not a valid Office Add-in
I´ve tried this Microsoft Link:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;235009
but it doesn´t help !
With some PC my Addin works fine, but from others I´ve this error !
(this tells me that my Addin is basically OK !)
What I can I do ?
Need help please !
Thanks a lot, John
|
|
|
|
|
Would it because your Addin only compatible to certain version of Outlook?
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I have two dialog windows A and B, each has its own toolbar and menubar, B is shown by calling B.DoModal() in A, if i click a menu item in B, it shall hide B and show A again, I used the ShowWindow(SW_HIDE), This is how B is shown after click a menu item in A
//phmd is a global variable defined for an instance of B
// TODO: Add your command handler code here
if (phmd.GetSafeHwnd()==NULL){
phmd.DoModal();
//phmd.SetNetwork(this);
}
else{
phmd.ShowWindow(SW_SHOWNORMAL);
}
then in window B, i call ShowWindow(SW_HIDE) when the menu item A is called.
it hides the window, but the menubar and toolbar is still there and window A is not active even though can display it.
Pls help on this. Thanks a lot!
|
|
|
|