
' 在頂層表單實作動态顯示視窗清單

' 我從一開始程式設計,就徹底抛棄了_screen,而改用頂層表單。我個人感覺頂層表單做出的系統顯示專業些,也許是因為我對_screen了解不夠深入吧。選用頂層表單作為系統主表單,就意味着很多東西必須自己去實作。例如如何實作動态顯示視窗清單,以為是我的個人經驗,希望能抛磚引玉!

' *************************

' 基于base.vcx中的_form類

' *************************

' ''''''*!* LoadValues事件代碼:

' ''''''*-- 表單狀态設定

With This

.cFormName = .Caption

.JustName = FindWin(This)

.Name = " _ " + Alltrim(Str(.hWnd))

.Icon = " ImagesLogo.ico "

.MDIForm = .F.

.ShowTips = .T.

.BorderStyle = 2

.oldWidth = .Width

.oldHeight = .Height

.chkFormType() && 檢查表單類型

ToBar (.cFormName)

Endwith

' '''''*-- 儲存表機關置

Local cThisName

cThisName = This.JustName

If Type( " _Screen.&cThisName " ) = " U " Then

_Screen.AddObject(cThisName, " Custom " )

With _Screen. & cThisName.

.AddProperty( " LEFT " , 0 )

.AddProperty( " TOP " , 0 )

Endwith

End If

With _Screen. & cThisName.

This.Left = This.Left + .Left

This.Top = This.Top + .Top

' '''''*-- 計算表單在螢幕中的位置

If Sysmetric( 2 ) - (This.Top + This.Height) >= 140 Then

.Left = .Left + 20

.Top = .Top + 20

Else

.Left = 0

.Top = 0

End If

Endwith

' '''''*-- 重新整理視窗清單

If !This.nWindowType = 1 Then

If Vartype (_Screen.WindowListText) = " U " Then

_Screen.AddProperty( " WindowListText " , "" )

End If

cFormInf = Alltrim(This.Name) + " # " + Alltrim(This.Caption) + " , "

_Screen.WindowListText = _Screen.WindowListText + cFormInf

This.AddWindowList()

End If

' '''''*-- 重新整理工具條

If !Type( " oMytoolsbar " ) = " U " Then

Local tForm,cForm,o

tForm = Lower(Alltrim(This.JustName))

For Each o In oMytoolsbar.Controls

cForm = Alltrim(o.Name)

cForm = Lower(Substrc(cForm, 4 , Len (cForm)))

If cForm = tForm Then

o.Enabled = .F.

Exit

End If

Next

End If


' '''''*!* AddWindowList事件代碼

' '''''*-- 增加視窗清單

With _Screen

nListForm = Alines(aWindowList, .WindowListText, " , " )

Define Bar 4 Of _4 Prompt " - "

For i = 1 To nListForm

cFormInf = Strtran(aWindowList[i], " , " , "" )

cFormName = Left (cFormInf, At( " # " , cFormInf) - 1 )

cFormInf = Substr(cFormInf, At( " # " , cFormInf) + 1 )

cFormInf = " < " + Alltrim(Str(i)) + " . " + cFormInf

_FontName = Alltrim(.MenuFontName)

_FontSize = .MenuFontSize

Define Bar i + 4 Of _4 Prompt " &cFormInf " Font " &_FontName " ,_FontSize

* On Selection Bar i + 4 Of _4 Activate Window & cFormName Top

On Selection Bar i + 4 Of _4 ActivateWindow( " &cFormName " )

Endfor

Endwith


' '''''*!* DeleteWindowList事件代碼

' '''''*-- 删除視窗清單

Release Bar 4 Of _4 && 删除 " - "

With _Screen

nListForm = Alines(aWindowList, .WindowListText, " , " )

For i = 1 To nListForm

Release Bar i + 4 Of _4

Endfor

cFormInf = Alltrim(This.Name) + " # " + Alltrim(This.Caption) + " , "

.WindowListText = Strtran(.WindowListText, cFormInf, "" )

Endwith


' '''''*!* chkFormType

' '''''*-- 判别目前表單類型

Local lFormType

lFormType = .T.

Try

lFormType = PEMSTATUS(This.Parent, " WindowList " , 5 )

Catch

lFormType = .F.

Finally

This.FormType = lFormType

Endtry