home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
ALERT.PRG
< prev
next >
Wrap
Text File
|
1993-09-13
|
3KB
|
147 lines
////////////////////////////
//
// alert.prg
//
// Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// ALERT() for Windows.
//
////////////////////////////
#include "windows.ch"
#define CR chr(13)
#define NTRIM(n) alltrim(str(n))
function alert(cMsg, aChoices)
local aDlg, i, j, n, aWid, aChoose, aErr
local hWnd, hDC
local lErr := .f., e, w, h, t := 0, cTitle, msgh
if valtype(cMsg) != "C"
cMsg = asString(cMsg)
endif
cTitle := cMsg
if aChoices == nil
aChoices = {"&Ok"}
endif
if (n := len(aChoices)) > 4
n = 4
endif
cMsg = strtran(cMsg, ";", CR)
i := 1
while ( !Empty(e := ProcName(i)) )
if left(e, 11) == "(b)ERRORSYS"
lErr = .t.
endif
i++
end
// work out total width of choices, also add "&" to the choices (if needed)
aWid := array(n)
aChoose := array(n)
hDC = GetDC()
for i = 1 to n
if (aWid[i] := _GetTextWidth(hDC, aChoices[i]) + 6) < 20
aWid[i] = 20
endif
t += aWid[i]
aChoose[i] = iif(at("&", aChoices[i]) == 0, "&" + aChoices[i], aChoices[i])
next i
ReleaseDC( , hDC)
if lErr
w = 220
h = 160
else
w = iif(t < 220, 220, t + 40)
h = 50 + (msgh := (len(cMsg) - len(strtran(cMsg, CR)) + 1) * 10)
cTitle = "Alert"
endif
// get space between choices
t = max(int((w - t - 8) / (n + 1)), 0) // 8 for vscrollbar
aDlg = CreateDialog(cTitle, ;
WS_CAPTION + WS_VSCROLL + WS_HSCROLL + WS_SYSMENU ;
+ WS_GROUP + WS_TABSTOP ;
+ WS_THICKFRAME + WS_VISIBLE + WS_POPUP, ;
24, 12, w, h)
j = t
aDlg = AppendDialog(aDlg, "", DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
j, h - 30, aWid[1], 14, ;
aChoose[1])
for i = 2 to n
j += aWid[i - 1] + t
aDlg = AppendDialog(aDlg, "", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
j, h - 30, aWid[i], 14, ;
aChoose[i])
next i
i := 1
e = ""
if lErr
aErr = {}
do while ( !Empty(ProcName(i)) )
aadd(aErr, "Called from " + Trim(ProcName(i)) ;
+ "(" + NTRIM(ProcLine(i)) + ")")
i++
enddo
aDlg = AppendDialog(aDlg, "lbox", DLG_LISTBOX, ;
WS_CHILD + WS_VISIBLE + WS_VSCROLL + WS_BORDER, ;
10, 10, 190, 110, ;
aErr)
else
aDlg = AppendDialog(aDlg, "", DLG_STATIC, ;
SS_CENTER + WS_CHILD + WS_VISIBLE, ;
10, 10, 200, msgh, ;
cMsg)
endif
hWnd := GetFocus()
i = ModalDialog(aDlg, , hWnd) // change name & param order ??
SetFocus(hWnd)
return i
static function asString(x)
local v := valtype(x)
do case
case v == "C"
case v == "N"
return NTRIM(x)
case v == "L"
if x
return ".T."
else
return ".F."
endif
case v == "D"
return dtoc(x)
case v == "U"
return "NIL"
case v == "A"
return "<Array>"
case v == "O"
return "<Object " + x:classname() + ">"
case v == "B"
return "<Block>"
otherwise
return ""
end case
return x