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. how to let CEdit SetFocus in a simple SDI program

how to let CEdit SetFocus in a simple SDI program

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorial
15 Posts 5 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.
  • U uday kiran janaswamy

    use SetFocus(...) Good Luck. Uday kiran

    I Offline
    I Offline
    ikohl
    wrote on last edited by
    #5

    it's complex, only use SetFocus can't succeed

    1 Reply Last reply
    0
    • I ikohl

      tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #6

      Call it immediatly before exiting your OnInit function. If that doesn't work look through your code for any other instances of SetFocus, maybe you are setting it but it is later being stolen.

      1 Reply Last reply
      0
      • I ikohl

        tried this method several times at many different places, such as when created, when updated, or in InitInstance, can't success. don't know what's the problem

        P Offline
        P Offline
        prasad_som
        wrote on last edited by
        #7

        On way is using CEdit::Setfocus in overridden OnActivateView()

        Prasad Notifier using ATL

        I 2 Replies Last reply
        0
        • P prasad_som

          On way is using CEdit::Setfocus in overridden OnActivateView()

          Prasad Notifier using ATL

          I Offline
          I Offline
          ikohl
          wrote on last edited by
          #8

          ok, thanks, let me try

          1 Reply Last reply
          0
          • P prasad_som

            On way is using CEdit::Setfocus in overridden OnActivateView()

            Prasad Notifier using ATL

            I Offline
            I Offline
            ikohl
            wrote on last edited by
            #9

            I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.

            P I 2 Replies Last reply
            0
            • I ikohl

              I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #10

              its failing ? Is it giving some ASSERT or just not doing what its intended to do? Have you suppressed its base class call ? You need to do that. It would just look like this,

              void CSDIView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
              {
              m_edtContent.SetFocus();//later you can customize this to set foucs as your need
              }

              Prasad Notifier using ATL

              1 Reply Last reply
              0
              • I ikohl

                I don't know what's the reason, but i called m_edtContent.SetFocus in my overridden OnActivateView(), are you OK in your side, thanks for your help.

                I Offline
                I Offline
                ikohl
                wrote on last edited by
                #11

                yes, really thanks for your help, it succeeds when i call like "CView::OnActivateView(bActivate, pActivateView, pDeactiveView); m_edtContent.SetFocus();" but not if i call like" m_edtContent.SetFocus(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); ". it's really very good, but after i quit the program, it will say "The exception Breakpoint, A breakpoint has been reached."

                P 1 Reply Last reply
                0
                • I ikohl

                  yes, really thanks for your help, it succeeds when i call like "CView::OnActivateView(bActivate, pActivateView, pDeactiveView); m_edtContent.SetFocus();" but not if i call like" m_edtContent.SetFocus(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); ". it's really very good, but after i quit the program, it will say "The exception Breakpoint, A breakpoint has been reached."

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #12

                  ikohl wrote:

                  CView::OnActivateView(bActivate, pActivateView, pDeactiveView);

                  tries to set foucs on view itself. In your case its not needed.

                  Prasad Notifier using ATL

                  I 1 Reply Last reply
                  0
                  • P prasad_som

                    ikohl wrote:

                    CView::OnActivateView(bActivate, pActivateView, pDeactiveView);

                    tries to set foucs on view itself. In your case its not needed.

                    Prasad Notifier using ATL

                    I Offline
                    I Offline
                    ikohl
                    wrote on last edited by
                    #13

                    yes, it's ok in sdi program, except for can't focus previous program when this program quits. but for mdi program, there's an error box will jump out when quit this program. really thanks for your help, you're a kind man.

                    P 1 Reply Last reply
                    0
                    • I ikohl

                      yes, it's ok in sdi program, except for can't focus previous program when this program quits. but for mdi program, there's an error box will jump out when quit this program. really thanks for your help, you're a kind man.

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #14

                      Actually, problem was you can't use SetFocus unless that window ,parent window is visible. OnActivateView is one place where you can achieve this. You can use its parameters for certain checks. Other place I feel is overriding WM_SHOWWINDOW, but it will get called once. You can look for such messages and use SetFocus there.

                      Prasad Notifier using ATL

                      I 1 Reply Last reply
                      0
                      • P prasad_som

                        Actually, problem was you can't use SetFocus unless that window ,parent window is visible. OnActivateView is one place where you can achieve this. You can use its parameters for certain checks. Other place I feel is overriding WM_SHOWWINDOW, but it will get called once. You can look for such messages and use SetFocus there.

                        Prasad Notifier using ATL

                        I Offline
                        I Offline
                        ikohl
                        wrote on last edited by
                        #15

                        ok, i will review it, really thanks for your help

                        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