home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Form1"
- ClientHeight = 1845
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 3375
- Height = 2250
- Left = 1035
- LinkTopic = "Form1"
- ScaleHeight = 1845
- ScaleWidth = 3375
- Top = 1140
- Width = 3495
- Begin ccSubClass SubClass1
- Left = 300
- Messages = TH_RT_M.FRX:0000
- Top = 1170
- End
- Begin ccCallback Callback1
- IntVersion = 5
- Left = 2670
- Top = 1200
- Type = 6 'EnumWindows
- End
- Begin CommandButton ExitBut
- Caption = "Close"
- Default = -1 'True
- Height = 525
- Left = 1080
- TabIndex = 0
- Top = 1170
- Width = 1245
- End
- Begin Label Label1
- Caption = "This example shows how you can implement the Task List's Tile and Cascade commands in your Visual Basic application."
- Height = 885
- Left = 240
- TabIndex = 1
- Top = 90
- Width = 2955
- End
- Option Explicit
- Dim ThunderRTMain As Integer
- Dim winpos As WINDOWPOS
- Sub Callback1_EnumWindows (hWnd As Integer, lpData As Long, retval As Integer)
- Dim classname As String
- Dim res As Integer
- classname = String$(32, 0)
- res = GetClassName(hWnd, classname, Len(classname) + 1)
- classname = Left$(classname, InStr(1, classname, Chr$(0)) - 1)
- If classname = THUNDERRTMAINSTRING Then
- ' Stop the enumeration once we find the window
- retval = 0
- ThunderRTMain = hWnd
- Me.Caption = "ThunderRTMain = " & Hex$(hWnd)
- SubClass1.HwndParam = ThunderRTMain
- End If
- End Sub
- Sub ExitBut_Click ()
- Unload Me
- End Sub
- Sub Form_Load ()
- Dim hres As Integer, htask As Integer
- ' Get this task and find the ThunderRTMain window by
- ' enumerating all the top level windows for this task.
- htask = GetCurrentTask()
- hres = EnumTaskWindows(htask, Callback1.ProcAddress, 0)
- End Sub
- Sub Form_Resize ()
- Dim res As Integer
- ' The Task List Manager has specific criterias for determining
- ' which windows are to be tiled or cascaded. It attempts to tile
- ' all visible windows in their normal state. Setting the ThunderRTMain
- ' window to a minimized or maximized state has fatal side effects.
- ' Hiding the ThunderRTMain window does not seem to cause any fatal
- ' problems, the only side effect we found was that this application
- ' will not appear in the Task List Manager's list of tasks if the
- ' Task List Manager is opened while the ThunderRTMain form is hidden.
- ' Hide the ThunderRTMain window when this form is minimized
- ' or maximized. This removes this window from the list of
- ' windows to be tiled or cascaded when the "Tile" or "Cascade"
- ' command is chosen from the Task List Manager.
- ' Unhide the ThunderRTMain window when this form is normal.
- ' This adds this window back to the list of windows to be
- ' tiled or cascaded when the "Tile" or "Cascade" command
- ' is chosen from the Task List Manager.
- Select Case Me.WindowState
- Case NORMAL: res = ShowWindow(ThunderRTMain, SW_SHOWNORMAL)
- Case MINIMIZED: res = ShowWindow(ThunderRTMain, SW_HIDE)
- Case MAXIMIZED: res = ShowWindow(ThunderRTMain, SW_HIDE)
- End Select
- End Sub
- Sub SubClass1_WndMessage (Wnd As Integer, msg As Integer, wp As Integer, lp As Long, retval As Long, nodef As Integer)
- ' Shows how to intercept the "Tile" or "Cascade" message and set the
- ' window size manually.
- Dim lpwinpos As Long
- Dim flags As Integer, isicon As Integer, ismax As Integer
- Select Case msg
- Case WM_WINDOWPOSCHANGING:
- ' Make sure our application is not in iconic or maximized state before
- ' tiling or cascading.
- isicon = IsIconic(Me.hWnd)
- ismax = IsZoomed(Me.hWnd)
- If ismax Or isicon Then Exit Sub
- 'get structure information
- lpwinpos = dwGetAddressForObject(winpos)
- dwCopyDataBynum lp, lpwinpos, Len(winpos)
- ' Visual Basic creates an invisible form that serves as the "Main" form for
- ' every Visual Basic application. This "Main" form is of the class
- ' "ThunderRTMain", you can use SpyWin to verify that this form exist for
- ' Visual Basic applications. "ThunderRTMain" forms are what's referred to
- ' as "pop-up" windows. These window styles do not respond to the tile or
- ' cascade message sent from the Windows version 3.0 (or later) Task List or
- ' other applications that support the cascade and tile features.
- ' When the "Tile" or "Cascade" command is selected in the Windows Task List,
- ' a WM_WINDOWPOSCHANGING message is sent to the "ThunderRTMain" form telling it
- ' to tile or cascade itself if possible.
- ' Since it cannot do either, it ignores the message. Unfortunately, Windows is
- ' not aware that the application cannot tile or cascade, so an empty slot is
- ' left after the operation is completed on the other windows.
- ' We intercept the Tile and Cascade messages, and tell the application's main
- ' form to move and resize to the coordinates as specified in the tile or
- ' cascade messages.
- ' There are two parameters in the WINDOWPOS structure that we test for to
- ' determine whether this is a tiling or cascading message rather than a move
- ' or resize message (since the ThunderRTMain window also receives this message
- ' whenever the main form for this application is moved or resized). These are
- ' our observations through our own testing and may not be the way these
- ' parameters are meant to be used or interpreted. The first is the
- ' hwndInsertAfter element, this is normally the handle of this application's
- ' main form, but is NULL when a tile or cascade message is sent. The
- ' second is the SWP_NOCOPYBITS bit of the flags element. This bit is
- ' turned on during a tile or cascade message, and off for others.
- If (winpos.hwndInsertAfter = 0) And (winpos.flags And SWP_NOCOPYBITS) Then
- ' flags = winpos.flags And &HFEFC
- ' Size and position the main form.
- SetWindowPos Me.hWnd, 0, winpos.x, winpos.y, winpos.cx, winpos.cy, flags
- End If
- End Select
- End Sub
-