Highlighted
Absent Member.
Absent Member.
335 views

[archive] Make an Acu program grab focus?

[Migrated content. Thread originally posted on 29 October 2009]

I have a program that monitors a directory for the presence of a file. When it sees the file, I want it to maximise its window, and grab input focus from whatever has it at the time (yes, I know how annoying that can be, but I still want to do it!):)

I also would (ideally) like the program to minimize to the system tray, not the task bar. Is that do-able?

Nigel
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Make an Acu program grab focus?

The solution is to use a Format 10 SET statement. Something like this will cause the window to become current and active:

[INDENT]SET INPUT WINDOW window-1[/INDENT]

Where window-1 is the handle of a floating window. It must be a floating window or the SET statement has no effect.

I don't have any information about how to minimize to the system tray rather than the taskbar. I suspect there is a Winows API that you could call to make it happen but I don't know for sure. Can anyone else out there hed some light on that?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Make an Acu program grab focus?

The solution is to use a Format 10 SET statement. Something like this will cause the window to become current and active:

[INDENT]SET INPUT WINDOW window-1[/INDENT]


Hey Doug! Thanks. That'll work fine so long as the application has the focus in the first place. I need it to happen, even if another applicatoin is the currently active one.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Make an Acu program grab focus?

I understand now. There is some discussion in the following thread of using the Windows API SetWindowPos to bring a window to the front:

http://www.acucorp.com/support/supported/customer_forum/showthread.php?t=660&highlight=windows+api

It seems this may work even if the application doesn't currently have focus, but I haven't tried it yet.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Make an Acu program grab focus?

There is currently no mechanism to get an ACUCOBOL-GT application to minimize into the system tray.

As for getting focus, this is not good design, in that a UI should be user driven, not application driven. To get the users attention, you should use the method recommended by Microsoft, which is to make your window flash:

       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  FLASHINGWINDOW.
      * Copyright (c) 1996-2006 by Acucorp, Inc.  Users of ACUCOBOL
      * may freely modify and redistribute this program.
      *This program illustrates how to use the Windows API to make the
      *application window blink to get the users attention
       ENVIRONMENT DIVISION.
       DATA        DIVISION.
       WORKING-STORAGE              SECTION.
       77  hAcuWnd                  HANDLE OF WINDOW.
       77  hWinWnd                  PIC X(4) COMP-N.
       77  CNTL-FONT                USAGE HANDLE OF FONT SMALL-FONT.
       77  KEY-STATUS               IS SPECIAL-NAMES
           CRT STATUS               PIC 9(4) VALUE 0.
           88 EXIT-PRESSED          VALUE 27.
           88 FLASH-PRESSED         VALUE 15.
       SCREEN      SECTION.
       01  MAIN-SCREEN.
           03      PUSH-BUTTON
                   LINE             25
                   COL              25
                   SIZE             14
                   TITLE            "&Flash"
                   EXCEPTION-VALUE  = 15.
           03      PUSH-BUTTON
                   LINE             25
                   COL              41
                   SIZE             14
                   TITLE            "E&xit"
                   SELF-ACT
                   EXCEPTION-VALUE  = 27.
       PROCEDURE DIVISION.
       MAIN-LOGIC.
           DISPLAY STANDARD         GRAPHICAL WINDOW
                   TITLE            "Flashing Demo"
                   SIZE             80
                   LINES            27
                   BACKGROUND-LOW
                   CONTROL          FONT CNTL-FONT
                   HANDLE           hAcuWnd.
           CALL    "[EMAIL="USER32.DLL@WINAPI"]USER32.DLL@WINAPI[/EMAIL]".
           INQUIRE hAcuWnd          SYSTEM HANDLE IN hWinWnd.
           DISPLAY MAIN-SCREEN.
           PERFORM WITH             TEST AFTER UNTIL EXIT-PRESSED
                   ACCEPT           MAIN-SCREEN
                   IF               FLASH-PRESSED
                                    PERFORM FLASH-WINDOW
                                    END-IF
           END-PERFORM.
           GOBACK.
       FLASH-WINDOW.
           PERFORM 10               TIMES
                   CALL             "FlashWindow" USING
                                    VALUE hWinWnd
                                    VALUE 1
                                    END-CALL
                   CALL             "C$SLEEP" USING 0.5
           END-PERFORM.
           EXIT    PARAGRAPH.



If you insist on becoming foreground, some useful reading may be found here:
http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Make an Acu program grab focus?

Thanks Gisle, your advice is as invaluable as ever.

Plan "B" beckons... 😉
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.