Loading ...
Sorry, an error occurred while loading the content.

Re: [libertybasic] Where is the focus?

Expand Messages
  • Stefan Pendl
    ... I envision a solution using the GetFocus API function with a TIMER. There are already some examples posted on the group on how to utilize the GetFocus API
    Message 1 of 11 , Jul 21, 2013
    • 0 Attachment
      Am 21.07.2013 04:46, schrieb Sarmed N.:
      >
      >
      >
      > Dear Stefan,
      >
      > Is there a treatment for the (BMP Buttons under
      > focus problem), the user cannot determine which button under focus when he use
      > Win7.
      > You know for who use the program 8 hours a day, it
      > is not easy to use the mouse, the right hand became heavy, he use the key
      > board, easier faster, and more reliable.
      > One of the solutions to me is to immigrate to LBB, I
      > prefer that LB will solve this problem.
      > I hope you'll find some solution!
      >

      I envision a solution using the GetFocus API function with a TIMER.

      There are already some examples posted on the group on how to utilize
      the GetFocus API function.

      Best would be to use indexed button handles, like #m.bmpButton1,
      #m.bmpButton2, etc.

      An array would be filled with the image names of the regular image and
      one that has a green border to indicate having focus:
      images(1,0) = "buttonOne"
      images(1,1) = "buttonOnefocus"

      GetFocus will check which button has focus and if it is a BMPbutton the
      image with the green border would be displayed.


      --
      Stefan Pendl
      http://stefanpendl.runbasichosting.com/

      LB 4.04 Pro ... http://www.libertybasic.com/assist.html
      LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

      LB Community Wiki .............. http://basic.wikispaces.com/
      LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
      LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

      Books at http://www.lulu.com/ and http://www.amazon.com/
      Alyce Watson ... APIs for Liberty BASIC
      Carl Gundel .... Beginning Programming with Liberty BASIC

      Windows 7 Home Premium 64-bit SP1
      AMD Turion X2 RM-70 2GHz, 4GB RAM
    • green8819
      If possible I prefer not using scan, inkey$, or timer because they keep CPU running until a keypress. How about: ----start code Question, thanks to Sarmed,
      Message 2 of 11 , Jul 21, 2013
      • 0 Attachment
        If possible I prefer not using scan, inkey$, or timer because they keep CPU running until a keypress.

        How about:

        '----start code
        'Question, thanks to Sarmed, 19July2013
        'Hint, thanks to Stefan, 21July2013
        'Original Demo, thanks to Janet, 31May2009
        'The following from Mike, 22July2013
        nomainwin
        WindowWidth = 200 :WindowHeight = 350
        UpperLeftX = 10 :UpperLeftY = 10
        '---------------------------------------------------
        textbox #w.tbx1, 20, 50, 100, 25
        textbox #w.tbx2, 20, 100, 100, 25
        button #w.btn1, "Calculate1", [Calc], UL, 20,150
        button #w.btn2, "Calculate2", [Calc], UL, 20,200
        statictext #w.msg, "",20, 250, 200, 40
        stylebits #w.entered, _BS_DEFPUSHBUTTON, 0, 0, 0
        button #w.entered, "", [Retrieve], UL, -100, 0
        '---------------------------------------------------
        open "Last Focus" for window_nf as #w
        #w "trapclose [quit]" :#w "font arial 10"
        'get handles
        htextbox1=hwnd(#w.tbx1)
        htextbox2=hwnd(#w.tbx2)
        hbutton1=hwnd(#w.btn1)
        hbutton2=hwnd(#w.btn2)
        wait
        '---------------------------------------------------
        [Calc]
        'gosub xxx
        goto [Retrieve]
        wait

        [Retrieve]
        tbx=0 :btn=0
        'Which control has focus?
        callDLL #user32,"GetFocus",Handle as uLong
        'Retrieve something from that control
        select case Handle
        case htextbox1
        tbx = 1
        case htextbox2
        tbx = 2
        case hbutton1
        btn = 1
        case hbutton2
        btn = 2
        end select

        if tbx then
        tbx$ = "#w.tbx";tbx
        #tbx$ "!Contents? var$"
        #w.msg "Last focus = ";right$(tbx$,4)+chr$(13)+_
        "Entry = "+var$
        end if
        if btn then
        btn$ = "#w.btn";btn
        #w.msg "Last focus = ";right$(btn$,4)
        end if
        #tbx$ ""
        wait

        [quit]
        close #w
        END
        '----end code


        --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@...> wrote:
        >
        > Am 21.07.2013 04:46, schrieb Sarmed N.:
        > >
        > >
        > >
        > > Dear Stefan,
        > >
        > > Is there a treatment for the (BMP Buttons under
        > > focus problem), the user cannot determine which button under focus when he use
        > > Win7.
        > > You know for who use the program 8 hours a day, it
        > > is not easy to use the mouse, the right hand became heavy, he use the key
        > > board, easier faster, and more reliable.
        > > One of the solutions to me is to immigrate to LBB, I
        > > prefer that LB will solve this problem.
        > > I hope you'll find some solution!
        > >
        >
        > I envision a solution using the GetFocus API function with a TIMER.
        >
        > There are already some examples posted on the group on how to utilize
        > the GetFocus API function.
        >
        > Best would be to use indexed button handles, like #m.bmpButton1,
        > #m.bmpButton2, etc.
        >
        > An array would be filled with the image names of the regular image and
        > one that has a green border to indicate having focus:
        > images(1,0) = "buttonOne"
        > images(1,1) = "buttonOnefocus"
        >
        > GetFocus will check which button has focus and if it is a BMPbutton the
        > image with the green border would be displayed.
        >
        >
        > --
        > Stefan Pendl
        > http://stefanpendl.runbasichosting.com/
        >
        > LB 4.04 Pro ... http://www.libertybasic.com/assist.html
        > LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe
        >
        > LB Community Wiki .............. http://basic.wikispaces.com/
        > LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
        > LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/
        >
        > Books at http://www.lulu.com/ and http://www.amazon.com/
        > Alyce Watson ... APIs for Liberty BASIC
        > Carl Gundel .... Beginning Programming with Liberty BASIC
        >
        > Windows 7 Home Premium 64-bit SP1
        > AMD Turion X2 RM-70 2GHz, 4GB RAM
        >
      • green8819
        A friend says: TIMER doesn t keep the CPU running, because it is used in conjunction with WAIT. You could get the timer to check the focus perhaps 20 times a
        Message 3 of 11 , Jul 22, 2013
        • 0 Attachment
          A friend says:

          "TIMER doesn't keep the CPU running, because it is used in conjunction with WAIT. You could get the timer to check the focus perhaps 20 times a second; that would use an immeasurably small amount of CPU time and is a simpler and safer method, I would say"

          And I would say:
          The CPU is doing 20 repetitive tasks every sec. Why burden it if preventable? Check only on demand? By the way, I kept Task Manager in view, while I conducted a test on the 'btnPressed.bas' which uses TIMER. CPU usage read zero. That probably means 'incredibly' negligible, not absolute zero.

          Thanks for the feedback.


          --- In libertybasic@yahoogroups.com, "green8819" <skynetmike@...> wrote:
          >
          > If possible I prefer not using scan, inkey$, or timer because they keep CPU running until a keypress.
          >
        • paradisejb
          Mike, when I run this code, the Handle I get from running callDLL #user32, GetFocus ,Handle as uLong in the [Retrieve] branch does not match any of the
          Message 4 of 11 , Jul 22, 2013
          • 0 Attachment
            Mike, when I run this code, the Handle I get from running
            "callDLL #user32,"GetFocus",Handle as uLong"
            in the [Retrieve] branch does not match any of the handles first obtained and assigned to the 4 variables right after the window is opened. As a result, no selection is matched in your select case routine, and no "Last focus..." is printed out. The program finishes at #tbx$ "" where I get a "Runtime Error: Invalid file handle #tbx".

            Do I have false expectations, or am I doing something wrong?

            Jack

            --- In libertybasic@yahoogroups.com, "green8819" <skynetmike@...> wrote:
            >
            > If possible I prefer not using scan, inkey$, or timer because they keep CPU running until a keypress.
            >
            > How about:
            >
            > '----start code
            > 'Question, thanks to Sarmed, 19July2013
            > 'Hint, thanks to Stefan, 21July2013
            > 'Original Demo, thanks to Janet, 31May2009
            > 'The following from Mike, 22July2013
            > nomainwin
            > WindowWidth = 200 :WindowHeight = 350
            > UpperLeftX = 10 :UpperLeftY = 10
            > '---------------------------------------------------
            > textbox #w.tbx1, 20, 50, 100, 25
            > textbox #w.tbx2, 20, 100, 100, 25
            > button #w.btn1, "Calculate1", [Calc], UL, 20,150
            > button #w.btn2, "Calculate2", [Calc], UL, 20,200
            > statictext #w.msg, "",20, 250, 200, 40
            > stylebits #w.entered, _BS_DEFPUSHBUTTON, 0, 0, 0
            > button #w.entered, "", [Retrieve], UL, -100, 0
            > '---------------------------------------------------
            > open "Last Focus" for window_nf as #w
            > #w "trapclose [quit]" :#w "font arial 10"
            > 'get handles
            > htextbox1=hwnd(#w.tbx1)
            > htextbox2=hwnd(#w.tbx2)
            > hbutton1=hwnd(#w.btn1)
            > hbutton2=hwnd(#w.btn2)
            > wait
            > '---------------------------------------------------
            > [Calc]
            > 'gosub xxx
            > goto [Retrieve]
            > wait
            >
            > [Retrieve]
            > tbx=0 :btn=0
            > 'Which control has focus?
            > callDLL #user32,"GetFocus",Handle as uLong
            > 'Retrieve something from that control
            > select case Handle
            > case htextbox1
            > tbx = 1
            > case htextbox2
            > tbx = 2
            > case hbutton1
            > btn = 1
            > case hbutton2
            > btn = 2
            > end select
            >
            > if tbx then
            > tbx$ = "#w.tbx";tbx
            > #tbx$ "!Contents? var$"
            > #w.msg "Last focus = ";right$(tbx$,4)+chr$(13)+_
            > "Entry = "+var$
            > end if
            > if btn then
            > btn$ = "#w.btn";btn
            > #w.msg "Last focus = ";right$(btn$,4)
            > end if
            > #tbx$ ""
            > wait
            >
            > [quit]
            > close #w
            > END
            > '----end code
            >
            >
            > --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@> wrote:
            > >
            > > Am 21.07.2013 04:46, schrieb Sarmed N.:
            > > >
            > > >
            > > >
            > > > Dear Stefan,
            > > >
            > > > Is there a treatment for the (BMP Buttons under
            > > > focus problem), the user cannot determine which button under focus when he use
            > > > Win7.
            > > > You know for who use the program 8 hours a day, it
            > > > is not easy to use the mouse, the right hand became heavy, he use the key
            > > > board, easier faster, and more reliable.
            > > > One of the solutions to me is to immigrate to LBB, I
            > > > prefer that LB will solve this problem.
            > > > I hope you'll find some solution!
            > > >
            > >
            > > I envision a solution using the GetFocus API function with a TIMER.
            > >
            > > There are already some examples posted on the group on how to utilize
            > > the GetFocus API function.
            > >
            > > Best would be to use indexed button handles, like #m.bmpButton1,
            > > #m.bmpButton2, etc.
            > >
            > > An array would be filled with the image names of the regular image and
            > > one that has a green border to indicate having focus:
            > > images(1,0) = "buttonOne"
            > > images(1,1) = "buttonOnefocus"
            > >
            > > GetFocus will check which button has focus and if it is a BMPbutton the
            > > image with the green border would be displayed.
            > >
            > >
            > > --
            > > Stefan Pendl
            > > http://stefanpendl.runbasichosting.com/
            > >
            > > LB 4.04 Pro ... http://www.libertybasic.com/assist.html
            > > LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe
            > >
            > > LB Community Wiki .............. http://basic.wikispaces.com/
            > > LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
            > > LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/
            > >
            > > Books at http://www.lulu.com/ and http://www.amazon.com/
            > > Alyce Watson ... APIs for Liberty BASIC
            > > Carl Gundel .... Beginning Programming with Liberty BASIC
            > >
            > > Windows 7 Home Premium 64-bit SP1
            > > AMD Turion X2 RM-70 2GHz, 4GB RAM
            > >
            >
          • green8819
            Hello Jack, What do we do after entering something in a textbox? We press [Enter]? Did you do that?
            Message 5 of 11 , Jul 22, 2013
            • 0 Attachment
              Hello Jack,

              What do we do after entering something in a textbox?
              We press [Enter]? Did you do that?

              --- In libertybasic@yahoogroups.com, "paradisejb" <jburman1860@...> wrote:
              >
              > Mike, when I run this code, the Handle I get from running
              > "callDLL #user32,"GetFocus",Handle as uLong"
              > in the [Retrieve] branch does not match any of the handles first obtained and assigned to the 4 variables right after the window is opened. As a result, no selection is matched in your select case routine, and no "Last focus..." is printed out. The program finishes at #tbx$ "" where I get a "Runtime Error: Invalid file handle #tbx".
              >
              > Do I have false expectations, or am I doing something wrong?
              >
              > Jack
              >
              > --- In libertybasic@yahoogroups.com, "green8819" <skynetmike@> wrote:
              > >
              > > If possible I prefer not using scan, inkey$, or timer because they keep CPU running until a keypress.
              > >
              > > How about:
              > >
              > > '----start code
              > > 'Question, thanks to Sarmed, 19July2013
              > > 'Hint, thanks to Stefan, 21July2013
              > > 'Original Demo, thanks to Janet, 31May2009
              > > 'The following from Mike, 22July2013
              > > nomainwin
              > > WindowWidth = 200 :WindowHeight = 350
              > > UpperLeftX = 10 :UpperLeftY = 10
              > > '---------------------------------------------------
              > > textbox #w.tbx1, 20, 50, 100, 25
              > > textbox #w.tbx2, 20, 100, 100, 25
              > > button #w.btn1, "Calculate1", [Calc], UL, 20,150
              > > button #w.btn2, "Calculate2", [Calc], UL, 20,200
              > > statictext #w.msg, "",20, 250, 200, 40
              > > stylebits #w.entered, _BS_DEFPUSHBUTTON, 0, 0, 0
              > > button #w.entered, "", [Retrieve], UL, -100, 0
              > > '---------------------------------------------------
              > > open "Last Focus" for window_nf as #w
              > > #w "trapclose [quit]" :#w "font arial 10"
              > > 'get handles
              > > htextbox1=hwnd(#w.tbx1)
              > > htextbox2=hwnd(#w.tbx2)
              > > hbutton1=hwnd(#w.btn1)
              > > hbutton2=hwnd(#w.btn2)
              > > wait
              > > '---------------------------------------------------
              > > [Calc]
              > > 'gosub xxx
              > > goto [Retrieve]
              > > wait
              > >
              > > [Retrieve]
              > > tbx=0 :btn=0
              > > 'Which control has focus?
              > > callDLL #user32,"GetFocus",Handle as uLong
              > > 'Retrieve something from that control
              > > select case Handle
              > > case htextbox1
              > > tbx = 1
              > > case htextbox2
              > > tbx = 2
              > > case hbutton1
              > > btn = 1
              > > case hbutton2
              > > btn = 2
              > > end select
              > >
              > > if tbx then
              > > tbx$ = "#w.tbx";tbx
              > > #tbx$ "!Contents? var$"
              > > #w.msg "Last focus = ";right$(tbx$,4)+chr$(13)+_
              > > "Entry = "+var$
              > > end if
              > > if btn then
              > > btn$ = "#w.btn";btn
              > > #w.msg "Last focus = ";right$(btn$,4)
              > > end if
              > > #tbx$ ""
              > > wait
              > >
              > > [quit]
              > > close #w
              > > END
              > > '----end code
              > >
              > >
              > > --- In libertybasic@yahoogroups.com, Stefan Pendl <pendl2megabit@> wrote:
              > > >
              > > > Am 21.07.2013 04:46, schrieb Sarmed N.:
              > > > >
              > > > >
              > > > >
              > > > > Dear Stefan,
              > > > >
              > > > > Is there a treatment for the (BMP Buttons under
              > > > > focus problem), the user cannot determine which button under focus when he use
              > > > > Win7.
              > > > > You know for who use the program 8 hours a day, it
              > > > > is not easy to use the mouse, the right hand became heavy, he use the key
              > > > > board, easier faster, and more reliable.
              > > > > One of the solutions to me is to immigrate to LBB, I
              > > > > prefer that LB will solve this problem.
              > > > > I hope you'll find some solution!
              > > > >
              > > >
              > > > I envision a solution using the GetFocus API function with a TIMER.
              > > >
              > > > There are already some examples posted on the group on how to utilize
              > > > the GetFocus API function.
              > > >
              > > > Best would be to use indexed button handles, like #m.bmpButton1,
              > > > #m.bmpButton2, etc.
              > > >
              > > > An array would be filled with the image names of the regular image and
              > > > one that has a green border to indicate having focus:
              > > > images(1,0) = "buttonOne"
              > > > images(1,1) = "buttonOnefocus"
              > > >
              > > > GetFocus will check which button has focus and if it is a BMPbutton the
              > > > image with the green border would be displayed.
              > > >
              > > >
              > > > --
              > > > Stefan Pendl
              > > > http://stefanpendl.runbasichosting.com/
              > > >
              > > > LB 4.04 Pro ... http://www.libertybasic.com/assist.html
              > > > LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe
              > > >
              > > > LB Community Wiki .............. http://basic.wikispaces.com/
              > > > LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
              > > > LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/
              > > >
              > > > Books at http://www.lulu.com/ and http://www.amazon.com/
              > > > Alyce Watson ... APIs for Liberty BASIC
              > > > Carl Gundel .... Beginning Programming with Liberty BASIC
              > > >
              > > > Windows 7 Home Premium 64-bit SP1
              > > > AMD Turion X2 RM-70 2GHz, 4GB RAM
              > > >
              > >
              >
            • Stefan Pendl
              ... I really doubt that any process will really use zero CPU cycles at all, since then it is hung. There is always some kind of heart beat that allows the CPU
              Message 6 of 11 , Jul 22, 2013
              • 0 Attachment
                Am 22.07.2013 12:09, schrieb green8819:
                >
                > And I would say:
                > The CPU is doing 20 repetitive tasks every sec. Why burden it if preventable? Check only on demand? By the way, I kept Task Manager in view, while I conducted a test on the 'btnPressed.bas' which uses TIMER. CPU usage read zero. That probably means 'incredibly' negligible, not absolute zero.
                >

                I really doubt that any process will really use zero CPU cycles at all,
                since then it is hung.

                There is always some kind of heart beat that allows the CPU to interact
                with the process.

                You can use the Sleep API function to suspend the process, but then you
                will miss some of the user events.

                If you want a process to react on user events, you need to use CPU
                cycles, even if they are minuscule.

                TIMER is not bad, nor is GOTO, they both have their use cases, but the
                developer has to make the right decision to use the right tool ;-)


                --
                Stefan Pendl
                http://stefanpendl.runbasichosting.com/

                LB 4.04 Pro ... http://www.libertybasic.com/assist.html
                LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                LB Community Wiki .............. http://basic.wikispaces.com/
                LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
                LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

                Books at http://www.lulu.com/ and http://www.amazon.com/
                Alyce Watson ... APIs for Liberty BASIC
                Carl Gundel .... Beginning Programming with Liberty BASIC

                Windows 7 Home Premium 64-bit SP1
                AMD Turion X2 RM-70 2GHz, 4GB RAM
              • Stefan Pendl
                ... I usually hit the OK button on the dialog or move on to the next entry box using the TAB key. I only use the ENTER key, if there is a button that shows as
                Message 7 of 11 , Jul 22, 2013
                • 0 Attachment
                  Am 22.07.2013 18:55, schrieb green8819:
                  > Hello Jack,
                  >
                  > What do we do after entering something in a textbox?
                  > We press [Enter]? Did you do that?
                  >

                  I usually hit the OK button on the dialog or move on to the next entry
                  box using the TAB key.

                  I only use the ENTER key, if there is a button that shows as being the
                  default to advance to the next action.

                  A developer should allow any workflow, so everybody will be able to work
                  through the dialog.


                  --
                  Stefan Pendl
                  http://stefanpendl.runbasichosting.com/

                  LB 4.04 Pro ... http://www.libertybasic.com/assist.html
                  LB 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                  LB Community Wiki .............. http://basic.wikispaces.com/
                  LB Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
                  LB Bug Tracker ................. http://libertybasicbugs.wikispaces.com/

                  Books at http://www.lulu.com/ and http://www.amazon.com/
                  Alyce Watson ... APIs for Liberty BASIC
                  Carl Gundel .... Beginning Programming with Liberty BASIC

                  Windows 7 Home Premium 64-bit SP1
                  AMD Turion X2 RM-70 2GHz, 4GB RAM
                • green8819
                  I am trying to find out if a program will let me know which control had the last focus. In my program, there is no problem with button presses. As for textbox,
                  Message 8 of 11 , Jul 22, 2013
                  • 0 Attachment
                    I am trying to find out if a program will let me know which control had the last focus.

                    In my program, there is no problem with button presses.
                    As for textbox, also no problem if a user presses [Enter] after an entry.

                    I overlooked an important fact that a user might press [Tab] instead; as in filling out an e-form with several textboxes. Sometimes we don't know which entry we did last.

                    I give up on a solution for this. If anyone knows, how about sharing. Preferably a tried and tested solution.
                  Your message has been successfully submitted and would be delivered to recipients shortly.