Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Caret not displayed in CEdit control with focus when dialog initially displayed

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

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiobusinessquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 11065933
    wrote on last edited by
    #1

    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 the specfic 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,

    L 1 Reply Last reply
    0
    • M Member 11065933

      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 the specfic 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,

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should use the OnInitDialog method of CDialog Class | Microsoft Docs[^] to set the focus.

      M 1 Reply Last reply
      0
      • L Lost User

        You should use the OnInitDialog method of CDialog Class | Microsoft Docs[^] to set the focus.

        M Offline
        M Offline
        Member 11065933
        wrote on last edited by
        #3

        Richard MacCutchan wrote:

        You should use the OnInitDialog method of CDialog Class | Microsoft Docs[^] to set the focus.

        I stated that the focus edit is being set from the OnInitialUpdate override of the CFormView derived class, I should have clarified that this has been called from the CDialog OnInitDialog method via a call to

        SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);

        Also, the OnInitDialog method returns FALSE to indicate that I have set the focus to a control. .

        L 1 Reply Last reply
        0
        • M Member 11065933

          Richard MacCutchan wrote:

          You should use the OnInitDialog method of CDialog Class | Microsoft Docs[^] to set the focus.

          I stated that the focus edit is being set from the OnInitialUpdate override of the CFormView derived class, I should have clarified that this has been called from the CDialog OnInitDialog method via a call to

          SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);

          Also, the OnInitDialog method returns FALSE to indicate that I have set the focus to a control. .

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sorry, I cannot help further as I don't have MFC.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups