Hi,
Our users can run multiple instances of our application, when they exit the last instance, I want to be able to recognise this and execute some logic.
Using the following code, I can recognise all prowin32.exe currently running on the local machine. However, in all instances, the MainWindowTitle property returns "Progress";
DEFINE VARIABLE processList AS System.Diagnostics.Process extent.
processList = System.Diagnostics.Process:GetProcesses().
DO cntr = 1 to extent(processList):
IF index(processList[cntr]:ProcessName,"prowin") > 0 THEN
MESSAGE
processList[cntr]:ProcessName
processList[cntr]:MainWindowTitle
processList[cntr]:Id
VIEW-AS ALERT-BOX.
END.
Is there anything I can do within the application to set a window title so it's picked up by the above API, or, is this just another limitation with Progress?
Thanks.
I'll try again. I've hacked it a bit so it'll work but shouldn't be too hard to adapt.
&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v9r12 &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure /*------------------------------------------------------------------------ File : Purpose : Syntax : Description : Author(s) : Created : Notes : ----------------------------------------------------------------------*/ /* This .W file was created with the Progress AppBuilder. */ /*----------------------------------------------------------------------*/ /* *************************** Definitions ************************** */ DEFINE variable cNewName AS CHARACTER NO-UNDO initial "Testing". PROCEDURE SetWindowTextA EXTERNAL "user32.dll" : DEFINE INPUT PARAMETER HWND AS LONG. DEFINE INPUT PARAMETER txt AS CHARACTER. END PROCEDURE. PROCEDURE SendMessageA EXTERNAL "USER32.DLL": DEFINE INPUT PARAMETER h_Widget AS LONG. DEFINE INPUT PARAMETER i_Message AS LONG. DEFINE INPUT PARAMETER i_wParam AS LONG. DEFINE INPUT PARAMETER i_lParam AS LONG. DEFINE RETURN PARAMETER i_ApiStatus AS LONG. END PROCEDURE. PROCEDURE GetWindow EXTERNAL "user32.dll" : DEFINE INPUT PARAMETER HWND AS LONG. DEFINE INPUT PARAMETER uCmd AS LONG. DEFINE RETURN PARAMETER hwndOther AS LONG. END PROCEDURE. PROCEDURE GetParent EXTERNAL "user32.dll" : DEFINE INPUT PARAMETER hwndChild AS LONG. DEFINE RETURN PARAMETER hwndParent AS LONG. END PROCEDURE. PROCEDURE ExtractIconA EXTERNAL "shell32.dll": DEFINE INPUT PARAMETER hInst AS LONG. DEFINE INPUT PARAMETER lpszExeFileName AS CHARACTER. DEFINE INPUT PARAMETER nIconIndex AS LONG. DEFINE RETURN PARAMETER i_Return AS LONG. END PROCEDURE. &Scoped-DEFINE WM_GETICON 127 &Scoped-DEFINE WM_SETICON 128 /* WM_SETICON / WM_GETICON Type Codes */ &Scoped-DEFINE ICON_SMALL 0 &Scoped-DEFINE ICON_BIG 1 /* some GetWindow() Constants */ &Scoped-DEFINE GW_OWNER 4 DEFINE VARIABLE hParent AS INTEGER NO-UNDO. DEFINE VARIABLE hOwner AS INTEGER NO-UNDO. DEFINE VARIABLE i_ApiStat AS INTEGER NO-UNDO. DEFINE VARIABLE hIcon AS INTEGER NO-UNDO. /* find the hidden owner window */ RUN GetParent (DEFAULT-WINDOW:HWND, OUTPUT hParent). RUN GetWindow (hParent, {&GW_OWNER}, OUTPUT hOwner). /*IF hOwner = 0 THEN RUN GetWindow (hParent, 1, OUTPUT hOwner).*/ IF hOwner = 0 THEN RUN GetWindow (hParent, 2, OUTPUT hOwner). /* change the title: */ RUN SetWindowTextA (hOwner, cNewName). IF hIcon > 0 THEN DO: RUN SendMessageA( hOwner, {&WM_SETICON}, {&ICON_BIG}, hIcon, OUTPUT i_ApiStat ). RUN SendMessageA( hOwner, {&WM_SETICON}, {&ICON_SMALL}, hIcon, OUTPUT i_ApiStat ). END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK /* ******************** Preprocessor Definitions ******************** */ &Scoped-define PROCEDURE-TYPE Procedure &Scoped-define DB-AWARE no /* _UIB-PREPROCESSOR-BLOCK-END */ &ANALYZE-RESUME /* *********************** Procedure Settings ************************ */ &ANALYZE-SUSPEND _PROCEDURE-SETTINGS /* Settings for THIS-PROCEDURE Type: Procedure Allow: Frames: 0 Add Fields to: Neither Other Settings: CODE-ONLY COMPILE */ &ANALYZE-RESUME _END-PROCEDURE-SETTINGS /* ************************* Create Window ************************** */ &ANALYZE-SUSPEND _CREATE-WINDOW /* DESIGN Window definition (used by the UIB) CREATE WINDOW Procedure ASSIGN HEIGHT = 15 WIDTH = 60. /* END WINDOW DEFINITION */ */ &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure /* *************************** Main Block *************************** */ /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME
Thanks, will give it a try.