BUG: CFormView Loses the Control's Focus When Restored (224928)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Professional Edition 4.0
- Microsoft Visual C++, 32-bit Professional Edition 4.1
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++ .NET (2002)
This article was previously published under Q224928 SYMPTOMS If you set the focus to one control of CFormView, minimize
the frame window of CFormView, and then restore it, the focus isn't set back to
the control that previously held the focus. CAUSE The handle of the control that had the focus when the frame
window was minimized, isn't stored. RESOLUTION To save the handle of the control that has the focus when
you minimize the view, do the following: - Define a message called WM_SAVEFOCUS in the Resource.h
file:
#define WM_SAVEFOCUS WM_APP+1
- Add a message handler for this user-defined message. In the
class definition of your CMyFormView class, add:
afx_msg LRESULT OnSaveFocus(WPARAM wParam, LPARAM lParam);
In the .cpp file of CMyFormView, add the message map macro:
ON_MESSAGE(WM_SAVEFOCUS, OnSaveFocus)
Add the handler function:
LRESULT CMyFormView::OnSaveFocus(WPARAM wParam, LPARAM lParam)
{
CFormView::SaveFocusControl();
return (LRESULT)0;
}
- In the class definition of CMainFrame, add:
afx_msg void OnSysCommand( UINT nID, LPARAM lParam );
In the .cpp file, add the OnSysCommand message map macro:
ON_WM_SYSCOMMAND()
Override OnSysCommand of the frame window class that you are using for
the formview, and send the WM_SAVEFOCUS message when it is about to minimize.
The code should resemble the following:
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xfff0) == SC_MINIMIZE)
GetActiveView()->SendMessage(WM_SAVEFOCUS);
CFrameWnd::OnSysCommand(nID,lParam);
}
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
REFERENCES (c) Microsoft Corporation 1999, All Rights Reserved.
Contributions by Yana Wang, Microsoft Corporation.
Modification Type: | Major | Last Reviewed: | 9/12/2003 |
---|
Keywords: | kbBug kbCtrl kbpending KB224928 |
---|
|