home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmMain
- BorderStyle = 3 'Fixed Dialog
- Caption = "SGWindow Test"
- ClientHeight = 5160
- ClientLeft = 120
- ClientTop = 576
- ClientWidth = 7896
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 5160
- ScaleWidth = 7896
- StartUpPosition = 3 'Windows Default
- Begin VB.Frame Frame1
- Height = 1044
- Left = 108
- TabIndex = 4
- Top = 3996
- Width = 2532
- Begin VB.Label lblDescr
- Height = 792
- Left = 72
- TabIndex = 5
- Top = 180
- Width = 2352
- WordWrap = -1 'True
- End
- End
- Begin VB.CommandButton cmdExit
- Caption = "E&xit"
- Height = 408
- Left = 6516
- TabIndex = 1
- Top = 3540
- Width = 1236
- End
- Begin VB.ListBox lstTests
- Height = 3528
- IntegralHeight = 0 'False
- ItemData = "Form1.frx":0000
- Left = 120
- List = "Form1.frx":0002
- TabIndex = 0
- Top = 432
- Width = 2532
- End
- Begin VB.Frame frm1
- Height = 1044
- Left = 2772
- TabIndex = 2
- Top = 3996
- Width = 5016
- Begin VB.Label lblMessage
- BeginProperty Font
- Name = "Courier"
- Size = 9.6
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 744
- Left = 108
- TabIndex = 3
- Top = 180
- Width = 4800
- End
- End
- Begin VB.Frame frameTest
- Height = 3648
- Left = 2772
- TabIndex = 6
- Top = 324
- Width = 3612
- End
- Begin VB.Label lblTest
- Alignment = 1 'Right Justify
- Height = 252
- Left = 4260
- TabIndex = 9
- Top = 60
- Width = 2112
- End
- Begin VB.Label lblAttachedWnd
- Height = 252
- Left = 1320
- TabIndex = 8
- Top = 60
- Width = 3132
- End
- Begin VB.Label Label1
- Caption = "Attached Wnd:"
- Height = 252
- Left = 120
- TabIndex = 7
- Top = 60
- Width = 1092
- End
- Begin VB.Menu mnuFile
- Caption = "File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- ' --- SG Window objects
- Public WithEvents g_wndTest As sgWindow.Window
- Attribute g_wndTest.VB_VarHelpID = -1
- Public WithEvents g_wndForm As sgWindow.Window
- Attribute g_wndForm.VB_VarHelpID = -1
- ' Tests structures
- Private Type TestType
- nID As Integer ' Test code
- sName As String ' User readable test name
- sDescr As String ' Test description
- frm As Form
- End Type
- Private Type Tests
- nTests As Integer ' Total number of tests
- nCurrTest As Integer ' Active test
- arrTests() As TestType ' Array of test structures
- End Type
- Private g_Tests As Tests
- ' Misc constants
- Const g_TestFormLeft% = 40
- Const g_TestFormTop% = 160
- Public Function GetWindowDescription(wnd As sgWindow.Window) As String
- If Len(wnd.Text) <> 0 Then
- GetWindowDescription = wnd.Class & " - " & wnd.Text
- Else
- GetWindowDescription = wnd.Class & " ID: " & CStr(wnd.id)
- End If
- End Function
- Private Sub ShowTest(nTest%)
- If (nTest < -1) Or (nTest > g_Tests.nTests - 1) Then Exit Sub
- ' Hide current test
- Dim w As New sgWindow.Window
- If (g_Tests.nCurrTest >= 0) Then
- w.HWND = g_Tests.arrTests(g_Tests.nCurrTest).frm.HWND
- w.Visible = False
- lblTest.Caption = "TEST:"
- End If
- ' Show test
- If (nTest > -1) Then
- Dim frm As Form
- Set frm = g_Tests.arrTests(nTest).frm
-
- ' Attach form to the SGWindow object
- w.HWND = frm.HWND
-
- ' Main form should be parent of the form containing test.
- If w.Parent.HWND <> Me.HWND Then
- w.Parent = g_wndForm
- End If
-
- ' Position and show test form
- PositionTestFrame frm
- w.Visible = True
- lblTest.Caption = "TEST: " & frm.Caption
- End If
- g_Tests.nCurrTest = nTest
- If Me.Visible Then Me.SetFocus
- InitializeTest nTest
- End Sub
- Private Sub InitializeTest(nTest%)
- Select Case nTest + 1
- Case 1: frmTest1.RefeshWindows
- Case 2: frmTest2.txtClass = g_wndTest.Class
- Case 3: frmTest3.txtText = g_wndTest.Text
- Case 4: frmTest4.RefreshStyles
- Case 5: frmTest5.RefreshStyles
- Case 6: frmTest6.RefreshPosition
- Case 7:
- Case 8: frmTest8.RefreshState
- Case 11: frmTest11.RefreshState
- Case 19: frmTest18.RefreshState
-
- Case Else
- End Select
- End Sub
- Private Sub PositionTestFrame(frm As Object)
- frm.left = frameTest.left + g_TestFormLeft - Me.left
- frm.top = frameTest.top + g_TestFormTop
- End Sub
- Private Sub AddTest(id%, name$, descr$, frm As Form)
- Dim test As TestType
- test.nID = id
- test.sName = name
- test.sDescr = descr
- Set test.frm = frm
- g_Tests.arrTests(g_Tests.nTests) = test
- g_Tests.nTests = g_Tests.nTests + 1
- Load frm
- frm.Caption = test.sName
- If Not g_wndForm Is Nothing Then
- Dim w As New sgWindow.Window
- w.HWND = frm.HWND
- w.Parent = g_wndForm
- End If
- End Sub
- Private Sub OnLoad()
- ' Initialize tests array
- ReDim g_Tests.arrTests(32)
- g_Tests.nTests = 0
- AddTest 1, "Attach", "Demonstrates how to attach window handle (HWND) to the SGWindow object and how to enumerate windows", frmTest1
- AddTest 2, "Class", "Retrieve window class name", frmTest2
- AddTest 3, "Text", "Retrieve or set window text (caption)", frmTest3
- AddTest 4, "Style", "Retrive or set window style", frmTest4
- AddTest 5, "Extended style", "Retrive or set window extended style", frmTest5
- AddTest 6, "Position", "Retrieve or set window position", frmTest6
- AddTest 7, "Visible", "Retrieve or set window visibility state", frmTest7
- AddTest 8, "Destroy", "Destroy window attached window", frmTest8
- AddTest 9, "SendMessage", "Send message to the attached window", frmTest9
- AddTest 10, "Freeze events", "Freeze SG Window events", frmTest10
- AddTest 11, "Hooked", "Enables or disables window message subclassing", frmTest11
- AddTest 12, "Enable message", "Adds or removes message from the collection of messages that fires events", frmTest12
- AddTest 13, "Find window", "Finds specified window", frmTest13
- AddTest 14, "Insert into system menu", "Insert menu item into the system menu", frmTest14
- AddTest 15, "Create window", "Demonstrates how to create and manage window using Win32 API", frmTest15
- AddTest 16, "Client paint", "Demonstrates painting on the window client area", frmTest16
- AddTest 17, "Frame paint", "Demonstrates painting on the window frame area", frmTest22
- AddTest 18, "Print", "Print a window to the supplied device context", frmTest17
- AddTest 19, "Redraw", "Redraw window", frmTest18
- AddTest 20, "Top level parent", "Retrieve top level parent of the attached window", frmTest19
- AddTest 21, "Icon", "Retrieve icon from the attache window", frmTest20
- AddTest 22, "Send keys", "Send keybord messages to the attached window", frmTest21
- AddTest 23, "Simple frame paint", "Demonstrates painting on the window frame area. This sample paints over the default caption.", frmTest23
- AddTest 24, "Append Menu", "Demonstrates how to update forms menu at runtime.", frmTest24
- ' Load tests listbox
- Dim i%
- For i = 0 To g_Tests.nTests - 1
- lstTests.AddItem g_Tests.arrTests(i).sName
- Next
- ShowTest 0
- frmTest1.RefeshWindows
- End Sub
- Private Sub GetSelectedTest(ByRef tst As TestType)
- tst.nID = 0
- If lstTests.ListIndex = -1 Then Exit Sub
- Dim sSel$, i%
- sSel = lstTests.List(lstTests.ListIndex)
- For i = 0 To g_Tests.nTests - 1
- If sSel = g_Tests.arrTests(i).sName Then
- tst.nID = g_Tests.arrTests(i).nID
- tst.sDescr = g_Tests.arrTests(i).sDescr
- tst.sName = g_Tests.arrTests(i).sName
- End If
- Next
- End Sub
- Private Function FormatMessage(msg As Long, wParam As Long, lParam As Long)
- Dim sMsg$
- sMsg = "Message: " & GetMessageName(msg) & " - " & CStr(msg) & vbCrLf & _
- "wParam: " & CStr(wParam) & ", Lo=" & CStr(sgWindow.LowWord(wParam)) & ", Hi=" & CStr(sgWindow.HighWord(wParam)) & vbCrLf & _
- "lParam: " & CStr(lParam) & ", Lo=" & CStr(sgWindow.LowWord(lParam)) & ", Hi=" & CStr(sgWindow.HighWord(lParam))
- FormatMessage = sMsg
- End Function
- Private Sub OnClose()
- Dim i%
- For i = 0 To g_Tests.nTests - 1
- Unload g_Tests.arrTests(i).frm
- Next
- End Sub
- Private Sub cmdExit_Click()
- Unload Me
- End Sub
- Private Sub Form_Load()
- ' Initialize Window object
- Set g_wndForm = New sgWindow.Window
- g_wndForm.HWND = Me.HWND
- g_wndForm.Hooked = True
- Set g_wndTest = New sgWindow.Window
- g_wndTest.HWND = Me.HWND
- g_wndTest.Hooked = True
- g_wndTest.EnableMessage wm_MOUSEMOVE
- OnLoad
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- OnClose
- End Sub
- Private Sub lstTests_Click()
- Dim tst As TestType
- GetSelectedTest tst
- lblDescr.Caption = tst.sDescr
- ShowTest tst.nID - 1
- End Sub
- Private Sub mnuFileExit_Click()
- OnClose
- Unload Me
- End Sub
- Private Sub g_wndTest_Message(ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef result As Long)
- Me.lblMessage = FormatMessage(msg, wParam, lParam)
- result = g_wndTest.CallWindowProc(msg, wParam, lParam)
- End Sub
-