CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2020
    Posts
    1

    Caret not displayed in CEdit control with focus when dialog initially displayed

    I have a CDialog derived dialog which has a CFormView derived member which has a number of CEdit derived controls placed on it.

    Based on business rules at runtime one of the CEdit derived controls should receive the focus when the dialog is displayed. In the OnInitialUpdate override of the CFormView derived class (called from owning dialogs OnInitDialog method which returns FALSE to indicate that we have set the focus on a control) the specific control is determined and focus is set to that control with the following call:


    PostMessage(WM_NEXTDLGCTL, (WPARAM)pFocusEdit->GetSafeHwnd(), TRUE);


    When the dialog is displayed there is no caret displayed within the control. It is outlined in the blue colour showing that it has focus, if I start typing the text is displayed but still no caret. If I TAB to the next control the caret is displayed there and if I TAB back it is now displayed in the originally focused control.
    Alternatively, after the dialog is initially displayed and the caret is not showing If I shift the active window to another app (e.g. visual studio) and then actiavte the app again then the caret does appear in the CEdit control.

    Any suggestions as to how I can ensure that the desired CEdit control receives focus on display of the dialog and that the caret is displayed?

    Thanks,

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Caret not displayed in CEdit control with focus when dialog initially displayed

    It is not clear what is the dependency between CDialog and CFormView objects in your project.
    If I do something like
    Code:
    PostMessage(WM_NEXTDLGCTL, (WPARAM)pFocusEdit->GetSafeHwnd(), TRUE);
    in a simple CDialog derived class OnInitDialog then I get what you want.

    Could you post a small project reproducing your problem with caret?
    Victor Nijegorodov

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Caret not displayed in CEdit control with focus when dialog initially displayed

    Maybe it's just me, but a CDialog having a CFormView as a member seems kind of wonky to me. I don't know if it has anything to do with your problem though. Why did you set it up that way?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured