BCX Console Demonstration Program S94.bas

 ' ********************************************************
 '   BCX sample console program by Kevin Diggins that ...
 '   (1)  Launches NotePad
 '   (2)  Creates a 1 second delay
 '   (3)  Sets NotePad's Window to Foreground
 '   (4)  Creates another 1 second delay
 '   (5)  Centers NotePad's Window on the desktop
 ' ********************************************************
 
 SHELL "notepad.exe"
 
 SLEEP(1000)
 
 SetForegroundWindow(FindWindowText("Untitled - Notepad"))
 
 SLEEP(1000)
 
 CenterWindow(FindWindowText("Untitled - Notepad"))
 
 FUNCTION FindWindowText(WindowText$) AS HWND
 
   LOCAL zBuffer$
   LOCAL hNext AS HWND
   LOCAL hPrev AS HWND
   LOCAL hTop  AS HWND
 
   hTop  = GetTopWindow(0)
   hPrev = hTop
   hNext = 0
 
   WHILE hNext <> hTop
     hNext = GetWindow(hPrev, GW_HWNDNEXT)
     GetWindowText(hNext, zBuffer$, LEN(WindowText$) + 1)
     IF UCASE$(zBuffer$) = UCASE$(WindowText$) THEN
       FUNCTION = hNext
     END IF
     hPrev = hNext
   WEND
   FUNCTION = 0
 END FUNCTION
 
 SUB CenterWindow(hWnd AS HWND)
   DIM wRect AS RECT
   DIM x AS DWORD
   DIM y AS DWORD
   GetWindowRect(hWnd, &wRect)
   x = (GetSystemMetrics ( _
   SM_CXSCREEN) - (wRect.right - wRect.left)) / 2
   y = (GetSystemMetrics ( _
   SM_CYSCREEN) - (wRect.bottom - wRect.top + GetSystemMetrics(SM_CYCAPTION))) / 2
   SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOSIZE OR SWP_NOZORDER)
 END SUB