Pages

Thursday, February 7, 2002

Peoplecode 3-tier Detection

The Status Bar is a control that is at the bottom of a panel that displays information about the application status. It is divided into individual panes. Each pane displays specific aspects of the process/function the user is in. 5 panes are present in v.7 and 6 panes in v.8. This article will demonstrate a platform independent method to detect 3-tier connection by accessing the information stored on status bar, provided the database sever and application server have different names.
Take a look at a sample status bar:

The 1st pane does not have a border, and is used for panel loading. We are interested in the 3rd pane. It displays the server name, GF75DMO. In PS8, there’s another pane for Time, but server name is still on 3rd pane.
If server name is not displayed, turn it on in Configuration Manager Display tab:




  • Copy the function declaration:

  • Declare Function GetActiveWindow Library "user32"
    () Returns long As number;
    Declare Function GetWindow Library "user32"
    (long Value As number, long Value As number) Returns long As number;
    Declare Function GetClassNameA Library "user32"
    (long Value As number, string Ref As string, integer Value As number) Returns long As number;
    Declare Function SendMsg2 Library "user32" Alias "SendMessageA"
    (long Value As number, integer Value As number, integer Value As number, string Ref As string)
    Returns long As number;Function GetSB(&PANETEXT As string) Returns boolean;
    &STATBAR = "msctls_statusbar32";
    &HWND = GetActiveWindow();
    &GW_CHILD = 5;
    &GW_HWNDNEXT = 2;
    
    &MAXLEN = 128;   &CLSNAME = Rept(" ", &MAXLEN);
    &CWND = GetWindow(&HWND, &GW_CHILD);
    While &CWND > 0
    &CLSLEN = GetClassNameA(&CWND, &CLSNAME, &MAXLEN);
    If &CLSNAME = &STATBAR Then
      Break;
    End-If;
    &CWND = GetWindow(&CWND, &GW_HWNDNEXT);
    End-While;
    If &CWND > 0 Then
    &NPARTS = 0;
    &CORD = 0;
    &SB_GETTEXTA = 1026;
    &RC = SendMsg2(&CWND, &SB_GETTEXTA, 2, &PANETEXT);
    If &RC > 0 Then
      Return True;
    End-If;
    End-If;
    Return False;
    End-Function;



  • Test the function in a FieldChange event:

  • &XX = GetSB(&PANETEXT);
    If &XX Then
    If &PANETEXT = "MyAppSvr" Then
    WinMessage("3-tier");
    Else
    WinMessage("2-tier");
    End-If;
    Else
    WinMessage("fail");
    End-If;
    The server name is returned in &PANETEXT. Compare it to a list of known App Server names. If a match is found, then the user has logged into the App server.
    As with all external Windows function APIs, if your app server is not NT, set the execution location of this code to client:

    You can also read or write into this or other panes on the status bar. But there are some considerations when writing text to it. Please email the author if you’d like to see how to do it.

    (This article was originally published on 02/07/02 at www.slerp.com. PSTools version 5,6,7)