Click here to Skip to main content
15,891,912 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I'm wondering how to handle an input focus event on a CView derived class before the event occurs. It's like calling a OnSettingFocus if such an event handler exists, and then cancel the input focus, to make my view never gaining the input focus (for some reasons).
NB: CWnd::EnableWindow(FALSE); wont work, because my view has a child view and the call of CWnd::EnableWindow(FALSE); will make the child view disabled also.
Help me please to do that :(
Posted
Updated 4-Apr-11 3:46am
v2

EnableWindow(0);

Thats easy. ;-)
 
Share this answer
 
Comments
Mr. Tomay 4-Apr-11 9:49am    
I have updated my question
mbue 4-Apr-11 9:54am    
What you want to do?
* The view should not gain the focus
* But the child can get input focus?
Is this correct?
Then call SetFocus(hChild) on CYourView::OnSettingFocus().
Regards.
Mr. Tomay 4-Apr-11 10:16am    
The problem is that it does'nt exist an OnSettingFocus event handler
mbue 4-Apr-11 10:32am    
CWnd::OnSetFocus or handle the message WM_SETFOCUS.
Regards.
Mr. Tomay 4-Apr-11 10:42am    
CWnd::OnSetFocus : The framework calls this member function after gaining the input focus. It's late here. I want to handle it before, and then cancel the operation. Is it possible ?
SQL
BEGIN_MESSAGE_MAP(CSomeRecordSetView, CFormView)
    ON_COMMAND(ID_RECORD_NEXT_MM, OnRecordNextMm)
 END_MESSAGE_MAP()


C#
void CSomeRecordSetView::OnRecordNextMm()
{
    if (m_CurrentRecord < m_NumRecords - 1)
    {
        // open set
        m_pSet->Open();

        // move to the incremented record
        m_pSet->Move(++m_CurrentRecord);

        // copy data from set to view
        DataExchange(m_pSet, TRUE);

        // cause re-draw
        UpdateData(FALSE);

        // close the set
        m_pSet->Close();

    }
}



DataExchange method (you have to write this) moves data from RecordSet to View (whan argument is TRUE) and vice versa (when argument is FALSE), e.g.

C#
void CSomeRecordSetView::DataExchange(CSomeRecordSet *pSet, BOOL Direction)
{
    if (Direction)
    {
        // copy from recordSet to view
        m_SomeData = m_pSet->m_SomeData;
    }
    else
    {
        // copy from dialog to recordset
        m_pSet->m_SomeData = m_SomeData;
    }
}



This, as far as I remember, replaces the default behaviour of RecordSet view Next button. Prev, First and Last are similar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900