SetFocus()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?am9zZXJhbW9uYnJhdm8=?=

    #1

    SetFocus()

    I use a CDialog with several controls and I want to set the focus in one of
    them , a CEdit, when an instance is created.
    The trouble is that I can get a pointer to the CEdit window, say p, but if I
    use the code
    p->SetFocus();
    then a warning about a fatal error " memory that can't be read " is issued
    and application is killed.
    I've tried the code in the constructor and after creation; both producing
    the same effect.
    Any help ?
  • Ismo Salonen

    #2
    Re: SetFocus()

    joseramonbravo wrote:
    I use a CDialog with several controls and I want to set the focus in one of
    them , a CEdit, when an instance is created.
    The trouble is that I can get a pointer to the CEdit window, say p, but if I
    use the code
    p->SetFocus();
    then a warning about a fatal error " memory that can't be read " is issued
    and application is killed.
    I've tried the code in the constructor and after creation; both producing
    the same effect.
    Any help ?
    The Ui for the control is valid only after CDialog::OnInit Dialog() call.

    Add your ui initialization stuff to the overridden method.


    ismo

    Comment

    • =?Utf-8?B?am9zZXJhbW9uYnJhdm8=?=

      #3
      Re: SetFocus()

      Thank you for you advice.
      Following your advice I coded:
      --------------------------------------------------
      BOOL CDialog_Newchat ::OnInitDialog( )
      {
      CDialog::OnInit Dialog();
      CEdit* p;
      p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
      p->SetCapture() ;
      .... etc
      ----------------------------------------
      and this solved the error but didn't bring the desired effect of putting
      next to come keyboard input into the CEdit control unless a left-mouse-click
      on any place of the window application was made.
      I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
      have worked.
      Any further help?
      José Ramón

      "Ismo Salonen" wrote:
      joseramonbravo wrote:
      I use a CDialog with several controls and I want to set the focus in one of
      them , a CEdit, when an instance is created.
      The trouble is that I can get a pointer to the CEdit window, say p, but if I
      use the code
      p->SetFocus();
      then a warning about a fatal error " memory that can't be read " is issued
      and application is killed.
      I've tried the code in the constructor and after creation; both producing
      the same effect.
      Any help ?
      >
      The Ui for the control is valid only after CDialog::OnInit Dialog() call.
      >
      Add your ui initialization stuff to the overridden method.
      >
      >
      ismo
      >

      Comment

      • Ben Voigt

        #4
        Re: SetFocus()


        "joseramonbravo " <joseramonbravo @discussions.mi crosoft.comwrot e in message
        news:72E322C2-A0E0-4342-A0CC-AC36C0C7AC65@mi crosoft.com...
        Thank you for you advice.
        Following your advice I coded:
        --------------------------------------------------
        BOOL CDialog_Newchat ::OnInitDialog( )
        {
        CDialog::OnInit Dialog();
        CEdit* p;
        p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
        p->SetCapture() ;
        ... etc
        ----------------------------------------
        and this solved the error but didn't bring the desired effect of putting
        next to come keyboard input into the CEdit control unless a
        left-mouse-click
        on any place of the window application was made.
        I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
        have worked.
        Any further help?
        SetCapture deals with the mouse, while SetFocus deals with the keyboard.

        The thing is that while the active application can give focus away to any
        window, no inactive application can steal the focus. This is very desirable
        behavior from a user's perspective. I hated what happened in previous
        versions of Windows: when I'm typing away in a window and some messagebox
        pops up, it would dissappear as soon as I hit the spacebar, before I even
        realized it was there. Also now when you try to activate your application,
        Windows flashes the taskbar instead, that's also to keep asynchronous
        notifications from disturbing work.

        You can hook keyboard input system-wide, it's just a lot more effort.

        But ask yourself, if your user is typing a Word document when the chat
        window appears and reaches the end of the line without noticing the new
        dialog, do you want those last few words+ENTER key to go to your dialog? Of
        course not. Even worse, what if they had just copied something large and
        embarassing, and now hit Ctrl+V, ENTER. That would be very bad for your
        program to intercept.


        Comment

        • =?Utf-8?B?am9zZXJhbW9uYnJhdm8=?=

          #5
          Re: SetFocus()

          Thanks. Your answer has helped me to "focus" the problem I was tampering with.

          "Ben Voigt" wrote:
          >
          "joseramonbravo " <joseramonbravo @discussions.mi crosoft.comwrot e in message
          news:72E322C2-A0E0-4342-A0CC-AC36C0C7AC65@mi crosoft.com...
          Thank you for you advice.
          Following your advice I coded:
          --------------------------------------------------
          BOOL CDialog_Newchat ::OnInitDialog( )
          {
          CDialog::OnInit Dialog();
          CEdit* p;
          p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
          p->SetCapture() ;
          ... etc
          ----------------------------------------
          and this solved the error but didn't bring the desired effect of putting
          next to come keyboard input into the CEdit control unless a
          left-mouse-click
          on any place of the window application was made.
          I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
          have worked.
          Any further help?
          >
          SetCapture deals with the mouse, while SetFocus deals with the keyboard.
          >
          The thing is that while the active application can give focus away to any
          window, no inactive application can steal the focus. This is very desirable
          behavior from a user's perspective. I hated what happened in previous
          versions of Windows: when I'm typing away in a window and some messagebox
          pops up, it would dissappear as soon as I hit the spacebar, before I even
          realized it was there. Also now when you try to activate your application,
          Windows flashes the taskbar instead, that's also to keep asynchronous
          notifications from disturbing work.
          >
          You can hook keyboard input system-wide, it's just a lot more effort.
          >
          But ask yourself, if your user is typing a Word document when the chat
          window appears and reaches the end of the line without noticing the new
          dialog, do you want those last few words+ENTER key to go to your dialog? Of
          course not. Even worse, what if they had just copied something large and
          embarassing, and now hit Ctrl+V, ENTER. That would be very bad for your
          program to intercept.
          >
          >
          >

          Comment

          Working...