0

I want to create the simplest service for monitoring which new application I am opening or which application I am switching to make it active window/application on Windows 10+ using the Win32 api.

Purpose of this exercise is to track my activity of which application I am opening or which application I am switching to.

How can I create such service using Win32 api?

Alok
  • 7,734
  • 8
  • 55
  • 100
  • I spent two minutes doing basic web searches: [GetForegroundWindow](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow) and [GetWindowThreadProcessId](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid) would be where I'd begin, then read this: https://stackoverflow.com/questions/4102569/get-process-name-from-process-id-win32 – paddy Mar 16 '22 at 02:59
  • 1
    Additionally, you may wish to install system-wide user input hooks to catch things like mouse-scrolling over a non-foreground window, which is typically an indication of redirected attention. – paddy Mar 16 '22 at 03:02
  • @paddy: Yes we can find out list of processes or foreground or background processes at any moment. But I need to create service which can keep track of system events like opening new application or making application into background or foreground. – Alok Mar 16 '22 at 03:05
  • Your question does not indicate any amount of reading, nor what problems you've solved or are currently having. So I assumed you had an idea and didn't know where to begin. Regarding the simple method of querying the foreground window, you can do basic tracking by polling periodically. You may miss events, but it's unclear whether you care about that. It sounds like you're just trying to make a productivity tool for yourself, in which case it would be quite simple to just check the foreground window every 10 seconds or whatever. – paddy Mar 16 '22 at 03:10
  • 3
    There's a hook specifically for such events: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwineventhook. It's certainly simpler than messing with DLLs to use a CBT hook, but simple isn't a word that tends to go together with the win32 API in general. – chris Mar 16 '22 at 03:13
  • @paddy: Yes I dont know where to begin from. I just find out that I need to use win32 through which I can interect with windows os. – Alok Mar 16 '22 at 03:13

0 Answers0