home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / articles / vbbultn / source / th_rt_m.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-04-06  |  6.3 KB  |  142 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   1845
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   3375
  8.    Height          =   2250
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1845
  12.    ScaleWidth      =   3375
  13.    Top             =   1140
  14.    Width           =   3495
  15.    Begin ccSubClass SubClass1 
  16.       Left            =   300
  17.       Messages        =   TH_RT_M.FRX:0000
  18.       Top             =   1170
  19.    End
  20.    Begin ccCallback Callback1 
  21.       IntVersion      =   5
  22.       Left            =   2670
  23.       Top             =   1200
  24.       Type            =   6  'EnumWindows
  25.    End
  26.    Begin CommandButton ExitBut 
  27.       Caption         =   "Close"
  28.       Default         =   -1  'True
  29.       Height          =   525
  30.       Left            =   1080
  31.       TabIndex        =   0
  32.       Top             =   1170
  33.       Width           =   1245
  34.    End
  35.    Begin Label Label1 
  36.       Caption         =   "This example shows how you can implement the Task List's Tile and Cascade commands in your Visual Basic application."
  37.       Height          =   885
  38.       Left            =   240
  39.       TabIndex        =   1
  40.       Top             =   90
  41.       Width           =   2955
  42.    End
  43. Option Explicit
  44. Dim ThunderRTMain As Integer
  45. Dim winpos As WINDOWPOS
  46. Sub Callback1_EnumWindows (hWnd As Integer, lpData As Long, retval As Integer)
  47. Dim classname As String
  48. Dim res As Integer
  49.     classname = String$(32, 0)
  50.     res = GetClassName(hWnd, classname, Len(classname) + 1)
  51.     classname = Left$(classname, InStr(1, classname, Chr$(0)) - 1)
  52.     If classname = THUNDERRTMAINSTRING Then
  53.     ' Stop the enumeration once we find the window
  54.     retval = 0
  55.     ThunderRTMain = hWnd
  56.     Me.Caption = "ThunderRTMain = " & Hex$(hWnd)
  57.     SubClass1.HwndParam = ThunderRTMain
  58.     End If
  59. End Sub
  60. Sub ExitBut_Click ()
  61.     Unload Me
  62. End Sub
  63. Sub Form_Load ()
  64. Dim hres As Integer, htask As Integer
  65.     ' Get this task and find the ThunderRTMain window by
  66.     ' enumerating all the top level windows for this task.
  67.     htask = GetCurrentTask()
  68.     hres = EnumTaskWindows(htask, Callback1.ProcAddress, 0)
  69. End Sub
  70. Sub Form_Resize ()
  71. Dim res As Integer
  72.     ' The Task List Manager has specific criterias for determining
  73.     ' which windows are to be tiled or cascaded.  It attempts to tile
  74.     ' all visible windows in their normal state.  Setting the ThunderRTMain
  75.     ' window to a minimized or maximized state has fatal side effects.
  76.     ' Hiding the ThunderRTMain window does not seem to cause any fatal
  77.     ' problems, the only side effect we found was that this application
  78.     ' will not appear in the Task List Manager's list of tasks if the
  79.     ' Task List Manager is opened while the ThunderRTMain form is hidden.
  80.     ' Hide the ThunderRTMain window when this form is minimized
  81.     ' or maximized.  This removes this window from the list of
  82.     ' windows to be tiled or cascaded when the "Tile" or "Cascade"
  83.     ' command is chosen from the Task List Manager.
  84.     ' Unhide the ThunderRTMain window when this form is normal.
  85.     ' This adds this window back to the list of windows to be
  86.     ' tiled or cascaded when the "Tile" or "Cascade" command
  87.     ' is chosen from the Task List Manager.
  88.     Select Case Me.WindowState
  89.     Case NORMAL: res = ShowWindow(ThunderRTMain, SW_SHOWNORMAL)
  90.     Case MINIMIZED: res = ShowWindow(ThunderRTMain, SW_HIDE)
  91.     Case MAXIMIZED: res = ShowWindow(ThunderRTMain, SW_HIDE)
  92.     End Select
  93. End Sub
  94. Sub SubClass1_WndMessage (Wnd As Integer, msg As Integer, wp As Integer, lp As Long, retval As Long, nodef As Integer)
  95. ' Shows how to intercept the "Tile" or "Cascade" message and set the
  96. ' window size manually.
  97. Dim lpwinpos As Long
  98. Dim flags As Integer, isicon As Integer, ismax  As Integer
  99.     Select Case msg
  100.     Case WM_WINDOWPOSCHANGING:
  101.         ' Make sure our application is not in iconic or maximized state before
  102.         ' tiling or cascading.
  103.         isicon = IsIconic(Me.hWnd)
  104.         ismax = IsZoomed(Me.hWnd)
  105.         If ismax Or isicon Then Exit Sub
  106.         'get structure information
  107.         lpwinpos = dwGetAddressForObject(winpos)
  108.         dwCopyDataBynum lp, lpwinpos, Len(winpos)
  109.         ' Visual Basic creates an invisible form that serves as the "Main" form for
  110.         ' every Visual Basic application.  This "Main" form is of the class
  111.         ' "ThunderRTMain", you can use SpyWin to verify that this form exist for
  112.         ' Visual Basic applications.  "ThunderRTMain" forms are what's referred to
  113.         ' as "pop-up" windows.  These window styles do not respond to the tile or
  114.         ' cascade message sent from the Windows version 3.0 (or later) Task List or
  115.         ' other applications that support the cascade and tile features.
  116.         ' When the "Tile" or "Cascade" command is selected in the Windows Task List,
  117.         ' a WM_WINDOWPOSCHANGING message is sent to the "ThunderRTMain" form telling it
  118.         ' to tile or cascade itself if possible.
  119.         ' Since it cannot do either, it ignores the message.  Unfortunately, Windows is
  120.         ' not aware that the application cannot tile or cascade, so an empty slot is
  121.         ' left after the operation is completed on the other windows.
  122.         ' We intercept the Tile and Cascade messages, and tell the application's main
  123.         ' form to move and resize to the coordinates as specified in the tile or
  124.         ' cascade messages.
  125.         ' There are two parameters in the WINDOWPOS structure that we test for to
  126.         ' determine whether this is a tiling or cascading message rather than a move
  127.         ' or resize message (since the ThunderRTMain window also receives this message
  128.         ' whenever the main form for this application is moved or resized).  These are
  129.         ' our observations through our own testing and may not be the way these
  130.         ' parameters are meant to be used or interpreted.  The first is the
  131.         ' hwndInsertAfter element, this is normally the handle of this application's
  132.         ' main form, but is NULL when a tile or cascade message is sent.  The
  133.         ' second is the SWP_NOCOPYBITS bit of the flags element.  This bit is
  134.         ' turned on during a tile or cascade message, and off for others.
  135.         If (winpos.hwndInsertAfter = 0) And (winpos.flags And SWP_NOCOPYBITS) Then
  136. '                    flags = winpos.flags And &HFEFC
  137.             ' Size and position the main form.
  138.             SetWindowPos Me.hWnd, 0, winpos.x, winpos.y, winpos.cx, winpos.cy, flags
  139.         End If
  140.     End Select
  141. End Sub
  142.