Results 1 to 6 of 6

Thread: Multiple Instances of Forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Okay,

    I have a main form called frmMain. I have another hidden form called frmStar. Now what I want to do is create multiple instances of frmStar. I would like at least 20 frmStar's to be on the screen at once. How would I do this?
    ?

    Thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Code:
    Private Sub Form_Load()
     Dim f(1 To 20) As Form
     Dim iCt As Integer
     
     For iCt = LBound(f) To UBound(f)
        
        Set f(iCt) = New frmStar
        
        f(iCt).Show
        
    Next iCt
     
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Okay that works good, however, I need to have the forms show up in random posistions. Not just all on top of each ohter.

    The effect that im going for is having a bunch of frms start at the top of the screen then slowly move down the screen.

    I have the frmStar shaped as a star, and it is always on top. here is my code so far.

    Module:
    Code:
    Option Explicit
    
    Global Const WINDING = 2
    Global Const ALTERNATE = 1
    Global Const RGN_OR = 2
    
    Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    
    Declare Function CreateEllipticRgn& Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
    
    Declare Function CreatePolyPolygonRgn& Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long)
    
    
    
    
    
    '000000000000000000000000000000000000000
    Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
        Global Const conHwndTopmost = -1
        Global Const conSwpNoActivate = &H10
        Global Const conSwpShowWindow = &H40
    
    Public Function on_top(hwndTop As Long)
    SetWindowPos hwndTop, conHwndTopmost, 100, 100, 400, 141, conSwpNoActivate Or conSwpShowWindow
    End Function
    Here is form Code
    Code:
    Option Explicit
    Dim Star(5) As POINTAPI
    Dim lReigon As Long
    Dim lReigon1 As Long
    Dim lReigon2 As Long
    Dim lResult As Long
    
    
    
    Private Sub cmdStars_Click()
    Load frmStar
       
    '       Make the form big enough
            frmStar.Width = 500 * Screen.TwipsPerPixelX
            frmStar.Height = 500 * Screen.TwipsPerPixelY
            
            'Polygon region  - This draws a star
            Star(0).x = 231:  Star(0).y = 12
            Star(1).x = 220:  Star(1).y = 57
            Star(2).x = 259:    Star(2).y = 31
            Star(3).x = 209:    Star(3).y = 31
            Star(4).x = 245:    Star(4).y = 57
            Star(5).x = 231:    Star(5).y = 12
            lReigon = CreatePolygonRgn(Star(0), 6, WINDING)
            
            ' set the window reigon
            lResult = SetWindowRgn(frmStar.hwnd, lReigon, True)
            frmStar.Show
            on_top frmStar.hwnd
    End Sub
    
    Private Sub Form_Load()
    frmMain.Visible = False
    cmdStars_Click
    End Sub
    Any ideas?

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Here is a start to what you are looking for, however you are definitely gonna want to tweak it. Also the on_top code produced some undesirable effects, so I commented it out and I had to move some things around.

    In the module...
    Code:
    Option Explicit
    
    Global Const WINDING = 2
    Global Const ALTERNATE = 1
    Global Const RGN_OR = 2
    
    Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    
    Declare Function CreateEllipticRgn& Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
    
    Declare Function CreatePolyPolygonRgn& Lib "gdi32" (lpPoint As POINTAPI, lpPolyCounts As Long, ByVal nCount As Long, ByVal nPolyFillMode As Long)
    
    
    
    
    
    '000000000000000000000000000000000000000
    Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
        Global Const conHwndTopmost = -1
        Global Const conSwpNoActivate = &H10
        Global Const conSwpShowWindow = &H40
    
    Public Function on_top(hwndTop As Long)
    SetWindowPos hwndTop, conHwndTopmost, 100, 100, 400, 141, conSwpNoActivate Or conSwpShowWindow
    End Function
    In the form named frmMain

    Code:
    Option Explicit
    
    
    Private Sub cmdStars_Click()
    Dim f(1 To 20) As Form
    Dim iCt As Integer
    
    For iCt = LBound(f) To UBound(f)
    
            Set f(iCt) = New frmStar
            
            Load f(iCt)
            
            'on_top f(iCt).hwnd
            
    Next iCt
    
    End Sub
    
    Private Sub Form_Load()
    frmMain.Visible = False
    cmdStars_Click
    End Sub
    In the form named frmStar (also add a Timer and set it's interval to 1)

    Code:
    Dim Star(5) As POINTAPI
    Dim lReigon As Long
    Dim lReigon1 As Long
    Dim lReigon2 As Long
    Dim lResult As Long
    Dim speed As Integer
    
    Private Sub Form_Load()
    
            Randomize
            
    '       Make the form big enough
            Me.Width = 500 * Screen.TwipsPerPixelX
            Me.Height = 500 * Screen.TwipsPerPixelY
            Me.Left = Rnd * Screen.Width
            Me.Top = 0
           
            'Polygon region  - This draws a star
            Star(0).x = 231:  Star(0).y = 12
            Star(1).x = 220:  Star(1).y = 57
            Star(2).x = 259:    Star(2).y = 31
            Star(3).x = 209:    Star(3).y = 31
            Star(4).x = 245:    Star(4).y = 57
            Star(5).x = 231:    Star(5).y = 12
            lReigon = CreatePolygonRgn(Star(0), 6, WINDING)
            
            ' set the window reigon
            lResult = SetWindowRgn(Me.hwnd, lReigon, True)
            
            speed = (Rnd * 100) + 50
            
            Me.Show
            
            DoEvents
            
    End Sub
    
    Private Sub Timer1_Timer()
        
        If Me.Top > Screen.Height Then Me.Top = 0
        
        Me.Top = Me.Top + speed
        
    End Sub
    Good Luck!
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    Thanks YoungBuck,
    It works pretty good. Still need to edit some stuff, but this really helped.

    Thanks alot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width