Announcement

Collapse
No announcement yet.

Help With Making An Application Awalys Active / on focus

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

  • Help With Making An Application Awalys Active / on focus

    Am working on a Point Of Sale application that have to be active (ALWAYS ON FOCUS) at all times until intentionally closed. As of now, it does happen that the application is not always on focus, either because windows popped-up a notification update or i clicked the task bar unintentionally resulting in focus switching to that particular windows. Is there a way of insuring that at all times the application is not only ALWAYS on top BUT also always active because computers that would be running this POS application won’t be having a mouse to keep on switching focus? Thank you.

  • #2
    One possible way to make sure your application window is always on top and active is this:

    At the end of your On Show event script, start a timer, which is triggered every few seconds. Five seconds should be fast enough to make the application return quickly, like this:

    Code:
    Page.StartTimer(5000);
    Now, in the On Timer event script, place this:

    Code:
    nRes = String.ToNumber(DLL.CallFunction(_SystemFolder .. "\\User32.dll", "GetActiveWindow", "0", DLL_RETURN_TYPE_LONG, DLL_CALL_CDECL));
    nWnd = Application.GetWndHandle();
    
    if (nRes ~= nWnd) then
       -- set current window on top and reactivate
       Window.SetOrder(nWnd, HWND_TOPMOST);
    end
    Ulrich

    Comment


    • #3
      Originally posted by Ulrich View Post
      One possible way to make sure your application window is always on top and active is this:

      At the end of your On Show event script, start a timer, which is triggered every few seconds. Five seconds should be fast enough to make the application return quickly, like this:

      Code:
      Page.StartTimer(5000);
      Now, in the On Timer event script, place this:

      Code:
      nRes = String.ToNumber(DLL.CallFunction(_SystemFolder .. "\\User32.dll", "GetActiveWindow", "0", DLL_RETURN_TYPE_LONG, DLL_CALL_CDECL));
      nWnd = Application.GetWndHandle();
      
      if (nRes ~= nWnd) then
         -- set current window on top and reactivate
         Window.SetOrder(nWnd, HWND_TOPMOST);
      end
      Ulrich

      This solves my problem. Maybe it's time indigorose help us with more knowledge on how to extend AMS applications with windows dll.

      Comment


      • #4
        You are welcome.

        Ulrich

        Comment


        • #5
          Ulrich, we have a new problem with the proposed solution.

          Our proposed approach finds an input field that is always on focus for bar code reading on scan, yet our proposed solution does not restore this focus when the application is restored to it's required top order
          (
          Window.SetOrder(nWnd, HWND_TOPMOST);c
          ) Any thoughts on that ?

          Comment


          • #6
            You could use Page.SetFocus() to move the focus to the desired control when the window became inactive.

            Ulrich

            Comment


            • #7
              I will upload a sample application. This does not produce an expected outcome.

              Comment


              • #8
                Sample application

                Here is a sample application. When the application loss focus the first it kicks back very well, but after that it does not set the focus to the input field
                Attached Files

                Comment


                • #9
                  Try this:
                  Code:
                  function ResetApplicationFocus()
                  	nRes = String.ToNumber(DLL.CallFunction(_SystemFolder .. "\\User32.dll", "GetActiveWindow", 0, DLL_RETURN_TYPE_LONG, DLL_CALL_CDECL));
                  	nWnd = Application.GetWndHandle();
                  		
                  	if (nRes ~= nWnd) then
                  		-- set current window on top and reactivate
                  		Window.SetOrder(nWnd, HWND_TOPMOST);
                  		DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SetForegroundWindow", nWnd, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
                  		Page.SetFocus("INPUT_BARCODE");
                  	end
                  end
                  Ulrich

                  Comment


                  • #10
                    Ulrich, we still do not have a working solution. Thank you for your support.

                    Comment


                    • #11
                      To fixed this issue is to run a timer and perform a mouse click on specific screen location.

                      Comment

                      Working...
                      X