|
Thank you for taking the time to respond.
Actually I have never had another version of VS installed on this computer.
|
|
|
|
|
Hi, I'm messing with some custom tooltips. Here's the situation:
In my application I'm showing certain items in a list ctrl. There's a note column and a (jpeg) preview column. Both should display tooltips. My idea was to override a CToolTipCtrl and the WM_PAINT message for that control. Then in OnToolHitTest I would test whether the mouse is hovering over a note or preview and it would fill the members (a jpeg image or string, depending on what I'm pointing at) and use either of these in the WM_PAINT handler.
Now, once I hovered over an existing note, the tooltip keeps displaying (I set it to trigger for the whole client rect), even though I keep returning -1 from OnToolHitTest. So I'm not really sure what I'm missing here, it does work for the first time though. But once a tooltip has been displayed, it's pretty much broken.
|
|
|
|
|
Why is it that I can't get this window to call OnSysCommand when the user clicks on the Close [X] button. Is there something wrong with my code that someone can point out or am I leaving something out? Thanks!
/*************************************/
CClass1.h
class CClass1: public CFormView
{
....code.....
protected:
// Generated message map functions
//{{AFX_MSG(Class1)
afx_msg void OnSysCommand(UINT nID,LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CClass1.cpp
BEGIN_MESSAGE_MAP(CClass1, CFormView)
//{{AFX_MSG_MAP(CClass1)
ON_WM_SYSCOMMAND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CClass1::OnSysCommand(UINT nID, LPARAM lParam)
{
if(nID == SC_CLOSE) //Check If [X] Button
{
AfxMessageBox(_T("Hello"));
}
else
CFormView::OnSysCommand(nID, lParam);
}
|
|
|
|
|
From memory OnSysCommand() is called for items selected on the System Menu, not for the [x] Close button. Use WM_CLOSE (OnClose?) for that.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I used Class Wizard to insert an On_WM_CLOSE OnClose() function but it doesn't call it at all when I click on [X]. Anything else I'm missing?
void CClass1::OnClose()
{
//perform actions before closing
CFormView::OnClose();
}
|
|
|
|
|
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.
|
|
|
|