FINDFIRSTINSTANCE function

Purpose: FINDFIRSTINSTANCE will search for a running instance of a GUI program by looking for the Class Name. If found, the caption bar of the sought program will flash until the sought program is re-activated. If the sought program does not have a caption bar, the sought program is given, automatically, the keyboard focus.


 Syntax:

 RetVal = FINDFIRSTINSTANCE(ClassName$)

 Parameters:

  • RetVal The function returns a value of TRUE if an instance of the sought program is found and FALSE if it is not found.
  • ClassName$ Class Name of the program for which to search.

Remarks: FINDFIRSTINTANCE usually is used in the SUB FORMLOAD procedure. If a BCX program is searching for an instance of itself, the Class Name is stored in a preset variable named BCX_CLASSNAME$. In the example below, "mandelbrot" is the Class Name stored in BCX_CLASSNAME$

Example:

 
 GUI "mandelbrot"
  
 CONST Red   = RGB(10,0,0)
 CONST Green = RGB(0,10,0)
 CONST Blue  = RGB(0,0,10)
  
 GLOBAL Form  AS CONTROL
 GLOBAL Kolor AS INTEGER
  
 SUB FORMLOAD
   IF FINDFIRSTINSTANCE(BCX_CLASSNAME$) THEN PostQuitMessage(0)
   Kolor = Blue
   Form  = BCX_FORM("Mandelbrot  ~ Made with BCX ~")
   BCX_SET_FORM_COLOR(Form,0)
   CENTER(Form)
   SHOW(Form)
 END SUB
  
 BEGIN EVENTS
   SELECT CASE CBMSG
     '*******************
     CASE WM_CREATE
     '*******************
     IF NOT SetTimer(hWnd, 1, 3000, 0)  THEN
       MessageBox(hWnd, "Timer Error", "Error", MB_OK)
       PostQuitMessage(0)
     END IF
     '*******************
     CASE WM_PAINT
     '*******************
     DIM RAW ps  AS PAINTSTRUCT
     DIM RAW hdc AS HDC
     hdc = BeginPaint(hWnd, &ps)
     DrawMandelbrot(hdc)
     DeleteDC(hdc)
     EndPaint(hWnd, &ps)
     '*******************
     CASE WM_TIMER
     '*******************
     SELECT CASE Kolor
       CASE Red
       Kolor = Green
       CASE Green
       Kolor = Blue
       CASE Blue
       Kolor = Red
       CASE ELSE
       Kolor = Blue
     END SELECT
     InvalidateRect(Form,0,1)
     '*******************
   END SELECT
 END EVENTS
  
 SUB DrawMandelbrot(hdc AS HDC)
   DIM RAW Count AS INTEGER
   DIM RAW A AS SINGLE, B AS SINGLE, C AS SINGLE
   DIM RAW I AS SINGLE, R AS SINGLE
   FOR I = -1.3 TO 1.3 STEP .01
     DOEVENTS
     FOR R = -2.2 TO 1 STEP .01
       A = B = C = Count = 0
       WHILE ABS(A) <= 2 AND ABS(B) <= 2 AND Count < 128
         C = A * A - B * B + R
         B = 2 * A * B + I
         A = C
         INCR Count
       WEND
       SetPixel(hdc, 50 +(230 + R * 100), 140 + I * 100, Count * Kolor)
     NEXT
   NEXT
   UpdateWindow(Form)
 END SUB