Thread: Interrupt WIN32 API functions help!!!

  1. #1
    Registered User
    Join Date
    Jul 2008

    Interrupt WIN32 API functions help!!!

    I'm writing a fractal generator that rasterizes the fractal through a certain amount of iterations, these iterations get more and more exact and take longer and longer to calculate... So this is what I want to do:

    I want whenever an interrupt happens, like a keypress or mouse click anything that involves interaction from the user, for the program to STOP doing whatever function it is currently in, like calculating mathematics or printing to the screen, and idle as if the function was never called

    E.g. When the program is in a loop calculating the mandelbrot set and you press a key I want that loop to stop and go to the user input function. I want this from any function within my program.

    I looked into setting something up so whenever WndProc hears any messages that deal with keyboard input or mouse clicks then it will stop whatever loop it is in, but I just cant figure out how to do that! I would really like to stop the loops from within WndProc because it deals with all messages to the window that the fractal is being drawn upon.

    If someone could please help me with this I'll be very very grateful!


  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    If this is a console program:

    A very simplistic way to do this would be to implement your own Control Handler. Check MSDN for SetConsoleCtrlHandler(). Have a global variable that indicates all is well. In your Control Handler, depending on what input you trapped, alter the variable to reflect that you want to stop. In your code to handle calculations, put an occasional check on a global variable, and if it has been altered, return prematurely. This means you could stop on something like a control + c, control + break, etc. etc.. The only downside is that such a stop is not immediate, although I suspect this is a decent solution for the effort put into implementing it.

    If this is a Windows GUI program:

    Then the same idea applies. Monitor a variable in your calculation code that is changed when you press a character sequence of some sort. The key presses should be picked up by your message loop or somewhere down the line. [Edit]You will need a separate thread for your calculation code, however, in this case.[/Edit]
    Last edited by MacGyver; 07-20-2008 at 07:54 PM. Reason: Important clarification

  3. #3
    Registered User
    Join Date
    Jul 2008


    Thats a great idea, and ive implemented it up to the thread part... I have no idea how to deal with threads in the WIN32 API. Is there any good source as to where I should look?

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    I hate real numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Limitations on Win32 API functions
    By csonx_p in forum Windows Programming
    Replies: 5
    Last Post: 04-09-2008, 04:09 AM
  2. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  3. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM