//*************************************************************************************** //* Start_UIExl.Pkg //* //* A set of functions to get and handle Windows (WindowHandles) //* and a command that supports checking if another instance is running! //* //* Usage: //* Start_UI_Exclusive // If another instance runs it is set to //* // foreground //* //* Start_UI_Exclusive Main True // Same as above and a std.messagebox comes up! //* //* Start_UI_Exclusive Main "Text" // "Text" is displayed if a Instance is running! //* //* //* Michael Kurz '2000 06.09 mkurz@sbox.tu-graz.ac.at //*************************************************************************************** #IFDEF Get_GetForegroundWindow #ELSE external_function GetForegroundWindow "GetForegroundWindow" user32.dll returns Handle #ENDIF // Gets the Caption of Window... Function WindowCaption Global Handle hwnd returns String String sCaption Pointer pCaption Integer iRet move (Repeat(Character(0),801)) to sCaption // Think of a max. of 800 character +1 for safety! GetAddress of sCaption to pCaption move (GetWindowText(hwnd,pCaption,800)) to iRet // Tries to get the WindowCaption text! move (CString(sCaption)) to sCaption move (Trim(sCaption)) to sCaption Function_Return sCaption End_Function // Finds a Window by its WindowText, it has to fit "EQ" Function MKFindWindowEQ for Desktop String sTextExt returns Handle String sText Pointer pText Integer iRet move sTextExt to sText GetAddress of sText to pText move (OemToAnsi(pText,pText)) to iRet // Wandelt OEM in ANSI String um... Function_Return (FindWindow("",sText)) End_Function // Finds a Window by its WindowText, it only has to be in the caption of the window! // Man kann einen StartWindow handle uebergeben, weil in besonderen Situationen kein // ForegroundWindow Handle gefunden wird! (Click auf TrayIcon!!!) Function MKFindWindowIN_Ext for Desktop Handle hwnd String sTextExt Handle hwndSkip returns Integer String sCaption sText Pointer pCaption pText Integer iRet // Local handle hwnd move sTextExt to sText GetAddress of sText to pText move (OemToAnsi(pText,pText)) to iRet // Wandelt OEM in ANSI String um... if hwnd eq 0 ; move (GetForegroundWindow()) to hwnd move (GetWindow(hwnd,GW_HWNDFIRST)) to hwnd While (hwnd ne 0) if hwnd if hwnd ne hwndSkip Begin move (Repeat(Character(0),201)) to sCaption GetAddress of sCaption to pCaption move (GetWindowText(hwnd,pCaption,200)) to iRet // Schaut ob Text enthalten ist aber move (CString(sCaption)) to sCaption move (Trim(sCaption)) to sCaption if sText IN sCaption Function_Return hwnd End move (GetWindow(hwnd,GW_HWNDNEXT)) to hwnd End Function_Return 0 End_Function Function MKFindWindowIN for Desktop String sTextExt Handle hwndSkip returns Integer Function_Return (MKFindWindowIN_Ext(Desktop,0,sTextExt,hwndSkip)) End_Function Procedure SwitchToProgramAndAbort Global String sLabel Handle hwnd Integer iRet move (MKFindWindowIN(Desktop,sLabel,0)) to hwnd if hwnd Begin move (SetForeGroundWindow(hwnd)) to iRet abort End End_Procedure // Checks if a window with the label of the given ID is running! Function isPrgRunning for Desktop Integer iID returns Integer Function_Return (MKFindWindowIN(Desktop,Label(iID),Window_Handle(iID))) End_Function // Does an abort and a msgbox if the program is already running! Procedure AbortPrgIfRunning for Desktop Integer iID String sWert Integer iRet Handle hwnd move (isPrgRunning(Desktop,iID)) to hwnd if hwnd Begin if NUM_Arguments gt 1 Begin if sWert eq "1" send Stop_Box "Another instance of the program is active!" "" Else send Stop_Box sWert "" End move (SetForeGroundWindow(hwnd)) to iRet abort End End_Procedure // Covers the start_ui command and checks if another instance is running! #COMMAND Start_UI_Exclusive #if !0=0 send AbortPrgIfRunning to Desktop (Main_Panel_ID(Focus(Desktop))) Start_UI #ELSE #IFDEF !1 send AbortPrgIfRunning to Desktop !1 !2 Start_Ui !1 #ELSE #IFDEF !1.OBJ send AbortPrgIfRunning to Desktop !1.obj !2 Start_UI !1.Obj #ENDIF #ENDIF #ENDIF #ENDCOMMAND