PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] TopMost vs. vbModal for progress form-VBForums
Results 1 to 13 of 13

Thread: [RESOLVED] TopMost vs. vbModal for progress form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    338

    Resolved [RESOLVED] TopMost vs. vbModal for progress form

    I have a form to display the status of longer lasting calculations.
    It shows progress bars and some text info.
    While the calculations are in the works, the progress form shall stay and block the main form for input.

    Easy when I show the progress form vbModal.
    But when I do so, the progress form blocks all other processes.
    So I show the form non-modal, and set the z order SetWindowPos Me.hWnd, HWND_TOPMOST...

    This kind of works, but I have to disable the other form.
    Works ok as well.
    Not so neat, because the flashing of the progress form is not there when I click the main form - could be better.

    But TopMost is really TopMost and is displayed above ALL other apps.
    Not really acceptable.

    The best would be a behavior like with vbModal, but not blocking other forms and processes.

    How do you do things like that?
    Or other ideas?

    Thanks,
    Karl

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,496

    Re: TopMost vs. vbModal for progress form

    Hi Karl,

    I read your post about three times, and I'm still unclear about what you want. That leads me to believe that possibly you are also unclear on what you want. However, if you could throw together an example of the problem you're having, that would probably help a great deal. For instance, just make some long loop (possibly with a Sleep API call in it) that illustrates the problem. Then, we could understand what you're after.

    I'm also guessing that you've sprinkled DoEvents in this "longer lasting calculations". Personally, I always think that's a bad idea, unless it's specifically setup to detect a "Cancel" button's click. If it's really that long lasting, you may want to think about spawning it to another process.

    Also, I've got a frmWorking form (and corresponding Working procedure and WorkingLabel procedure in a BAS module) that I use all the time. They work perfectly for me, but my primary application is setup such that only one or two other forms are shown at any specific time. In other words, it's rather specific to the way I do things. Therefore, I'm somewhat reluctant to post it. However, if you think it'll help, I will.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  3. #3
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    679

    Re: TopMost vs. vbModal for progress form

    Here is a basic idea how to do progress dialog with a modal form and an event

    Main form:
    thinBasic Code:
    1. '--- Form1
    2. Option Explicit
    3.  
    4. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    5.  
    6. Private WithEvents m_oProgress As Form2
    7.  
    8. Private Sub cmdDoWork_Click()
    9.     Set m_oProgress = New Form2
    10.     m_oProgress.Show vbModal, Me
    11. End Sub
    12.  
    13. Private Sub m_oProgress_Start()
    14.     Dim lIdx        As Long
    15.    
    16.     For lIdx = 1 To 20
    17.         '-- do some work
    18.         Call Sleep(100)
    19.         DoEvents
    20.         If m_oProgress.Cancelled Then
    21.             GoTo QH
    22.         End If
    23.     Next
    24. QH:
    25.     Unload m_oProgress
    26.     Set m_oProgress = Nothing
    27. End Sub
    Progress form:
    thinBasic Code:
    1. '--- Form2
    2. Option Explicit
    3.  
    4. Event Start()
    5.  
    6. Private m_bActivated        As Boolean
    7. Private m_bCancelled        As Boolean
    8.  
    9. Property Get Cancelled() As Boolean
    10.     Cancelled = m_bCancelled
    11. End Property
    12.  
    13. Private Sub cmdCancel_Click()
    14.     m_bCancelled = True
    15.     cmdCancel.Enabled = False
    16. End Sub
    17.  
    18. Private Sub Form_Activate()
    19.     If Not m_bActivated Then
    20.         m_bActivated = True
    21.         RaiseEvent Start
    22.     End If
    23. End Sub
    The progress form raises Start event once so the main form can perform the long-running task then, while pumping msgs and checking if the user signalled to cancel operation.

    The progress form is modal so the main form (or any other one) cannot be activated and "flashes" and focuses progress form, indicating that an operation is in progress.

    You can add props/methods on progress form to setup text, captions, percentages, etc.

    cheers,
    </wqw>

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    338

    Re: TopMost vs. vbModal for progress form

    Hello Elroy

    Quote Originally Posted by Elroy View Post
    Hi Karl,
    I read your post about three times, and I'm still unclear about what you want. That leads me to believe that possibly you are also unclear on what you want.
    Thanks for the effort Elroy, and yes, I could have expressed myself better.
    Anyway, I know what I want.

    See attached a very stripped down example.
    Progress.zip
    The main form starts a calculation and shows the progress form.
    Let it run.
    While the progress form is there, we can't click the main form - ok.

    The problem is seen when you switch to another app, let's say the browser.
    The progress form is on top of all, not only on top of the main form.

    This is not wanted.
    The progress form should be over the main form only.
    Like with vbModal.

    I don't know how to achieve that.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    338

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by wqweto View Post
    Here is a basic idea how to do progress dialog with a modal form and an event
    The progress form raises Start event once so the main form can perform the long-running task then, while pumping msgs and checking if the user signalled to cancel operation.
    Interesting idea to start the calculation from the progress form!
    I fear I can't easily use it like this, as I have 6531 places in my code that would have to be changed then.
    I'll check more deeply.


    Thank you wqweto

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    338

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by Karl77 View Post
    The progress form should be over the main form only.
    Like with vbModal.
    I don't know how to achieve that.
    Now I have an idea, and it seems to work.

    I don't do TopMost.
    In the progress form there is the timer that shows the progress.
    In the same timer, or one with a smaller interval, I do ZOrder.


    EDIT:
    Works ok in the IDE, but not as EXE.
    Hmm.

    EDIT2:
    I was not very clear again...
    It works ok with a single Desktop.
    When I switch to another Desktop, then the progress form is seen.
    Switching to another Desktop means the Win10 Virtual Desktops.
    Last edited by Karl77; Aug 9th, 2018 at 05:25 AM.

  7. #7
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    679

    Re: TopMost vs. vbModal for progress form

    The easiest way to peg the ZOrder of two forms, e.g. frmProgress to be on top of frmMain, is to use OwnerForm parameter of the Show method. For instance frmProgress.Show OwnerForm:=frmMain will show modeless frmProgress but will not allow frmMain to become on top of it. Just wanted to make sure you understand the consequences of form ownership here.

    In my sample I'm using vbModal with Show method but *still* passing OwnerForm param just to prevent a possible run-time bug when a modal form is display *behind* other non-active non-modal forms, effectively driving the end-user mad for not being able to dismiss this modal form.

    From my experience using the pattern with the starting event above is the way to go with progress forms. Another thing not clear from the sample is that in main form you can have *multiple* progress form declarations if your are going to handle multiple long-running tasks, e.g.

    thinBasic Code:
    1. Private WithEvents m_oProgressTask1 As Form2
    2. Private WithEvents m_oProgressAnotherLongTask As Form2
    3. Private WithEvents m_oProgressSayGoodbye As Form2

    And the usage pattern for these multiple progess form declarations is always split in two places:
    thinBasic Code:
    1. . . .
    2.     Set m_oProgressXxx = New Form2
    3.     m_oProgressXxx.Show vbModal, Me
    4. End Sub
    5.  
    6. Private Sub m_oProgressXxx_Start()
    7.     '--- do work here
    8.     Unload m_oProgressXxx
    9.     Set m_oProgressXxx = Nothing
    10. End Sub

    Note that at each point in time you have only one m_oProgressXxx variable instantiated at max. If you get two of these set, then you are doing two long-running tasks in parallel (or have some bug in DoEvents handling:-))

    cheers,
    </wqw>

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,440

    Re: TopMost vs. vbModal for progress form

    Karl, you don't need top most to have the form stay above your main form. Simply open the form owned by the main form. That way it isn't modal and is always displayed above the owner.

    frmProgress.Show , Me << where Me is the main form

    umm, wqweto beat me to it
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    969

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by Karl77 View Post
    Easy when I show the progress form vbModal.
    But when I do so, the progress form blocks all other processes.
    I think you are confused. A modal form doesn't block the other processes.

    What may be blocking the other processes is the process itself, that long process that you are executing.

    And what other processes are you talking about, anyway?

  10. #10
    Member
    Join Date
    Jun 2018
    Posts
    33

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by Karl77 View Post
    Hello Elroy



    Thanks for the effort Elroy, and yes, I could have expressed myself better.
    Anyway, I know what I want.

    See attached a very stripped down example.
    Progress.zip
    The main form starts a calculation and shows the progress form.
    Let it run.
    While the progress form is there, we can't click the main form - ok.

    The problem is seen when you switch to another app, let's say the browser.
    The progress form is on top of all, not only on top of the main form.

    This is not wanted.
    The progress form should be over the main form only.
    Like with vbModal.

    I don't know how to achieve that.
    If you still need this type of behavior with your example, just consider subclassing. See the attachment.

    Note: Always consider the recommended solutions in this thread. The subclassing stuff is just for an Idea to your example only.
    Attached Files Attached Files
    Last edited by PGBSoft; Aug 9th, 2018 at 06:04 AM.

  11. #11
    Fanatic Member
    Join Date
    Feb 2017
    Posts
    969

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by Karl77 View Post
    Hello Elroy



    Thanks for the effort Elroy, and yes, I could have expressed myself better.
    Anyway, I know what I want.

    See attached a very stripped down example.
    Progress.zip
    The main form starts a calculation and shows the progress form.
    Let it run.
    While the progress form is there, we can't click the main form - ok.

    The problem is seen when you switch to another app, let's say the browser.
    The progress form is on top of all, not only on top of the main form.

    This is not wanted.
    The progress form should be over the main form only.
    Like with vbModal.

    I don't know how to achieve that.
    As others already suggested: show the form as owned but not modal and set the main form Enabled = False.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    338

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by wqweto View Post
    The easiest way to peg the ZOrder of two forms, e.g. frmProgress to be on top of frmMain, is to use OwnerForm parameter of the Show method. For instance frmProgress.Show OwnerForm:=frmMain will show modeless frmProgress but will not allow frmMain to become on top of it. Just wanted to make sure you understand the consequences of form ownership here.
    I forgot to pass the form on Show.
    I did so now, and everything works fine.

    Solved.
    Thanks to all of you,
    Karl

  13. #13
    Addicted Member
    Join Date
    Aug 2011
    Posts
    188

    Re: TopMost vs. vbModal for progress form

    Quote Originally Posted by wqweto View Post
    The easiest way to peg the ZOrder of two forms, e.g. frmProgress to be on top of frmMain, is to use OwnerForm parameter of the Show method. </wqw>
    Never knew that! This is very helpful for me.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width