Custom CEdit looses focus when editing CTreeView/CTreeCtrl - Programmer

This is a discussion on Custom CEdit looses focus when editing CTreeView/CTreeCtrl - Programmer ; Hello MFC experts! I am running into the following problem: (I am novice MFC programmer) I've got MyTreeView class derived from CTreeView and I am creating my CustomCEdit control to edit items of the tree. However, my CustomCEdit obtains the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Custom CEdit looses focus when editing CTreeView/CTreeCtrl

  1. Custom CEdit looses focus when editing CTreeView/CTreeCtrl

    Hello MFC experts!

    I am running into the following problem: (I am novice MFC programmer)

    I've got MyTreeView class derived from CTreeView and I am creating my
    CustomCEdit control to edit items of the tree. However, my CustomCEdit
    obtains the focus and immediately looses it and the focus gets back to
    the tree control.

    What should I do to make it to work correctly?

    Here are some sections of my code:

    void tTreeView::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
    {
    // TODO: Add your control notification handler code here

    < some code here >

    DWORD dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE |
    ES_AUTOHSCROLL|ES_LEFT;
    CEdit *pEdit = new CTreeEditCtrl(pINodeItem, this);
    pEdit->Create(dwStyle, rcItem, this, 0x1233);

    //I've also tried adding the following code to the end of the above
    method,
    //but it did not help. (I made quite a few attempts to do it because I
    saw a message in the newsgroup advising to do this but with no luck.)

    #if 0
    PostMessage(
    WM_NEXTDLGCTL, // message
    (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    TRUE // Set true to use previous parameter
    );
    #endif

    ::PostMessage(GetSafeHwnd(),
    WM_HELP, 0, 0);
    // WM_SETFOCUS, // message
    // (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    // TRUE // Set true to use previous parameter
    // );
    #if 0
    PostMessage(
    // pEdit->GetSafeHwnd(),
    0x123152,
    (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    TRUE // Set true to use previous parameter
    );
    #endif
    }

    Thank you in advance,

    Gregory

  2. Re: Custom CEdit looses focus when editing CTreeView/CTreeCtrl

    try to "steal" focus back if the edit control is transfering focus to the
    treectrl.
    1 Handle WM_KILLFOCUS
    2 check if the new focus is the treectrl
    3 if 2,call SetFocus to set focus back.

    "gregory" дʼ
    news:a7a6733e.0408070924.129cf9f9@posting.google.c om...
    > Hello MFC experts!
    >
    > I am running into the following problem: (I am novice MFC programmer)
    >
    > I've got MyTreeView class derived from CTreeView and I am creating my
    > CustomCEdit control to edit items of the tree. However, my CustomCEdit
    > obtains the focus and immediately looses it and the focus gets back to
    > the tree control.
    >
    > What should I do to make it to work correctly?
    >
    > Here are some sections of my code:
    >
    > void tTreeView::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
    > {
    > // TODO: Add your control notification handler code here
    >
    > < some code here >
    >
    > DWORD dwStyle = WS_BORDER | WS_CHILD | WS_VISIBLE |
    > ES_AUTOHSCROLL|ES_LEFT;
    > CEdit *pEdit = new CTreeEditCtrl(pINodeItem, this);
    > pEdit->Create(dwStyle, rcItem, this, 0x1233);
    >
    > //I've also tried adding the following code to the end of the above
    > method,
    > //but it did not help. (I made quite a few attempts to do it because I
    > saw a message in the newsgroup advising to do this but with no luck.)
    >
    > #if 0
    > PostMessage(
    > WM_NEXTDLGCTL, // message
    > (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    > TRUE // Set true to use previous parameter
    > );
    > #endif
    >
    > ::PostMessage(GetSafeHwnd(),
    > WM_HELP, 0, 0);
    > // WM_SETFOCUS, // message
    > // (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    > // TRUE // Set true to use previous parameter
    > // );
    > #if 0
    > PostMessage(
    > // pEdit->GetSafeHwnd(),
    > 0x123152,
    > (WPARAM)pEdit->GetSafeHwnd(), // control to receive focus
    > TRUE // Set true to use previous parameter
    > );
    > #endif
    > }
    >
    > Thank you in advance,
    >
    > Gregory




+ Reply to Thread