How to break out of a event handling loop? Detect a minimizedwindow?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raylopez99

    How to break out of a event handling loop? Detect a minimizedwindow?

    See comment below. This is a simple problem but I'm a little rusty.
    How to break out of a event loop (here _Paint)? I've tried if/else,
    case, etc but not quite what I want--I keep getting the JIT system
    event exception handler saying "zero area!", or, worse, the Paint loop
    refuses to run at all; what I want to do is simply break out of the
    _Paint loop, and (optionally) show a MessageBox.

    This error happens everytime the "this.ClientRec tange" of the window
    being painted becomes zero, that is, everytime this window is
    minimized.

    So one way around this (perhaps the solution to this problem) is to
    set up code so that when a window is minimized, _Paint() is not
    executed. Or is there a simplier way?

    RL

    private void Form2MyDialogBo x_Paint(object sender, PaintEventArgs e)
    {


    Rectangle rect = this.ClientRect angle;
    int cx = rect.Width;
    int cy = rect.Height;
    bool TrueOrFalseZero Rect;

    if ((cx != 0) || (cy !=0)) { TrueOrFalseZero Rect = false; } else
    { TrueOrFalseZero Rect = true; throw new ArgumentExcepti on("zero
    area!"); }

    // AT THIS POINT IN PAINT, IF THE RECT IS ZERO AREA, I WOULD LIKE TO
    BREAK OUT OF PAINT...THE BELOW TRY/CATCH DOESN'T WORK

    try
    {
    // stuff deleted here, not important, basically you get a divide by
    zero error when cx=0

    }
    catch (ArgumentExcept ion ex)
    {
    MessageBox.Show (ex.ToString()) ;
    }

    finally
    {
    brush.Dispose() ; //clean up brush resources
    }


    }
  • Ben Voigt [C++ MVP]

    #2
    Re: How to break out of a event handling loop? Detect a minimized window?



    "raylopez99 " <raylopez99@yah oo.comwrote in message
    news:a6aa7b29-fa8e-439c-8201-6e4b92fe894d@d7 7g2000hsb.googl egroups.com...
    See comment below. This is a simple problem but I'm a little rusty.
    How to break out of a event loop (here _Paint)? I've tried if/else,
    case, etc but not quite what I want--I keep getting the JIT system
    event exception handler saying "zero area!", or, worse, the Paint loop
    refuses to run at all; what I want to do is simply break out of the
    _Paint loop, and (optionally) show a MessageBox.
    >
    This error happens everytime the "this.ClientRec tange" of the window
    being painted becomes zero, that is, everytime this window is
    minimized.
    >
    So one way around this (perhaps the solution to this problem) is to
    set up code so that when a window is minimized, _Paint() is not
    executed. Or is there a simplier way?
    >
    RL
    >
    private void Form2MyDialogBo x_Paint(object sender, PaintEventArgs e)
    {
    >
    >
    Rectangle rect = this.ClientRect angle;
    int cx = rect.Width;
    int cy = rect.Height;
    bool TrueOrFalseZero Rect;
    >
    if ((cx != 0) || (cy !=0)) { TrueOrFalseZero Rect = false; } else
    { TrueOrFalseZero Rect = true; throw new ArgumentExcepti on("zero
    area!"); }
    Well, you were outside the try/catch when you threw an exception, so it will
    hit the OS and do very bad things. Why not show your MessageBox and return
    immediately instead of throwing?
    >
    // AT THIS POINT IN PAINT, IF THE RECT IS ZERO AREA, I WOULD LIKE TO
    BREAK OUT OF PAINT...THE BELOW TRY/CATCH DOESN'T WORK
    >
    try
    {
    // stuff deleted here, not important, basically you get a divide by
    zero error when cx=0
    >
    }
    catch (ArgumentExcept ion ex)
    {
    MessageBox.Show (ex.ToString()) ;
    }
    >
    finally
    {
    brush.Dispose() ; //clean up brush resources
    }
    >
    >
    }

    Comment

    • raylopez99

      #3
      Re: How to break out of a event handling loop? Detect a minimizedwindow ?

      On Jul 6, 3:55 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
      Well, you were outside the try/catch when you threw an exception, so it will
      hit the OS and do very bad things.  Why not show your MessageBox and return
      immediately instead of throwing?
      >
      Thanks Ben Voigt! Indeed, simply placing the 'throw' * inside the
      'try' block solved the problem.

      And if you comment out the exception handling, it solves the problem
      with no distraction to the user (since a minimized window is not
      really an error)


      RL

      * this code:
      if (TrueOrFalseZer oRect)
      {
      // MessageBox.Show ("zero_area1!") ;
      throw new ArgumentExcepti on("zero area!");
      }

      Comment

      • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

        #4
        Re: How to break out of a event handling loop? Detect a minimized

        You shouldnt really throw when there are other options, error handling is
        expensive. Why not just have this:


        if ((cx != 0) || (cy !=0)) {
        TrueOrFalseZero Rect = false;
        } else {
        TrueOrFalseZero Rect = true;
        return ;}


        Its the better option, surely?
        --
        Ciaran O''Donnell
        try{ Life(); } catch (TooDifficultException) { throw Toys(); }



        "raylopez99 " wrote:
        On Jul 6, 3:55 pm, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
        >
        Well, you were outside the try/catch when you threw an exception, so it will
        hit the OS and do very bad things. Why not show your MessageBox and return
        immediately instead of throwing?
        >
        Thanks Ben Voigt! Indeed, simply placing the 'throw' * inside the
        'try' block solved the problem.
        >
        And if you comment out the exception handling, it solves the problem
        with no distraction to the user (since a minimized window is not
        really an error)
        >
        >
        RL
        >
        * this code:
        if (TrueOrFalseZer oRect)
        {
        // MessageBox.Show ("zero_area1!") ;
        throw new ArgumentExcepti on("zero area!");
        }
        >

        Comment

        • raylopez99

          #5
          Re: How to break out of a event handling loop? Detect a minimized

          On Jul 7, 6:11 am, Ciaran O''Donnell
          <CiaranODonn... @discussions.mi crosoft.comwrot e:
          You shouldnt really throw when there are other options, error handling is
          expensive. Why not just have this:
          Yes, that's much better; for this example, I was using somebody else's
          code and for demonstration purposes I was trying to modify it to work
          with try/catch.

          RL

          Comment

          Working...