//*************************************************************************************** //* 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 the program set it to foreground. //* //* Start_UI_Exclusive Main True // Same as above and a standard messagebox comes up. //* //* Start_UI_Exclusive Main "Text" // "Text" is displayed if an instance is running. //* //* //* Michael Kurz '2000 06.09 mkurz@sbox.tu-graz.ac.at //*************************************************************************************** // Finds a Window by its WindowText, it has to fit "EQ" // 2003-07-29 ------------------------------------ Start Nils G. Svedmyr #IF PKG_Version<|CI9 Function MKFindWindowEQ For Desktop String sTextExt Returns Handle #ELSE Function MKFindWindowEQ Desktop String sTextExt Returns Handle #ENDIF // 2003-07-29 ------------------------------------ Stop Nils G. Svedmyr String sText Pointer pText Integer iRet Move sTextExt To sText GetAddress Of sText To pText Move (OemToAnsi(pText,pText)) To iRet // Convert OEM string to ANSI Function_Return (FindWindow("",sText)) End_Function // Finds a Window by its WindowText, it only has to be in the caption of the window: Function MKFindWindowIN For Desktop String sTextExt Handle hwndSkip Returns Integer String sCaption sText Pointer pCaption pText Integer iRet Handle hwnd Move (Trim(sTextExt)) To sText GetAddress Of sText To pText Move (OemToAnsi(pText,pText)) To iRet // Convert OEM string to ANSI Move (GetForegroundWindow()) To hwnd Move (GetWindow(hwnd,GW_HWNDFIRST)) To hwnd While (hwnd <> 0) If (hwnd And (hwnd <> 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 (sCaption = sText) Function_Return hwnd End // If (hwnd And (hwnd <> hwndSkip)) Begin Move (GetWindow(hwnd,GW_HWNDNEXT)) To hwnd End // While (hwnd <> 0) Function_Return 0 End_Function // 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 > 1) Begin If (sWert = "1") Send Stop_Box "Another instance of the program is running!" "" Else Send Stop_Box sWert "" End Move (SetForeGroundWindow(hwnd)) To iRet Abort End // If hwnd Begin End_Procedure // Covers the start_ui command and checks if another instance is running! #COMMAND Start_UI_Exclusive #If !0=0 Send AbortPrgIfRunning Of Desktop (Main_Panel_ID(Focus(Desktop))) Start_UI #ELSE #IFDEF !1 // send AbortPrgIfRunning Of Desktop !1 !2 Send AbortPrgIfRunning Of Desktop (Main_Panel_ID(Focus(Desktop))) !2 Start_UI !1 #ELSE #IFDEF !1.OBJ Send AbortPrgIfRunning Of Desktop !1.obj !2 Start_UI !1.Obj #ENDIF #ENDIF #ENDIF #ENDCOMMAND