
程序代码:
*///////////////////////////////////////////////////////////////////UI相关
*提示消息居中
*msgCenter(cTxt,'nowait noclear nTimeOut...')
Procedure msgCenter(tcMsg, tcOptions)
Local cBuff, hDC, cFontName, nFontSize, nRows, nHeight, nWidth, cForm, oForm
Local aTemp[1]
* 取系统消息框字体 Name, Size
Declare Long SystemParametersInfo In win32api Long, Long, String @, Long
Declare Long GetDC In win32api Long
Declare Long ReleaseDC In win32api Long, Long
Declare Long GetDeviceCaps In win32api Long, Long
Declare Long MulDiv In win32api Long, Long, Long
cBuff = Space(336)
cBuff = BinToC(4+Len(cBuff), 'rs') + cBuff
SystemParametersInfo(41, Len(cBuff), @ cBuff, 0)
cFontName = Getwordnum(Substr(cBuff,309,32), 1, 0h00)
nFontSize = CToBin(Substr(cbuff,281,4),'rs')
hDC = GetDC(0)
nFontSize = -MulDiv(nFontSize, 72, GetDeviceCaps(hDC, 90))
ReleaseDC(0, hDC)
* 找出最长的一行, 用于确定窗口宽度
nRows = Alines(aTemp, tcMsg)
nWidth = 0
For ii = 1 To nRows
nWidth = Max(nWidth, Txtwidth(aTemp[ii],cFontName,nFontSize)*Fontmetric(6,cFontName,nFontSize))
Endfor
nWidth = nWidth + 2*5 && 加边框宽/高度(估计值,不知 wait 窗口的边框值如何定的)
nHeight = Fontmetric(1, cFontName, nFontSize) * nRows + 2*5
* 创建一个同样大小的临时窗口, 自动居中, 再将 wait window 对齐到这个窗口的左上角
cForm = Sys(2015)
Define Window (cForm) At 0,0 Size 1, 1 In Desktop Name oForm
oForm.Move(0, 0, nWidth, nHeight)
Move Window (cForm) Center
Wait tcMsg Window At Max(0,Wlrow(cForm)), Max(0,Wlcol(cForm)) &tcOptions
Release Windows (cForm) &&
Clear Dlls 'SystemParametersInfo','GetDC','ReleaseDC','GetDeviceCaps','MulDiv'
Endproc
**