-2

Creating an app that needs an event to trigger every few seconds or so.

I'm used to game design where a simple EventTick() that is handled by the engine does all the work. How can I make an event like this in the WinApi desktop wizard. I need to check a Proc Id in intermittent periods.

Thinking something like-

case WM_TICK:
{do thing}
break;

Or any other way to do this. I have also looked into WM_Timers but was getting mixed results so was thinking there was probably another way.

Greg
  • 3,861
  • 3
  • 23
  • 58
tea
  • 1
  • 1
  • Go read [this book](https://www.amazon.com/Programming-Windows%C2%AE-Fifth-Developer-Reference/dp/157231995X) . Save money and order a used copy. – selbie Apr 10 '20 at 05:47
  • If you already have a GUI message loop then [WM_TIMER](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-timer) is the way to go. Otherwise look at [waitable timers](https://learn.microsoft.com/en-us/windows/win32/sync/waitable-timer-objects). – Remy Lebeau Apr 10 '20 at 07:03
  • *"I need to check a Proc Id in intermittent periods"* - Sounds like you want to get notifications, when a particular process is terminated. A timer (or any method based on polling/sampling) is a poor choice for that. You can set up a callback when a process terminates. See [this Q&A](https://stackoverflow.com/q/3556048/1889329). – IInspectable Apr 10 '20 at 13:05

1 Answers1

0

To check if a process is still running, use EnumProcesses or CreateToolHelp32Snapshot to find your process, then use OpenProcess() with PROCESS_QUERY_LIMITED_INFORMATION to get a handle to the process. Then use GetExitCodeProcess() to check if the process has terminated, if it hasn't the output variable will be STILL_ACTIVE

You can do this inside your message loop using WM_TIMER

GuidedHacking
  • 3,628
  • 1
  • 9
  • 59