Announcement

Collapse
No announcement yet.

%WM_NCACTIVATE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %WM_NCACTIVATE

    The following has 'popped up' in the DDT code created by PBforms v1.5.
    Other than what Micro$oft has to say about it....
    what is it?
    what's it do?
    why is it important?

    Thanks.
    Code:
        Case %WM_NCACTIVATE
          Static hWndSaveFocus As DWord
          If IsFalse CbWParam Then
            ' Save control focus
            hWndSaveFocus = GetFocus()
          ElseIf hWndSaveFocus Then
            ' Restore control focus
            SetFocus(hWndSaveFocus)
            hWndSaveFocus = 0
          End If
    ------------------
    C'ya
    Don
    [email protected]
    C'ya
    Don

    http://www.ImagesBy.me

  • #2
    It serves to restore the focus after a change of application.


    ------------------

    Comment


    • #3
      Yes but what if the control is disabled on focus lost


      ------------------
      http://www.hellobasic.com
      Freeware and commercial tools for PowerBASIC
      hellobasic

      Comment


      • #4
        If you ASCII silly question, you get a silly ANSI:

        Edwin, the obvious answer is that you just modify the template code to suit your needs. For example, you might explicitly store the handle of the control that you *want* to receive focus when the app reactivates.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Originally posted by JOSE ROCA:
          It serves to restore the focus after a change of application.



          Jose, I'm going to put you up for a job at Micro$oft!



          ------------------
          C'ya
          Don
          [email protected]
          C'ya
          Don

          http://www.ImagesBy.me

          Comment


          • #6
            > Jose, I'm going to put you up for a job at Micro$oft!

            Jose knows how to both read and write - IOW, MS will think he's over-qualified..


            ------------------
            http://www.tolkenxp.com/pb
            Download: incLean, PBcodec, custom controls and code, etc.
            Borje Hagsten - [email protected]

            Comment


            • #7
              I'm going to wait for the official 'public' announcement (I gather the version 1.5 is currently only offered to 1.0 users) along with the "what's new"... but I'lll probably take advantage of the 30-day money-back thing for this product.

              But.. are you saying PBForms 1.5 automatically generates that WM_NCACTIVATE code to store the 'last focused' control? Using a STATIC variable so it's not re-entrant?

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                re-entrant?

                Not really important if since the app will store the last used focus.
                And that's only one.

                What me a bit concerns is the handle itself, it can point to a wrong (destroyed or hidden) control.
                While it might be easy to use and quick solvation code it's not entirly ok.

                Imagne restoring forcus to form #2 using the same dialog proc (your request )


                ------------------
                http://www.hellobasic.com
                Freeware and commercial tools for PowerBASIC
                hellobasic

                Comment


                • #9
                  Originally posted by Borje Hagsten:
                  > Jose, I'm going to put you up for a job at Micro$oft!

                  Jose knows how to both read and write - IOW, MS will think he's over-qualified..


                  Code:
                    A helicopter was flying around above Seattle yesterday when an
                  electrical malfunction disabled all of the aircraft's electronic
                  navigation and communications equipment.  Due to the clouds and haze,
                  the pilot could not determine the helicopter's position and course to
                  steer to the airport.
                   
                    The pilot saw a tall building, flew toward it, circled, drew a
                  handwritten sign, and held it in the helicopter's window. The pilot's
                  sign said "WHERE AM I?" in large letters.
                   
                    People in the tall building quickly responded to the aircraft, drew
                  a large sign, and held it in a building window.  Their sign said "YOU
                  ARE IN A HELICOPTER."
                   
                    The pilot smiled, waved, looked at his map, determined the course to
                  steer to SEATAC airport, and landed safely.
                   
                    After they were on the ground, the co-pilot asked the pilot how the
                  "YOU ARE IN A HELICOPTER" sign helped determine their position.
                   
                     The pilot responded "I knew that had to be the MICROSOFT building
                  because, similar to their help-lines, they gave me a technically
                  correct but completely useless answer."


                  ------------------
                  C'ya
                  Don
                  [email protected]
                  C'ya
                  Don

                  http://www.ImagesBy.me

                  Comment


                  • #10


                    ------------------
                    http://www.tolkenxp.com/pb
                    Download: incLean, PBcodec, custom controls and code, etc.
                    Borje Hagsten - [email protected]

                    Comment


                    • #11
                      Don,

                      Sorry if you have find my reply useless, but there are pilots and pilots...

                      > what is it?

                      Some lines of code (technically correct but useless information, but if you ASCII silly question...)

                      > what's it do?

                      Saves the focus when the application is going to be deactivated and restores it when it is reactivated.

                      > why is it important?

                      If it is important or not depends on you. Is it important for you to
                      restore the focus to the control that had the focus before the application
                      was deactivated? Answer the question yourself.

                      BTW I already knew the joke.


                      ------------------

                      Comment


                      • #12
                        It serves to restore the focus after a change of application.
                        Well... not quite. That is the intent of the DDT code but using WM_NCACTIVATE
                        to save and restore the keyboard focus is not a very good choice in my opinion.
                        This message is too broad in scope and occurs too early in the chain of messages
                        related to keyboard focus. In an application with multiple open windows, this
                        message is received whenever a window is activated within the application or in
                        another process. This message may also be sent/posted by the programmer when
                        implementing certain types of interfaces.

                        1. As Edwin pointed out, the use of a static variable, means that this code cannot be
                        used with multiple instances of the same window class.

                        2. This code is not going to work with MDI for two reasons.
                        (i) The static variable.
                        (ii) WM_NCACTIVATE occurs too early.

                        3. The code will not work with the following interface.
                        (a) One main window
                        (b) Two or more modeless windows that are owned by the main window.
                        (c) When the user accesses a secondary window, the title bar of the main window
                        remains highlighted.
                        To implement this interface, the programmer has to send/post WM_NCACTIVATE to the
                        main window. This means that the focus code is in the wrong place doing something
                        you don't want your code doing - resetting the focus to the main window.


                        ------------------
                        Dominic Mitchell
                        Dominic Mitchell
                        Phoenix Visual Designer
                        http://www.phnxthunder.com

                        Comment


                        • #13
                          (ii) might be a good tip..

                          The window always have the focus on activate (afaik).
                          You can use WM_SETFOCUS and navigate to desired control.

                          Not to mention dialogs which *might* restore to first control available.
                          A side effect of dialogs (and avoidable by nature ).


                          ------------------
                          http://www.hellobasic.com
                          Freeware and commercial tools for PowerBASIC
                          hellobasic

                          Comment


                          • #14
                            I post a message instead of setting the focus in %WM_NCACTIVATE
                            Code:
                               CASE %WM_NCACTIVATE
                                 IF ISFALSE wParam THEN hFocus = GetFocus
                            
                               CASE %WM_SETFOCUS
                                 IF hFocus THEN
                                    PostMessage hWnd, %WM_USER + 999, hFocus, 0
                                    hFocus = 0
                               END IF
                            
                               CASE %WM_USER + 999
                                  IF ISTRUE wParam THEN SetFocus wParam

                            ------------------

                            Comment


                            • #15
                              Thank you, gentlemen. Your discussions have helped.

                              And, Jose, no harm intended with the joke, it just seemed
                              like a good place for it.


                              ------------------
                              C'ya
                              Don
                              [email protected]
                              C'ya
                              Don

                              http://www.ImagesBy.me

                              Comment

                              Working...
                              X