home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!lax.pe-nelson.com!lax!twbrown
- From: twbrown@PE-Nelson.COM (Tom W. Brown)
- Newsgroups: comp.os.ms-windows.programmer.misc
- Subject: Re: Recursion and Windows programming
- Message-ID: <601@lax.lax.pe-nelson.com>
- Date: 10 Sep 92 00:07:31 GMT
- References: <1992Sep8.111139.8820@iccgcc.decnet.ab.com>
- Sender: news@lax.pe-nelson.com
- Organization: PE-Nelson
- Lines: 45
-
- In article <1992Sep8.111139.8820@iccgcc.decnet.ab.com>, schmidtg@iccgcc.decnet.ab.com writes:
- |>
- |>
- |> I am in the process of converting a DOS program to run in the MS Windows
- |> environment and I am having some difficulties. The program uses a recursive
- |> search routine to find the solution to a problem. The program also must do
- |> some screen output along the way. The problem that I am having is in breaking
- |> up the recursive algorithm so that it can be executed piece-meal in the
- |> Windows event driven execution paradigm. I want to run the algorithm
- |> during idle time processing and so I must only execute a portion each time.
- |> Since a recursive algorithm uses the machine stack, I don't know of an easy
- |> way to save context and restore it between processing without getting down
- |> and dirty. I'm sure I'm not the only one who has encountered this problem.
- |> How have others solved it?
-
- In the recursive routine that's doing the computation, put the following code
- somewhere at a convenient "yielding" point:
-
- ...
- {
- MSG msg;
-
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- ...
-
- This loop will process all messages in the queue before stopping, thus giving
- you idle time processing. Note that this gets more complicated (but not much)
- if you have things like modeless dialogs up or have accelerators that need
- handling. You may also have to worry about disabling application commands that
- might cause inadvertant reentry into the processing routine.
-
- In any case, don't be afraid to have more than one location where messages
- are retrieved and dispatched. I do it for exactly this reason.
-
-
- ----------------------------------------------------------------------------
- Tom Brown | "Strange women, lying in ponds, distributing
- PE Nelson Systems | swords is no basis for a system of government."
- twbrown@pe-nelson.com | Monty Python and the Holy Grail
- ----------------------------------------------------------------------------
-