Results 1 to 11 of 11

Thread: Can't Show Non-Modal Form...

Hybrid View

  1. #1
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Can't Show Non-Modal Form...

    Quote Originally Posted by clarkgriswald
    VB Code:
    1. Private Sub Timer1_Timer()
    2.  
    3.     Dim lProcessID As Long
    4.     Dim lID As Long
    5.    
    6.     Timer1.Interval = 0
    7.    
    8.     'get the process ID for prosper
    9.     lProcessID = GetWindowThreadProcessId(Me.hWnd, lID)
    10.    
    11.     'close any open message boxes
    12.     CloseMessageBox lProcessID
    13.    
    14.     Form2.Show   '<----- DANGER, WILL ROBINSON, DANGER
    15.  
    16. End Sub
    My shot in the dark would be the Form2.Show call in the timer loop is directly causing the error. If you call CloseMessageBox and it doesn't successfully close the MsgBox, then then it will try to show Form2 and blow up.

    Have you stepped through your code and made sure that it is closing the MsgBox where and when it should be closing?

  2. #2

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Exclamation Re: Can't Show Non-Modal Form...

    Yes, I have tested that the message box is being closed. I can't test it from VB due to the fact that once the message box is displayed timer events will NOT fire, but I have put in a DoEvents loop after the call the CloseMEssageBox and you will see the message box close...then hits the loop, then error pops up. Can't figure this out and it's driving me crazy, I need to handle this case.

  3. #3
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293
    [Edit]
    I agree with comment below. You just have the .Show call in the wrong location.
    Last edited by Fedhax; Oct 2nd, 2006 at 11:40 AM. Reason: Completely Misread The Code; Comment Was Wrong

  4. #4
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Can't Show Non-Modal Form...

    The MsgBox function is not finished before it has delivered the return value, i.e in the Form_Activate event. That's why. Move Form2.show to Form_Active() after the MsgBox function.

  5. #5

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Exclamation Re: Can't Show Non-Modal Form...

    Ok, we are getting somewhere, but i guess my problem is in the LARGER application, I will have no idea of the source of the message box, I just want to close the window...is there any way I can handle this situation?

  6. #6
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Can't Show Non-Modal Form...

    Quote Originally Posted by clarkgriswald
    Ok, we are getting somewhere, but i guess my problem is in the LARGER application, I will have no idea of the source of the message box, I just want to close the window...is there any way I can handle this situation?
    Do you have access to edit/modify the larger application?

    You are only going to run into problems where you will want to open a form after closing a MsgBox. Under that scenario, you will need to make sure that the routine that calls the MsgBox--in this case, Form_Activate--ends completely or your .Show call follows the MsgBox call.

    If you cannot know this information or edit the MsgBox calls, then you are might be up a creek. You could also look into this thread which runs into a similar problem with one of Outlook's modal windows. In his case, he wrote a 2nd program--an ActiveX EXE--to handle the modal form closing that you are trying to place in your program's timer. All it does is run an independent timer--since Outlook is a separate program from his program--to look for the window, simulate's end user input, and closes the window accordingly.

  7. #7

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Re: Can't Show Non-Modal Form...

    I actually do have access to the larger application, the one issue is that there are over 700 message box calls spread out over 10 separate referenced objects. This is an annoying issue to say the least, I may have to figure out a different approach altogether.

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