2

Is the window handle (HWND) of a window (especially Windows Notepad) persistent during the lifetime of the window, especially across hibernation?

Say I write a programm that retrieves (eg using FindWindowEx-function) and saves the handle of a specific window of another programm (in my case the window of a Windows Notepad).

Then the pc is hibernated and dehibernated/started again.

After the start/"dehibernation" the window of the other programm still exists, but will its window handle (HWND) still be the same?

(E.g. important because my programm wants to use the handle of the other window to perform some action with the other window like retrieve its content).

Thanks for any help

user
  • 33
  • 4
  • 7
    Generally yes HWNDs persist. But the other application may recreate it's Windows after being restored from hibernation. So I can't answer for a specific unknown application. Use an application like Spy++ to check the specific application. – Richard Critten Jul 03 '23 at 09:41
  • @Richard Critten Thanks a lot for your answer. Do you know if it is persistent for the built-in Windows Notepad? (So i open a Windows Notepad, type something in it, then hibernate and start again/"dehibernate": Will the Notepad (with the same content) still have the same window handle?) – user Jul 03 '23 at 10:01
  • 1
    @user - what are you really trying to do? – selbie Jul 03 '23 at 10:02
  • 1
    @selbie I'm trying to write a programm that saves open windows-notepads in a specific folder. The programm should run roughly every minute and also save old versions of the same note, but i don't know if that still works if i hibernate inbetween – user Jul 03 '23 at 10:12
  • @selbie (Later i want to extend it to do different things depending of the fate on the notepad, eg if it was saved with a name i will delete my saved copy, if its closed by user with the x-button by the user without saving then i want to copy it to a different subfolder, if the pc crashed (all windows disappear at the same time) then i want to restore it etc Basically i like using Windows Notepad (and don't like various note-taking programms i tried) but my notepads often disappear when the pc crashes/gets a bluescreen. The hibernation part is one aspect of the programm) – user Jul 03 '23 at 10:15
  • 4
    Wouldn't it be simpler to replace notepad by a program that creates the backups as needed? What you do sounds quite brittle to me. MS may change or replace notepad at any time. – Thomas Weller Jul 03 '23 at 10:22
  • 4
    @user If you only do it once a minute, just call `FindWindowEx` every time instead of saving the handle. – Ted Lyngmo Jul 03 '23 at 11:04
  • What if there is more than one instance of Notepad running? What's the plan then? – Paul Sanders Jul 03 '23 at 12:23
  • @PaulSanders could save the process ID/handle of the intended Notepad, and then find the window that belongs to that process. Even if the window is recreated after hibernation, the process won't be. – Remy Lebeau Jul 04 '23 at 15:26

1 Answers1

0

As far as hibernation is concerned, it won't change according to Resuming from hibernation.

restoring the contents of memory and all architectural registers. In the case of a resume from hibernation, the contents of the system memory are read back in from the disk, decompressed, and restored, which puts the system in the exact state it was in when it was hibernated.

YangXiaoPo-MSFT
  • 1,589
  • 1
  • 4
  • 22