home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / clswindo.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-08-03  |  2.6 KB  |  92 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsWindow"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. '--------------------------------------------------------------------------
  11. ' Class clsWindow shows how to create and manage window entirely from VB
  12. '--------------------------------------------------------------------------
  13.  
  14. Option Explicit
  15.  
  16. Implements IsgMessageSink
  17. Implements IsgPaintSink
  18.  
  19. Private mWnd As sgWindow.Window
  20. Private mwndRect As RECT
  21.  
  22.  
  23.  
  24. Public Sub Create(hParent&, sText$, id&, x&, y&, width&, height&, style&)
  25.    ' Enable message processing
  26.    mWnd.EnableMessage wm_ALL, True
  27.    
  28.    ' Get rid of attached window
  29.    mWnd.HWND = 0
  30.    
  31.    ' Create new window
  32.    mWnd.Create "", sText, style, 0, x, y, width, height, hParent, id
  33.    mWnd.Tag = sText
  34. End Sub
  35.  
  36. Private Sub Class_Initialize()
  37.    Set mWnd = New sgWindow.Window
  38.    mWnd.SetMessageCallback Me
  39.    mWnd.SetPaintCallback Me
  40. End Sub
  41.  
  42. Private Sub Class_Terminate()
  43.    mWnd.HWND = 0
  44.    Set mWnd = Nothing
  45. End Sub
  46.  
  47. Private Sub IsgMessageSink_Message(ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef result As Long)
  48.    Select Case msg
  49.       Case wm_NCCREATE
  50.          result = 1
  51.         
  52.       Case wm_SIZE
  53.          mwndRect.left = 0
  54.          mwndRect.top = 0
  55.          mwndRect.right = sgWindow.LowWord(lParam)
  56.          mwndRect.bottom = sgWindow.HighWord(lParam)
  57.          result = 0
  58.          
  59.       Case Else
  60.          result = mWnd.CallWindowProc(msg, wParam, lParam)
  61.    End Select
  62. End Sub
  63.  
  64. Private Sub IsgPaintSink_ClientPaint(ByVal hdc As Long, ByVal left As Long, ByVal top As Long, ByVal right As Long, ByVal bottom As Long)
  65.    Dim rcText As RECT
  66.    
  67.    'GetClientRect mWnd.HWND, rc
  68.    Rectangle hdc, 0, 0, mwndRect.right, mwndRect.bottom
  69.    
  70.    ' Calculate text rectangle
  71.    rcText = mwndRect
  72.    DrawText hdc, mWnd.Tag, -1, rcText, DT_CENTER + DT_VCENTER + DT_WORDBREAK + DT_CALCRECT
  73.    Dim nTextHeight%, nTextWidth%
  74.    nTextHeight = rcText.bottom - rcText.top
  75.    nTextWidth = rcText.right - rcText.left
  76.    rcText.top = (mwndRect.bottom - nTextHeight) / 2
  77.    rcText.bottom = rcText.top + nTextHeight
  78.    rcText.left = (mwndRect.right - nTextWidth) / 2
  79.    rcText.right = rcText.left + nTextWidth
  80.    
  81.    ' Draw text
  82.    DrawText hdc, mWnd.Tag, -1, rcText, DT_CENTER + DT_VCENTER + DT_WORDBREAK
  83. End Sub
  84.  
  85. Private Sub IsgPaintSink_FramePaint(ByVal hdc As Long)
  86.    ' Do nothing
  87. End Sub
  88.  
  89. Private Function IsgPaintSink_GetFlags() As sgWindow.PaintFlag
  90.    IsgPaintSink_GetFlags = pfClientPaint
  91. End Function
  92.