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:
|
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
FormAS
CONTROLGLOBAL
KolorAS
INTEGERSUB
FORMLOADIF
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
psAS
PAINTSTRUCTDIM
RAW
hdcAS
HDC hdc=
BeginPaint(
hWnd,&
ps)
DrawMandelbrot(
hdc)
DeleteDC(
hdc)
EndPaint(
hWnd,&
ps)
'*******************
CASE
WM_TIMER'*******************
SELECT
CASE
KolorCASE
Red Kolor=
GreenCASE
Green Kolor=
BlueCASE
Blue Kolor=
RedCASE
ELSE
Kolor=
BlueEND
SELECT
InvalidateRect(
Form,0
,1
)
'*******************
END
SELECT
END
EVENTS
SUB
DrawMandelbrot(
hdcAS
HDC)
DIM
RAW
CountAS
INTEGERDIM
RAW
AAS
SINGLE
, BAS
SINGLE
, CAS
SINGLE
DIM
RAW
IAS
SINGLE
, RAS
SINGLE
FOR
I=
-
1.3
TO
1.3
STEP
.01DOEVENTS
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=
CINCR
CountWEND
SetPixel(
hdc,50
+
(
230
+
R*
100
)
,140
+
I*
100
, Count*
Kolor)
NEXT
NEXT
UpdateWindow(
Form)
END
SUB