home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / mswindo / programm / misc / 1753 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  2.4 KB

  1. Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
  2. From: twbrown@PE-Nelson.COM (Tom W. Brown)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Recursion and Windows programming
  5. Message-ID: <601@lax.lax.pe-nelson.com>
  6. Date: 10 Sep 92 00:07:31 GMT
  7. References: <1992Sep8.111139.8820@iccgcc.decnet.ab.com>
  8. Sender: news@lax.pe-nelson.com
  9. Organization: PE-Nelson
  10. Lines: 45
  11.  
  12. In article <1992Sep8.111139.8820@iccgcc.decnet.ab.com>, schmidtg@iccgcc.decnet.ab.com writes:
  13. |> 
  14. |> 
  15. |> I am in the process of converting a DOS program to run in the MS Windows
  16. |> environment and I am having some difficulties.  The program uses a recursive
  17. |> search routine to find the solution to a problem.  The program also must do
  18. |> some screen output along the way.  The problem that I am having is in breaking
  19. |> up the recursive algorithm so that it can be executed piece-meal in the
  20. |> Windows event driven execution paradigm.  I want to run the algorithm
  21. |> during idle time processing and so I must only execute a portion each time.
  22. |> Since a recursive algorithm uses the machine stack, I don't know of an easy
  23. |> way to save context and restore it between processing without getting down
  24. |> and dirty.  I'm sure I'm not the only one who has encountered this problem.
  25. |> How have others solved it?
  26.  
  27. In the recursive routine that's doing the computation, put the following code
  28. somewhere at a convenient "yielding" point:
  29.  
  30.    ...
  31.    {
  32.       MSG msg;
  33.  
  34.       while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  35.          {
  36.          TranslateMessage(&msg);
  37.          DispatchMessage(&msg);
  38.          }
  39.    }
  40.    ...
  41.  
  42. This loop will process all messages in the queue before stopping, thus giving
  43. you idle time processing.  Note that this gets more complicated (but not much)
  44. if you have things like modeless dialogs up or have accelerators that need
  45. handling.  You may also have to worry about disabling application commands that
  46. might cause inadvertant reentry into the processing routine.
  47.  
  48. In any case, don't be afraid to have more than one location where messages
  49. are retrieved and dispatched.  I do it for exactly this reason.
  50.  
  51.  
  52. ----------------------------------------------------------------------------
  53. Tom Brown               |  "Strange women, lying in ponds, distributing
  54. PE Nelson Systems       |   swords is no basis for a system of government."
  55. twbrown@pe-nelson.com   |                    Monty Python and the Holy Grail
  56. ----------------------------------------------------------------------------
  57.