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 / vbpg32 / samples4 / ch05 / ex5a.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-02-16  |  7.4 KB  |  226 lines

  1. VERSION 4.00
  2. Begin VB.Form frmEX5A 
  3.    Caption         =   "Chapter 5 Examples A"
  4.    ClientHeight    =   4755
  5.    ClientLeft      =   1110
  6.    ClientTop       =   1620
  7.    ClientWidth     =   6630
  8.    Height          =   5160
  9.    Left            =   1050
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   317
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   442
  14.    Top             =   1275
  15.    Width           =   6750
  16.    Begin VB.CommandButton cmdSetParent 
  17.       Caption         =   "SetParent"
  18.       Height          =   375
  19.       Left            =   480
  20.       TabIndex        =   11
  21.       Top             =   3840
  22.       Width           =   2175
  23.    End
  24.    Begin VB.PictureBox picContainer 
  25.       Height          =   1335
  26.       Left            =   3240
  27.       ScaleHeight     =   1305
  28.       ScaleWidth      =   3165
  29.       TabIndex        =   10
  30.       Top             =   660
  31.       Width           =   3195
  32.    End
  33.    Begin VB.CommandButton cmdRTMain 
  34.       Caption         =   "Find ThunderRTMain"
  35.       Height          =   375
  36.       Left            =   480
  37.       TabIndex        =   9
  38.       Top             =   3420
  39.       Width           =   2175
  40.    End
  41.    Begin VB.Timer Timer1 
  42.       Enabled         =   0   'False
  43.       Interval        =   3000
  44.       Left            =   180
  45.       Top             =   4140
  46.    End
  47.    Begin VB.CommandButton cmdBringToTop 
  48.       Caption         =   "Bring MDI Child1 to top"
  49.       Height          =   375
  50.       Left            =   480
  51.       TabIndex        =   8
  52.       Top             =   3000
  53.       Width           =   2175
  54.    End
  55.    Begin VB.CommandButton cmdTile 
  56.       Caption         =   "Tile Windows"
  57.       Height          =   375
  58.       Left            =   480
  59.       TabIndex        =   7
  60.       Top             =   1680
  61.       Width           =   2175
  62.    End
  63.    Begin VB.CommandButton cmdCascade 
  64.       Caption         =   "CascadeWindows"
  65.       Height          =   375
  66.       Left            =   480
  67.       TabIndex        =   6
  68.       Top             =   1200
  69.       Width           =   2175
  70.    End
  71.    Begin VB.CheckBox chkTopmost 
  72.       Caption         =   "TopMost"
  73.       Height          =   255
  74.       Left            =   480
  75.       TabIndex        =   5
  76.       Top             =   2640
  77.       Width           =   1515
  78.    End
  79.    Begin VB.CommandButton cmdMove2 
  80.       Caption         =   "Move defered"
  81.       Height          =   375
  82.       Left            =   1440
  83.       TabIndex        =   4
  84.       Top             =   2160
  85.       Width           =   1215
  86.    End
  87.    Begin VB.CommandButton cmdMove1 
  88.       Caption         =   "Move"
  89.       Height          =   375
  90.       Left            =   480
  91.       TabIndex        =   3
  92.       Top             =   2160
  93.       Width           =   855
  94.    End
  95.    Begin VB.TextBox txtWindows 
  96.       Height          =   285
  97.       Index           =   0
  98.       Left            =   3240
  99.       TabIndex        =   2
  100.       Text            =   "Test Windows"
  101.       Top             =   180
  102.       Width           =   1395
  103.    End
  104.    Begin VB.CommandButton cmdArrange 
  105.       Caption         =   "ArrangeIconicWindows"
  106.       Height          =   435
  107.       Left            =   480
  108.       TabIndex        =   1
  109.       Top             =   660
  110.       Width           =   2175
  111.    End
  112.    Begin VB.CommandButton cmdAdjust 
  113.       Caption         =   "AdjustWindowRect"
  114.       Height          =   435
  115.       Left            =   480
  116.       TabIndex        =   0
  117.       Top             =   180
  118.       Width           =   2175
  119.    End
  120. Attribute VB_Name = "frmEX5A"
  121. Attribute VB_Creatable = False
  122. Attribute VB_Exposed = False
  123. Option Explicit
  124. ' Copyright 
  125.  1996 by Desaware. All Rights Reserved
  126. ' For experimental purposes - does not work reliably
  127. Private Sub chkTopmost_Click()
  128.     Dim dl&, position&
  129.     If chkTopmost.Value = 1 Then position = HWND_TOPMOST Else position = HWND_NOTOPMOST
  130.     dl& = SetWindowPos&(hwnd, position, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
  131. End Sub
  132. Private Sub cmdAdjust_Click()
  133.     Dim dl&
  134.     Dim lpRect As RECT
  135.     Dim dwStyle&
  136.     dwStyle& = GetWindowLong(hwnd, GWL_STYLE)
  137.     ' This is our target location and size for the client area
  138.     dl& = SetRect(lpRect, 50, 50, 150, 150)
  139.     ' Find out how big the window needs to be
  140.     dl& = AdjustWindowRect(lpRect, dwStyle, False)
  141.     ' Look at the new sizes
  142.     Debug.Print "Window size: " & lpRect.Right - lpRect.Left & " by " & lpRect.Bottom - lpRect.Top
  143.     ' Do the move - note the width and height calculations
  144.     dl& = MoveWindow(hwnd, lpRect.Left, lpRect.Top, lpRect.Right - lpRect.Left, lpRect.Bottom - lpRect.Top, True)
  145.     DoEvents
  146.     ' Verify the window size
  147.     dl& = GetWindowRect(hwnd, lpRect)
  148.     Debug.Print "GetWindowRect size: " & lpRect.Right - lpRect.Left & " by " & lpRect.Bottom - lpRect.Top
  149.     ' Verify the client area size
  150.     dl& = GetClientRect(hwnd, lpRect)
  151.     ' Compare results of GetClientRect with Scalewidth and Scaleheight when ScaleMode for form is pixels
  152.     Debug.Print "GetClientRect size: " & lpRect.Right - lpRect.Left & " by " & lpRect.Bottom - lpRect.Top
  153.     Debug.Print "Actual client size: " & ScaleWidth & " by " & ScaleHeight
  154. End Sub
  155. Private Sub cmdArrange_Click()
  156.     Dim dl&
  157.     ' Arranges the icons on the desktop
  158.     dl& = ArrangeIconicWindows(GetDesktopWindow())
  159. End Sub
  160. Private Sub cmdBringToTop_Click()
  161.     Timer1.Enabled = True
  162. End Sub
  163. Private Sub cmdCascade_Click()
  164.     ' Arranges the forms in the MDI form.
  165.     ' Replace the "GetParent(Form1.hwnd)" term with GetDesktopWindow() to cascade
  166.     ' all top level windows on the desktop
  167.     Dim dl&
  168.     dl& = CascadeWindowsByNum(GetParent(frmEX5A2.hwnd), 0, 0, 0, 0)
  169. End Sub
  170. Private Sub cmdMove1_Click()
  171.     Dim x%, newtop&
  172.     Dim dl&
  173.     For x% = 0 To 10
  174.         dl& = MoveWindow(txtWindows(x%).hwnd, 250, newtop&, 40, 20, True)
  175.         newtop = newtop + 21
  176.     Next x%
  177. End Sub
  178. Private Sub cmdMove2_Click()
  179.     Dim posres&
  180.     Dim x%, dl&
  181.     Dim newtop&
  182.     posres& = BeginDeferWindowPos(11)
  183.     For x% = 0 To 10
  184.         ' Note that posres might change
  185.         posres& = DeferWindowPos(posres, txtWindows(x%).hwnd, HWND_TOP, 300, newtop&, 40, 20, SWP_SHOWWINDOW)
  186.         newtop = newtop + 21
  187.     Next x%
  188.     dl& = EndDeferWindowPos(posres)
  189. End Sub
  190. Private Sub cmdRTMain_Click()
  191.     Dim hw&, cnt&
  192.     Dim rttitle As String * 256
  193.     hw& = FindWindow("ThunderRTMain", vbNullString)
  194.     cnt = GetWindowText(hw&, rttitle, 255)
  195.     MsgBox Left$(rttitle, cnt), 0, "RTMain title"
  196. End Sub
  197. Private Sub cmdSetParent_Click()
  198.     Dim dl&
  199.     dl& = SetParent(cmdSetParent.hwnd, picContainer.hwnd)
  200.     ' Be sure to reposition the button
  201.     cmdSetParent.Move 0, 0
  202. End Sub
  203. Private Sub cmdTile_Click()
  204.     ' Arranges the forms in the MDI form.
  205.     ' Replace the "GetParent(Form1.hwnd)" term with GetDesktopWindow() to tile
  206.     ' all top level windows on the desktop
  207.     Dim dl&
  208.     dl& = TileWindowsBynum(GetParent(frmEX5A2.hwnd), 0, 0, 0, 0)
  209. End Sub
  210. Private Sub Form_Load()
  211.     Dim x%
  212.     For x% = 1 To 10
  213.         Load txtWindows(x%)
  214.         txtWindows(x%).Visible = True
  215.     Next x%
  216.     frmEX5AMDI.Visible = True
  217. End Sub
  218. Private Sub Form_Unload(Cancel As Integer)
  219.     Unload frmEX5AMDI
  220. End Sub
  221. Private Sub Timer1_Timer()
  222.     Dim dl&
  223.     dl& = BringWindowToTop(frmEX5A2.hwnd)
  224.     Timer1.Enabled = False
  225. End Sub
  226.