Results 1 to 6 of 6

Thread: MDI & SDI switching

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3

    Question

    i've got a question:
    how can i change from MDI to SDI(and back), runtime or with restarting?
    i know it is possible, because Visual Basic itselvses also uses this. (in Options)

    i don't mind if i have to restart the application.

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    I don't think even APIs can change that around. Besides, MDIForms are different classes than Forms, its not just a style flag or something, so you'd have trouble there anyway.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    True enough indeed. But if there is a setting which chooses whether you use an SDI version of a form or an MDI version of a form though you have to keep 2 copies of each form, you can choose to have either at run time (you have to reload the project ...) The only forms you mess with are the MDI Children. Here is some sample code that I slopped together to show you what I mean.
    Start a New Project.

    Add Another Form (Form2)
    Add An MDIForm (MdiForm1)
    Set Form1's MDIChild to True.

    Set the project to run with the MDIForm1.
    Add a Menu to MDIForm1, Name it Test, Set it's caption to Test.
    Add a Picturebox to MDIForm1 (Picture1)

    Place the following code in the MDIForm1:
    Code:
    Dim Choice As Boolean
    
    Private Sub MDIForm_Load()
        Dim Temp As String
        Temp = InputBox("SDI or MDI?", , "MDI")
        If Temp = "SDI" Then
            Choice = True
            Me.Height = 0 + (Picture1.Height * 2) - 90
            Else
            Choice = False
        End If
    End Sub
    
    Private Sub MDIForm_Resize()
        If Choice = True Then
            If Me.WindowState > 1 Then
                Me.WindowState = 0
                Me.Top = 0
                Me.Left = 0
                Me.Width = Screen.Width
                Exit Sub
            End If
            If Me.Height <> 0 + (Picture1.Height * 2) - 90 And _
            Me.WindowState < 1 Then
                Me.Height = 0 + (Picture1.Height * 2) - 90
            End If
        End If
    End Sub
    
    Private Sub test_Click()
        If Choice = True Then
            Dim FormSDI As New Form2
            Set FormSDI = New Form2
            FormSDI.Show
            Else
            Dim FormMDI As New Form1
            Set FormMDI = New Form1
            FormMDI.Show
        End If
    End Sub
    Place this Code in the form load event of Form1 & Form2:
    Code:
    Private Sub Form_Load()
        MsgBox "I have been loaded"
    End Sub
    When you start up the project, you are asked to choose either MDI or SDI. If you use the default of MDI, everytime you hit the test button, you reieve the message "I have been loaded" and when you click ok, the form displays in the MDI parent area.

    If you choose SDI (by typing it in), you will recieve a 'minimized' mdi form, which is just the height of the titlebar, picturebox, and menu. If you try to resize the window, it snaps back to that height. If you hit maximize, it moves to the top of the screen and changes it's width to match the screen width, you are still unable to resize it. If you hit minimize, it will minimize to the tray. If you click on test, Form2 displays as an SDI window. You can set this to vbModal if you wish ...

    As you can see, the idea is possible, you just need to change the inputbox to a setting (from the registry, ini file, or whatnot, possibly even a menu item). You keep MDIForm as the main form, you just swap to a new Form style.

    Hope this clears that up.

    -Excalibur

    [Edited by ExcalibursZone on 09-29-2000 at 01:37 PM]

  4. #4
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    I did a little tinkering with the code and found that with a few case statements a new menu item and a new subroutine, you can change modes during runtime. What I mean by changing mode is the pseudo swap between MDI & SDI It's ugly, yes, but it works ...

    You could also set up another form called SDIMain, add a module and start the project off of sub main(). Based on the users saved setting, the program could launch either the sdimain form or the mdiform1 and give you the same functionality as the VB IDE. Though doing it this way means that you can't swap between the two form styles at runtime either ...

    There might be some minor intricate details I have missed (I'm at work and have little time to code this properly atm) but this should get the general effect down.

    -Excalibur

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3
    ok. thanks for the quick replies. i'll see if i can manage this SDI/MDI switching

  6. #6
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    wait! I don't know if this will work, but it may be worth trying. If you use CreateWindow/CreateWindowEx and a bunch of other calls, you can get a basic MDI window to exist. I know this works; the shaky part is here: I think if you can find a style flag on the windows or an API that will make your forms MDIChildren without using the VB property, then you can set them as children of the MDI window on the fly, as well as destroy the MDI window and leave the little guys standing.

    Again, I don't know if its feasible, but give it a shot.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

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