home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / test.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-08-12  |  5.5 KB  |  162 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Object = "{D488E33C-3223-11D2-987F-204C4F4F5020}#1.0#0"; "COMBOE~1.OCX"
  4. Begin VB.Form frmTest 
  5.    Caption         =   "SG Window - ComboBoxEx Sample"
  6.    ClientHeight    =   3540
  7.    ClientLeft      =   2640
  8.    ClientTop       =   1740
  9.    ClientWidth     =   7656
  10.    Icon            =   "Test.frx":0000
  11.    KeyPreview      =   -1  'True
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   3540
  14.    ScaleWidth      =   7656
  15.    Begin ComboExControl.ComboEx ComboEx1 
  16.       Height          =   0
  17.       Left            =   108
  18.       Top             =   144
  19.       Width           =   7392
  20.       _ExtentX        =   13039
  21.       _ExtentY        =   0
  22.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  23.          Name            =   "MS Sans Serif"
  24.          Size            =   7.8
  25.          Charset         =   0
  26.          Weight          =   400
  27.          Underline       =   0   'False
  28.          Italic          =   0   'False
  29.          Strikethrough   =   0   'False
  30.       EndProperty
  31.       Style           =   0
  32.    End
  33.    Begin ComctlLib.ImageList imlWindows 
  34.       Left            =   6960
  35.       Top             =   2700
  36.       _ExtentX        =   804
  37.       _ExtentY        =   804
  38.       BackColor       =   -2147483643
  39.       MaskColor       =   12632256
  40.       _Version        =   327682
  41.    End
  42. Attribute VB_Name = "frmTest"
  43. Attribute VB_GlobalNameSpace = False
  44. Attribute VB_Creatable = False
  45. Attribute VB_PredeclaredId = True
  46. Attribute VB_Exposed = False
  47. Option Explicit
  48. Private Type PictDesc
  49.   cbSizeofStruct As Long
  50.   picType As Long
  51.   hImage As Long
  52.   xExt As Long
  53.   yExt As Long
  54. End Type
  55. Private Type Guid
  56.   Data1 As Long
  57.   Data2 As Integer
  58.   Data3 As Integer
  59.   Data4(0 To 7) As Byte
  60. End Type
  61. Private Const SRCCOPY = &HCC0020
  62. Private Type RECT
  63.       Left As Long
  64.       Top As Long
  65.       Right As Long
  66.       Bottom As Long
  67. End Type
  68. Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
  69.    (lpPictDesc As PictDesc, riid As Guid, ByVal fPictureOwnsHandle As Long, _
  70.    ipic As IPicture) As Long
  71. Private Declare Function BitBlt Lib "gdi32" _
  72.    (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, _
  73.    ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
  74.    ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  75. Private Declare Function StretchBlt Lib "gdi32" _
  76.    (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
  77.    ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
  78.    ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _
  79.    ByVal dwRop As Long) As Long
  80. Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  81. Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
  82.  Function ConvertIcon(hIcon&) As Picture
  83.    Dim lOk&
  84.     If hIcon = 0 Then Exit Function
  85.     Dim NewPic As Picture, PicConv As PictDesc, IGuid As Guid
  86.     PicConv.cbSizeofStruct = Len(PicConv)
  87.     PicConv.picType = vbPicTypeIcon
  88.     PicConv.hImage = hIcon
  89.     IGuid.Data1 = &H20400
  90.     IGuid.Data4(0) = &HC0
  91.     IGuid.Data4(7) = &H46
  92.     lOk = OleCreatePictureIndirect(PicConv, IGuid, False, NewPic)
  93.    If lOk = 0 Then
  94.       Set ConvertIcon = NewPic
  95.    Else
  96.       Set ConvertIcon = imlWindows.ListImages(1).Picture
  97.    End If
  98. End Function
  99. Private Sub FillCombo(clsWindow As Window, Optional iIndent As Integer = 0)
  100.    Dim clsChild As Window, iIcon%, lWinIcon&
  101.    Dim sText$, pic As StdPicture
  102.    ' Get window icon
  103.    Set pic = clsWindow.Icon(sgSmall_16x16)
  104.    If pic Is Nothing Then
  105.       Set pic = clsWindow.Icon(sgBig_32x32)
  106.       If pic Is Nothing Then iIcon = 1
  107.    End If
  108.    If Not pic Is Nothing Then
  109.       imlWindows.ListImages.Add , , pic
  110.       iIcon = imlWindows.ListImages.Count
  111.    End If
  112.    ' Get window text and insert new item into the combo
  113.    sText = clsWindow.Class & " - '" & clsWindow.Text & "'"
  114.    ComboEx1.AddItem sText, iIcon, iIndent
  115.    ComboEx1.ItemData(ComboEx1.NewIndex) = clsWindow.hWnd
  116.    ' Add children to the combo
  117.    For Each clsChild In clsWindow.Children
  118.       FillCombo clsChild, iIndent + 1
  119.    Next
  120. End Sub
  121. Private Sub ShowWindow()
  122.    Dim rc As RECT
  123.    Me.Cls
  124.    GetWindowRect ComboEx1.ItemData(ComboEx1.ListIndex), rc
  125.    Call StretchBlt(Me.hdc, 10, 35, rc.Right - rc.Left, rc.Bottom - rc.Top _
  126.       , GetDC(ComboEx1.ItemData(ComboEx1.ListIndex)), _
  127.       0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, SRCCOPY)
  128. End Sub
  129. Private Sub ComboEx1_Click()
  130.    ShowWindow
  131. End Sub
  132. Private Sub ComboEx1_KeyDown(KeyCode As Integer, Shift As Integer)
  133.    Me.Cls
  134. Me.CurrentX = 7000
  135. Me.CurrentY = 120
  136.    Print KeyCode & " is pressed"
  137. End Sub
  138. Private Sub Form_Click()
  139.    ComboEx1.SetFocus
  140. End Sub
  141. Private Sub Form_DblClick()
  142.    Dim i%
  143.    For i = 0 To ComboEx1.ListCount - 1
  144.       ComboEx1.ListIndex = i
  145.       DoEvents
  146.    Next
  147.    ComboEx1.ListIndex = 0
  148. End Sub
  149. Private Sub Form_Load()
  150.    Dim clsDesktop As New sgWindow.Window
  151.    clsDesktop.AttachDesktop
  152.    ComboEx1.ImageList = imlWindows
  153.    FillCombo clsDesktop
  154.    ComboEx1.ListIndex = 0
  155. End Sub
  156. Private Sub Form_Resize()
  157.    On Error Resume Next
  158.    ComboEx1.Width = Me.ScaleWidth - ComboEx1.Left * 2
  159. End Sub
  160. Private Sub imlWindows_Click()
  161. End Sub
  162.