home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / FINDAP.ZIP / FINDSELF.PAS < prev    next >
Pascal/Delphi Source File  |  1991-08-10  |  2KB  |  66 lines

  1. library FINDSELF;
  2. { This routine will locate any other APPs running with the same window
  3.   CAPTION and if found, activate the other APP so that VBASIC can
  4.   abort this instance
  5. }
  6. {These are the units used}
  7. uses Strings, WinTypes;
  8.  
  9. {These are global variables to the DLL}
  10. var
  11.         ThWnd:integer;
  12.           Capt:Array[0..255] of Char;
  13.  
  14.  
  15. {These are the API functions used}
  16. procedure SetFocus (Wnd:hWnd); far;
  17.     External 'USER' index 22;
  18.  
  19. procedure GetWindowText (Wnd:hWnd; Buff:PChar; BufSize:word); far;
  20.     External 'USER' index 36;
  21. procedure SendMessage (Wnd, Msg, wParam:word;lParam:PChar); far;
  22.     External 'USER' index 111;
  23. procedure EnumWindows (Func:TFarProc; lParam:PChar);far;
  24.     External 'USER' index 54;
  25.  
  26.  
  27. {This is the call-back function that is sent the hWnd of every window}
  28. function EnumFunc (hWnd:hWnd; Search:PChar):Bool;export;
  29.     Begin
  30.       {First retrieve the caption of the Window}
  31.           GetWindowText (hWnd, @Capt, 256);
  32.       {StrPos is identical to Instr. We cap both strings to be insensitive}
  33.        if StrPos (StrUpper (@Capt), StrUpper(Search)) <> Nil then
  34.               Begin
  35.                            { APPActivate "SEARCH" }
  36.                               SetFocus(hWnd);
  37.                            {ThWnd = ThWnd + 1}
  38.                             Inc (ThWnd);
  39.  
  40.                         end;
  41.              EnumFunc := TRUE;
  42.    End;
  43.  
  44. function FindAppSelf (Search:PChar):Integer;export;
  45.     Begin
  46.       {Set counter to zero}
  47.       ThWnd := 0;
  48.       {Tell Windows to start sending hWnds to EnumFunc}
  49.       EnumWindows (@EnumFunc, Search);
  50.       {When all windows have been examined, return total to VB}
  51.       FindAppSelf := ThWnd div 2;
  52.                                { remove the DOUBLEing }
  53.    end;
  54.  
  55.  
  56.  
  57. Exports
  58.    EnumFunc,
  59.    {The resident keyword makes access from VB quicker}
  60.     FindAppSelf resident;
  61.  
  62.  
  63. {No startup code but we need the empty routine anyway}
  64. Begin
  65. End.
  66.