以書本 16-3 節的 Saver03.vbp 為基礎, 首先在 Saver03.frm 表單的最上面增加以下宣告式:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Const WS_CHILD = &H40000000
Const GWL_HWNDPARENT = (-8)
Const GWL_STYLE = (-16)
Const HWND_TOPMOST = -1&
Const HWND_TOP = 0&
Const HWND_BOTTOM = 1&
Const SWP_NOSIZE = &H1&
Const SWP_NOMOVE = &H2
Const SWP_NOZORDER = &H4
Const SWP_NOREDRAW = &H8
Const SWP_NOACTIVATE = &H10
Const SWP_FRAMECHANGED = &H20
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const SWP_NOCOPYBITS = &H100
Const SWP_NOOWNERZORDER = &H200
Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
接著將 Saver03.frm 表單以下的敘述:
If UCase(Left(Command, 2)) = "/P" Then ' 小螢幕 Unload Me: End End If
修改成:
If UCase(Left(Command, 2)) = "/P" Then ' 小螢幕 Dim hwndDsp As Long Dim r As RECT hwndDsp = Val(Mid(Command, 3)) GetClientRect hwndDsp, r Me.Caption = "Preview" Style = GetWindowLong(Me.hwnd, GWL_STYLE) Style = Style Or WS_CHILD SetWindowLong Me.hwnd, GWL_STYLE, Style SetParent Me.hwnd, hwndDsp SetWindowLong Me.hwnd, GWL_HWNDPARENT, hwndDsp SetWindowPos Me.hwnd, HWND_TOP, 0&, 0&, r.Right, r.Bottom, SWP_NOZORDER Or SWP_NOACTIVATE Or SWP_SHOWWINDOW End If
或者直接下載筆者所修改之後的 saver03.frm 以取代既有的 saver03.frm 檔案。