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

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