Results 1 to 26 of 26

Thread: [RESOLVED] Change Modal Form to Modeless while Beign Displayed

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Resolved [RESOLVED] Change Modal Form to Modeless while Beign Displayed

    I need to display a form as Modal but upon the button click on that form I need it to switch to modaless.

    I was thinking displaying it modaless and have the parent form loop until a process is complete but it would be easier to just switch states instead if possible.

    Note: This is a VBA UserForm but I can convert any solution to VBA.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    Easiest (and possibly only) way is hiding & then showing the form again,
    (but it will flicker)
    VB Code:
    1. ' modal to non-modal
    2. Me.Hide
    3. Me.Show
    4. '
    5. ' non-modal to modal
    6. Me.Hide
    7. Me.Show vbModal

    But as you want to change it while the form is being displayed (without hiding it ?), I don't think it is possible.
    Last edited by iPrank; Aug 5th, 2006 at 01:43 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    I tried something similar to that and was supossed to eliminate the flicker but it didnt work, still flickered but these two methods are very similar and do work just the stupid flicker.

    Thanks for the help but if anyone can get it to not flicker I would like to see it
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    Quote Originally Posted by RobDog888
    if anyone can get it to not flicker I would like to see it
    Me too.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Change Modal Form to Modeless while Beign Displayed

    Just experimenting, this seems to stop the flickering when changing modalness, but it does some kind of flicker when the modal Form2 is loaded Anyway..
    The idea: both forms (instances of the same Form) are loaded together, then when the button is pressed in the modal Form2 its unloaded and the modaless Form2 is shown. It seems there is not more flicker al least when changing modalness, because both forms are already loaded and visible.
    In Form1:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim Frm21 As Form2, Frm22 As Form2
    3.  
    4.     Set Frm21 = New Form2
    5.     Set Frm22 = New Form2
    6.    
    7.     Frm21.Left = Me.Left
    8.     Frm21.Top = Me.Top
    9.     Frm22.Left = Me.Left
    10.     Frm22.Top = Me.Top
    11.    
    12.     Frm21.Caption = "Modalness Form"
    13.     Frm22.Caption = "Modal Form"
    14.    
    15.     Set Frm22.FormToShow = Frm21
    16.    
    17.     Frm21.Show
    18.     Frm22.Show vbModal
    19. End Sub
    In Form2:
    VB Code:
    1. Private mFrmToShow  As Form
    2.  
    3. Public Property Set FormToShow(pFrm As Form)
    4.     Set mFrmToShow = pFrm
    5. End Property
    6.  
    7. Private Sub Command1_Click()
    8.     If Not (mFrmToShow Is Nothing) Then
    9.         mFrmToShow.Left = Me.Left
    10.         mFrmToShow.Top = Me.Top
    11.         Unload Me
    12.     End If
    13. End Sub
    Last edited by jcis; Aug 5th, 2006 at 03:43 AM.

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Hey quite cool but when a user may move an instance of form2 and then changes between modal and modeless the sync positioning of them will need to occur to reduct the incurred flicker. Much better results on my test forms but hopefully my vba userform's code will not interfere.

    Let me test it out on my userform now.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Just testing some more before I integrate it into the UserForm and tried using the .Move method as its less resource intensive (minimally) and it improved the switching between forms even more.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim Frm21 As Form2, Frm22 As Form2
    5.  
    6.     Set Frm21 = New Form2
    7.     Set Frm22 = New Form2
    8.    
    9. '    Frm21.Left = Me.Left
    10. '    Frm21.Top = Me.Top
    11. '    Frm22.Left = Me.Left
    12. '    Frm22.Top = Me.Top
    13.     Frm21.Move Me.Left, Me.Top
    14.     Frm22.Move Me.Left, Me.Top
    15.    
    16.     Frm21.Caption = "Modalness Form"
    17.     Frm22.Caption = "Modal Form"
    18.    
    19.     Set Frm22.FormToShow = Frm21
    20.    
    21.     Frm21.Show
    22.     Frm22.Show vbModal
    23. End Sub
    24.  
    25. Option Explicit
    26.  
    27. Private mFrmToShow  As Form
    28.  
    29. Public Property Set FormToShow(pFrm As Form)
    30.     Set mFrmToShow = pFrm
    31. End Property
    32.  
    33. Private Sub Command1_Click()
    34.     If Not (mFrmToShow Is Nothing) Then
    35. '        mFrmToShow.Left = Me.Left
    36. '        mFrmToShow.Top = Me.Top
    37.         mFrmToShow.Move Me.Left, Me.Top
    38.         Unload Me
    39.     End If
    40. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Change Modal Form to Modeless while Beign Displayed

    Found this, seems much better. Example: you want to change Form2 from modal to modalness or vice versa, pass the Hwnd of the Parent Form to MakeModal Function:
    In a module
    VB Code:
    1. Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
    2.  
    3. Public Enum MakeAsModal
    4.     Modal = 0
    5.     Modalless = 1
    6. End Enum
    7.  
    8. Public Sub MakeModal(ByRef frmParent As Form, ByVal isModal As MakeAsModal)
    9.     On Error Resume Next
    10.     Dim RetVal As Long
    11.     RetVal = EnableWindow(frmParent.hwnd, isModal)
    12. End Sub
    In Form1
    VB Code:
    1. Private Sub Command1_Click()
    2.     Form2.Show
    3. End Sub
    In Form2
    VB Code:
    1. Private Sub Command1_Click()
    2.     MakeModal Form1, Modal
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     MakeModal Form1, Modalless
    7. End Sub

    Edit: It works, but you wont get the typical Flash window and "beep" that VB6 makes when clicking a Form without Focus, not sure about VBA.
    Last edited by jcis; Aug 5th, 2006 at 04:11 AM.

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Thats another good one but unfortunately in my project's VBA UserForm doesnt have a parent or secondary form. Its only a single UserForm.

    Also, with the previous example, I have controls on the form that would also need to be updated/sync'd with the other instance just before the switch. Hmm...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Change Modal Form to Modeless while Beign Displayed

    This works fine in an UserForm in Excel (using 1 UserForm, Excel App is the Parent)
    VB Code:
    1. Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
    2.  
    3. Private Sub CommandButton1_Click()
    4.     EnableWindow Application.hwnd, 1
    5. End Sub
    6.  
    7. Private Sub CommandButton2_Click()
    8.     EnableWindow Application.hwnd, 0
    9. End Sub
    Last edited by jcis; Aug 5th, 2006 at 12:52 PM.

  11. #11
    Lively Member
    Join Date
    Apr 2004
    Posts
    113

    Re: Change Modal Form to Modeless while Beign Displayed

    Manually create your modal form by making it a "Always On Top" form. When you want to turn it off remove the "Always On Top"

    VB Code:
    1. Public Const SWP_NOMOVE  As Long = &H2
    2. Public Const SWP_NOSIZE  As Long = &H1
    3. Public Const flags  As Long = SWP_NOMOVE Or SWP_NOSIZE
    4. Public Const HWND_TOPMOST  As Long = -1
    5. Public Const HWND_NOTOPMOST  As Long = -2
    6.  
    7. Public Declare Function SetWindowPos Lib "user32.dll" (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
    8.  
    9. Public Sub SetTopMostWindow(lngHwnd As Long, blnTopMost As Boolean)
    10.  
    11. On Error Resume Next
    12.  
    13. If blnTopMost Then
    14.     Call SetWindowPos(lngHwnd, HWND_TOPMOST, 0, 0, 0, 0, flags)
    15. Else
    16.     Call SetWindowPos(lngHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, flags)
    17. End If
    18.  
    19. End Sub

  12. #12
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    Quote Originally Posted by rami.haddad
    Manually create your modal form by making it a "Always On Top" form. When you want to turn it off remove the "Always On Top"
    Sorry. I disagree.
    My users will not like it if my app opens an always-on-top form when they are multitasking.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Being an "Always on top" form does not make it modal. The Modal characteristic is important for me to have just as much as changing it to modeless.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Change Modal Form to Modeless while Beign Displayed

    Rob, just to be "updated" with this thread, if you have only one UserForm without parent or secondary form then the Application object shouldnt be its Parent? if this is the case, post 10 couldnt be a solution?
    The only VBA I know is part of MSExcel or MSWord but as you said "no parent" maybe you are doing something different.
    Last edited by jcis; Aug 5th, 2006 at 01:15 PM.

  15. #15

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    I must have misread post 10 last night, well actually this morning. So I will try it again but the UserForm is in Outlook and I could use FindWindow to get the apps handle so I'll try to tweak it for Outlook.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    I tried to change DS_MODALFRAME style, (and other experiments on style bits) but that didn't work.

    I've taken a look at Dialog Box Topics(Visual C++ Programmer's Guide)
    From there I found that (in VC++), modal and non-nodal dialog boxes cre created by 2 different function.
    To create a modal dialog box, call either of the two public constructors declared inCDialog. Next, call the dialog object’sDoModal member function to display the dialog box and manage interaction with it until the user chooses OK or Cancel. This management by DoModal is what makes the dialog box modal. For modal dialog boxes, DoModal loads the dialog resource.

    For a modeless dialog box, you must provide your own public constructor in your dialog class. To create a modeless dialog box, call your public constructor and then call the dialog object’sCreate member function to load the dialog resource. You can call Create either during or after the constructor call. If the dialog resource has the property WS_VISIBLE, the dialog box appears immediately. If not, you must call itsShowWindow member function
    And,
    Quote Originally Posted by MSDN
    Life Cycle of a Dialog Box

    During the life cycle of a dialog box, the user invokes the dialog box, typically inside a command handler that creates and initializes the dialog object, the user interacts with the dialog box, and the dialog box closes.

    For modal dialog boxes, your handler gathers any data the user entered once the dialog box closes. Since the dialog object exists after its dialog window has closed, you can simply use the member variables of your dialog class to extract the data.

    For modeless dialog boxes, you may often extract data from the dialog object while the dialog box is still visible. At some point, the dialog object is destroyed; when this happens depends on your code.
    So, I guess, in case of VB, IUnknown or some other culprit calls the DoModal method.
    Quote Originally Posted by MSDN
    Destroying the Dialog Box

    Modal dialog boxes are normally created on the stack frame and destroyed when the function that created them ends. The dialog object’s destructor is called when the object goes out of scope.

    Modeless dialog boxes are normally created and owned by a parent view or frame window — the application’s main frame window or a document frame window. The defaultOnClose handler callsDestroyWindow, which destroys the dialog-box window. If the dialog box stands alone, with no pointers to it or other special ownership semantics, you should overridePostNcDestroy to destroy the C++ dialog object. You should also overrideOnCancel and call DestroyWindow from within it. If not, the owner of the dialog box should destroy the C++ object when it is no longer necessary.
    So, I think, unless we can find a way to exit from the function, from where VB called DoModal (or similar) method, we can't make the form non-modal properly.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  17. #17
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    ...and I tried to remove WS_DISABLED from the parent/caller form. But that didn't work either.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  18. #18

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Maybe because I havent had my morning coffee yet but for the way I need my Outlook UserForm to work, post 8 and 10 dont work for me. The UserForm is still modal and not releasing the process to the parent to continue on.

    I think for practical purposes I can live with the minor flicker from the hide/show method. But I would like to see if its possible still.
    [/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    The modal form will not release the control until it is destroyed.(See the middle MSDN quote).

    (I GUESS) When we use .Hide, only the WINDOW (dialog box ?) gets destroyed. The dialog object (Form object ?) still remains intact. That's why control goes back to the caller form.
    Quote Originally Posted by MSDN
    For modal dialog boxes, your handler gathers any data the user entered once the dialog box closes. Since the dialog object exists after its dialog window has closed, you can simply use the member variables of your dialog class to extract the data.
    Last edited by iPrank; Aug 5th, 2006 at 02:07 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  20. #20

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Ah, ok.

    * Going for first cup of coffee now *
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Change Modal Form to Modeless while Beign Displayed

    It is time to call Moeur for help.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  22. #22

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Or Joacim Andersson. Havent seen him online yet today
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Change Modal Form to Modeless while Beign Displayed

    You rang

    I don't know how much help I can be to this thread since I'm currently sitting on a hotel room with a computer that doesn't have VB or Outlook installed, so I can't test anything.

    With that excuse out of the way, here goes: First of all, as you've already discussed, there is no way you can switch from a (true) modal to a modeless behaviour without first hiding the Form. The implementation in VB is a bit different from how it works with an MFC application which stores the dialogs as resources, but the basic idea is the same. The message pump for the modal Form keeps looping and doesn't return until the Form is hidden or destroyed. None of the style bits for a Form is changed when you show it modally. I'm not 100% sure about UserForms in VBA but they should work in a simular fashion as the VB Forms does.

    You can simulate a modal Form in the fashion jcis showed by disabling the caller window. However that will only make the Form look modal to the user, the code still runs in the parent and as I understood it your main concern was that the code should not continue until the UserForm was switched to modeless. The other idea jcis had about loading two instances of your Form, one modeless and one modal, would also work however as you've mentioned there would be a problem if the user moves the modal Form. The only way to get around that would be to subclass the modal Form and check for the WM_MOVE and WM_MOVING messages and move your modeless Form accordingly. However that might seem like a bit of a overkill just to get rid of some flickering.

    Another idea that hit me, which I can't test since I currently don't have VB, would be to call LockWindowUpdate on the desktop window... Maybe (I don't have a clue) that will prevent the screen from being redrawn during the few milliseconds it takes to hide and show your Form.
    VB Code:
    1. Call LockWindowUpdate(GetDesktopWindow)
    2. Me.Hide
    3. Me.Show
    4. Call LockWindowUpdate(0) 'Unlock it. You do [b]not[/b] want to keep the desktop locked :)

  24. #24

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Change Modal Form to Modeless while Beign Displayed

    Yes, I had tried that earlier but on the VBA UserForms handle and its about the best I can get. The LockWindowUpdate passing the GetDesktopWindow does not flicker the captionbar but the client area of the userform does go al white and then back for an effect that seems worse then the previous method.

    I think for the most part using the lockwindowupdate passing the forms handle and then hiding and reshowing is the best solution for your $.

    Thanks Guys for all your help and Thanks Joacim for seeing the Bat Signal.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Change Modal Form to Modeless while Beign Displayed

    Quote Originally Posted by RobDog888
    The LockWindowUpdate passing the GetDesktopWindow does not flicker the captionbar but the client area of the userform does go al white and then back
    I was afraid something like that would happen since only the non-client area is painted directly on the desktop while the Form itself is responsible for the client area. But as I said, I had no way of testing my suggestion. Unfortunatly you can only lock one window at the time.

  26. #26

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: [RESOLVED] Change Modal Form to Modeless while Beign Displayed

    I used Spy++ and had found that a VBA UserForm contains two windows. A main form window and a nested client area window. So maybe thats why the client area of the form would not lock for the update.

    I do appreciate the help though
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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