Run only one instance of your application: Difference between revisions

m
mNo edit summary
Line 77: Line 77:
     // If so, it activates the running application and closes this one.
     // If so, it activates the running application and closes this one.
       Procedure DoCheckProgramActive
       Procedure DoCheckProgramActive
  String sTitle
        String sTitle
  Handle hWnd
        Handle hWnd
  Integer iVoid
        Integer iVoid


  Register_Object Main
        Register_Object Main
  Get Label of Main to sTitle
        Get Label of Main to sTitle
        Move (FindWindow("",sTitle))  to hWnd
        If (hWnd) Begin
          Send Stop_Box (sTitle + " Already is Running and Can only be Started Once.") "Error:"
          Move (ShowWindow(hWnd,SW_MAXIMIZE)) to iVoid  // 9 =SW_RESTORE SW_NORMAL
          Move (SetForegroundWindow(hWnd)) to iVoid
          Abort
        End
      End_Procedure // DoCheckProgramActive


  Move (FindWindow("",sTitle))  to hWnd
      // End_Construct_Object
  If (hWnd) Begin
      Procedure End_Construct_Object
      Send Stop_Box (sTitle + " Already is Running and Can only be Started Once.") "Error:"
        Send DoCheckProgramActive
      Move (ShowWindow(hWnd,SW_MAXIMIZE)) to iVoid  // 9 =SW_RESTORE SW_NORMAL
        Forward Send End_Construct_Object
      Move (SetForegroundWindow(hWnd)) to iVoid
      End_Procedure // End_Construct_Object
      Abort
End_class
  End
End_Procedure // DoCheckProgramActive


// End_Construct_Object
The FindWindow technique is also discussed in the book "Mastering Visual DataFlex" from Starzen.
Procedure End_Construct_Object
    Send DoCheckProgramActive
    Forward Send End_Construct_Object
End_Procedure // End_Construct_Object
 
End_class