$INCLUDE "rapidq.inc"
CONST WM_LBUTTONUP = &H202
CONST GWL_HWNDPARENT = (-8)
CONST HWND_DESKTOP = 0
CONST GWL_WNDPROC=(-4)
CONST WM_ACTIVATE = &H6
CONST WA_ACTIVE = 1
CONST WA_INACTIVE = 0
Public CONST SW_HIDE = 0
Public CONST SW_NORMAL = 1
Public CONST SW_SHOW = 5
Public CONST SW_restore = 9
Public CONST MB_ICONEXCLAMATION = &H30&
Public CONST FILE_ATTRIBUTE_READONLY = &H1
Public CONST FILE_ATTRIBUTE_HIDDEN = &H2
Public CONST FILE_ATTRIBUTE_SYSTEM = &H4
Public CONST FILE_ATTRIBUTE_ARCHIVE = &H20
Public CONST FILE_ATTRIBUTE_NORMAL = &H80
Public CONST WM_SETFOCUS = &H7
Public CONST WM_CLOSE = &H10
Public CONST WM_QUERYENDSESSION = &H11
Public CONST WM_QUIT = &H12
DIM monitorsize AS INTEGER
DIM OldwndProc AS LONG
DECLARE FUNCTION SetActiveWindow LIB "user32.dll" ALIAS "SetActiveWindow" (BYVAL hwnd AS LONG) AS LONG
DECLARE FUNCTION CallWindowProc LIB "user32" ALIAS "CallWindowProcA" (lpPrevWndFunc AS LONG, hwnd AS LONG, msg AS LONG, wParam AS LONG, lParam AS LONG) AS LONG
DECLARE FUNCTION SetWindowLong LIB "user32" ALIAS "SetWindowLongA" (hwnd AS LONG, nIndex AS LONG, dwNewLong AS LONG) AS LONG
DECLARE FUNCTION ShowWindow LIB "user32" ALIAS "ShowWindow" (BYVAL hwnd AS LONG, BYVAL nCmdShow AS LONG) AS LONG
DECLARE FUNCTION CopyFile LIB "kernel32" ALIAS "CopyFileA" (BYVAL lpExistingFileName AS STRING, BYVAL lpNewFileName AS STRING, BYVAL bFailIfExists AS LONG) AS LONG
DECLARE FUNCTION GetFileAttributes LIB "kernel32" ALIAS "GetFileAttributesA" (BYVAL lpFileName AS STRING) AS LONG
DECLARE FUNCTION SetFileAttributes LIB "kernel32" ALIAS "SetFileAttributesA" (BYVAL lpFileName AS STRING, BYVAL dwFileAttributes AS LONG) AS LONG
DECLARE FUNCTION SetFocus LIB "user32" ALIAS "SetFocus" (BYVAL hwnd AS LONG) AS LONG
DECLARE FUNCTION GetFocus LIB "user32" ALIAS "GetFocus" () AS LONG
DECLARE FUNCTION setfontsize(s) AS SINGLE
$ESCAPECHARS ON
TYPE QWLabel EXTENDS QCANVAS
alignment AS INTEGER
labelstyle AS INTEGER
autosize AS INTEGER PROPERTY SET setautosize
CAPTION AS STRING PROPERTY SET setcaption
lines AS QSTRINGLIST
linespace AS SINGLE
WITH this
FUNCTION gettextwidth(maxstring AS STRING) AS INTEGER
IF RTRIM$(maxstring)="" THEN result=0 : EXIT FUNCTION
result=.textwidth(maxstring)
END FUNCTION
SUB reautosize
.height=.textheight(.CAPTION)*(.lines.itemcount*.linespace)+1
DEFINT il,maxwidth=0,lenl
DEFSTR maxstring,l1
FOR il=0 TO .lines.itemcount-1
l1=.lines.item(il)
lenl=LEN(l1)
IF maxwidth<lenl THEN
maxwidth=lenl : maxstring=l1
END IF
NEXT il
.width=.gettextwidth(maxstring)+4
END SUB
SUB redraw
DEFINT textleft=1
DEFINT i
DEFSTR l1
IF .autosize<>false THEN .reautosize
FOR i=0 TO .lines.itemcount-1
l1=.lines.item(i)
SELECT CASE .alignment
CASE tacenter
textleft=(.width-.gettextwidth(l1))\2
CASE tarightjustify
textleft=.width-.gettextwidth(l1)-2
END SELECT
.TextOut(textleft,i*.textheight(l1)*.linespace+2, l1, .font.COLOR, -1)
NEXT
END SUB
PROPERTY SET setautosize(newautosize AS INTEGER)
IF .autosize<>newautosize THEN
.autosize=newautosize
IF newautosize<>false THEN .reautosize
.redraw
END IF
END PROPERTY
PROPERTY SET setcaption(newcaption AS STRING)
.CAPTION=newcaption
.lines.clear
.lines.parse(newcaption,"\n")
IF .autosize<>false THEN
.reautosize
END IF
.redraw
END PROPERTY
EVENT OnPaint
.redraw
END EVENT
CONSTRUCTOR
linespace=1.2
autosize=false
alignment=taleftjustify
CAPTION = "QWLabel"
lines.parse(.CAPTION,"\n")
END CONSTRUCTOR
END WITH
END TYPE
FUNCTION basename(s AS STRING) AS STRING
$ESCAPECHARS off
DEFINT p1=rinstr(s,"\"),l=LEN(s)
IF p1>=l THEN result="" ELSE result=MID$(s,p1+1)
END FUNCTION
FUNCTION like(s AS STRING,mask AS STRING) AS INTEGER
DIM findpos AS INTEGER
DEFINT start=1,i,j,l,l1,maskp=1,sp=1,masklen,maskp2=maskp
DEFSTR s1,s2
l=LEN(s)
masklen=LEN(mask)
IF masklen<=0 THEN
IF l<=0 THEN like=true ELSE like=false
EXIT FUNCTION
END IF
like=true
DO
IF mask[maskp]="*" THEN
DO
maskp++
IF maskp>masklen THEN EXIT FUNCTION
LOOP UNTIL mask[maskp]<>"*"
maskp2=maskp
WHILE mask[maskp2+1]<>"*" AND mask[maskp2+1]<>"?"
IF maskp2<masklen THEN maskp2++ ELSE EXIT WHILE
WEND
DEFSTR m1=MID$(mask,maskp,maskp2-maskp+1)
findpos=INSTR(sp,s,m1)
IF findpos=0 THEN like=false : EXIT FUNCTION
sp=findpos+(maskp2-maskp+1)
IF sp>=l THEN EXIT FUNCTION
maskp=maskp2+1
ELSEIF mask[maskp]="?" THEN
IF maskp>=masklen THEN
IF sp>=l THEN
EXIT FUNCTION
ELSE
result=false:EXIT FUNCTION
END IF
ELSE
maskp++ : sp++
IF sp>l THEN result=false: EXIT FUNCTION
END IF
ELSE
IF mask[maskp]<>s[sp] THEN
result=false: EXIT FUNCTION
ELSE
maskp++ : sp++
END IF
END IF
LOOP UNTIL maskp>masklen OR sp>l
END FUNCTION
SUB iniWriteint(section AS STRING,keyname AS STRING, _
defaultvalue AS INTEGER, myinifile AS QREGISTRY)
myinifile.openkey( application.title & "\" & section,true)
myinifile.writeinteger(keyname,defaultvalue)
myinifile.closekey
END SUB
FUNCTION inireadstring(section AS STRING,keyname AS STRING, _
defaultvalue AS STRING, myinifile AS QREGISTRY) AS STRING
myinifile.openkey( application.title & "\" & section,false)
IF myinifile.valueexists(keyname) THEN
inireadstring=myinifile.readstring(keyname)
ELSE
inireadstring=defaultvalue
END IF
myinifile.closekey
END FUNCTION
SUB iniwritestring(section AS STRING,keyname AS STRING, _
defaultvalue AS STRING, myinifile AS QREGISTRY)
myinifile.openkey( application.title & "\" & section,true)
myinifile.writestring(keyname,defaultvalue)
myinifile.closekey
END SUB
FUNCTION inireadint(section AS STRING,keyname AS STRING, _
defaultvalue AS INTEGER, myinifile AS QREGISTRY) AS INTEGER
myinifile.openkey( application.title & "\" & section,false)
IF myinifile.valueexists(keyname) THEN
inireadint=myinifile.readinteger(keyname)
ELSE
inireadint=defaultvalue
END IF
myinifile.closekey
END FUNCTION
FUNCTION setfontsize(s) AS SINGLE
setfontsize=.025 * s * screen.height / monitorsize
END FUNCTION
CONST rqClassName = "TForm"
DECLARE FUNCTION FindWindow LIB "USER32" ALIAS "FindWindowA" _
(className AS STRING, windowName AS STRING) AS INTEGER
DECLARE SUB SetForegroundWindow LIB "USER32" ALIAS "SetForegroundWindow" (HWnd AS LONG)
FUNCTION AppPrevInstance(myFormName AS STRING) AS INTEGER
DEFINT hWnd = FindWindow(rqClassName, myFormName)
AppPrevInstance=hwnd
END FUNCTION
TYPE BROWSEINFO
hWndOwner AS LONG
pIDLRoot AS LONG
pszDisplayName AS LONG
lpszTitle AS LONG
ulFlags AS LONG
lpfnCallback AS LONG
lParam AS LONG
iImage AS LONG
END TYPE
CONST BIF_RETURNONLYFSDIRS = 1
CONST MAX_PATH = 260
CONST BFFM_INITIALIZED = 1
CONST BFFM_SETSELECTIONA = &H466
DECLARE SUB CoTaskMemFree LIB "Ole32" ALIAS "CoTaskMemFree"(hMem AS LONG)
DECLARE FUNCTION SHBrowseForFolder LIB "Shell32" ALIAS "SHBrowseForFolder"_
(lpbi AS BROWSEINFO) AS LONG
DECLARE FUNCTION SHGetPathFromIDList LIB "Shell32" ALIAS "SHGetPathFromIDList"_
(pidList AS LONG, lpBuffer AS STRING) AS LONG
DECLARE FUNCTION GetWindowRect LIB "User32" ALIAS "GetWindowRect"_
(hWnd AS LONG, lpRect AS QRECT) AS LONG
DECLARE FUNCTION MoveWindow LIB "User32" ALIAS "MoveWindow"_
(hWnd AS LONG, x AS LONG, y AS LONG,nWidth AS LONG,_
nHeight AS LONG, bRepaint AS LONG) AS LONG
DECLARE FUNCTION SetWindowText LIB "user32" ALIAS "SetWindowTextA"_
(hWnd AS LONG, ByRef lpString AS STRING) AS LONG
TYPE QBROWSEDIALOG EXTENDS QOBJECT
WITH QBROWSEDIALOG
CAPTION AS STRING
Title AS STRING
InitialDir AS STRING
Directory AS STRING
X AS STRING
FUNCTION BrowseHook(hWnd AS LONG, uMsg AS LONG, lParam AS LONG, lpData AS LONG) AS LONG
IF uMsg = BFFM_INITIALIZED THEN
DIM R AS QRECT
GetWindowRect(hWnd, R)
MoveWindow (hWnd, (Screen.Width-(R.Right-R.Left))/2, (Screen.Height-(R.Bottom-R.Top))/2,_
(R.Right-R.Left), (R.Bottom-R.Top), 0)
SendMessage(hWnd, BFFM_SETSELECTIONA, 1, lpData)
IF LEN(.CAPTION) THEN
SetWindowText(hWnd, .CAPTION)
END IF
END IF
END FUNCTION
FUNCTION EXECUTE AS LONG
DIM BI AS BROWSEINFO
DIM pidl AS LONG
DIM sPath AS STRING*MAX_PATH
DIM xPath AS STRING*MAX_PATH
.InitialDir = .InitialDir + CHR$(0)
BI.hWndOwner = Application.Handle
BI.pszDisplayName = VARPTR(xPath)
BI.lpszTitle = VARPTR(This.Title)
BI.lpfnCallback = CODEPTR(This.BrowseHook)
BI.lParam = VARPTR(This.InitialDir)
pidl = SHBrowseForFolder(BI)
IF pidl THEN
IF SHGetPathFromIDList(pidl, sPath) THEN
.Directory = LEFT$(sPath, INSTR(sPath, CHR$(0))-1)
ELSE
.Directory = LEFT$(xPath, INSTR(xPath, CHR$(0))-1)
END IF
CoTaskMemFree pidl
Result = 1
ELSE
Result = 0
END IF
END FUNCTION
END WITH
END TYPE
$TYPECHECK ON
TYPE TNOTIFYICONDATA
cbSize AS DWORD
hWnd AS LONG
uID AS LONG
uFlags AS LONG
uCallbackMessage AS LONG
hIcon AS LONG
szTip AS STRING*64
END TYPE
DECLARE SUB Shell_NotifyIcon LIB "SHELL32" ALIAS "Shell_NotifyIconA" _
(dwMessage AS LONG, NIDATA AS TNOTIFYICONDATA)
CONST NIM_ADD = 0
CONST NIM_MODIFY = 1
CONST NIM_DELETE = 2
CONST NIM_MESSAGE = 1
CONST NIM_ICON = 2
CONST NIM_TIP = 4
CONST WM_USER = &H400
CONST WM_TRAYICON = WM_USER + 400
CONST WM_COMMAND = &H111
CONST WM_SYSCOMMAND = &H112
CONST WM_LBUTTONDOWN = &H201
CONST WM_LBUTTONDBLCLK = &H203
CONST WM_RBUTTONDOWN = &H204
CONST WM_RBUTTONDBLCLK = &H206
CONST SC_MINIMIZE = 61472
CONST SC_CLOSE = 61536
DIM NI AS TNotifyIconData
DEFINT AlreadyTrayed=false
|
|