Hi chmod, the main problem for me patching it is that I'm unsure if there are multiple possible Window Class values for the different versions of DF (I'm _really_ new to DF). The version I'm using (came w/ a tutorial) has a window class of "OpenGL". But I don't know if that's true of others. If there are multiple, and I make that change, it could break DT for those with a different window class.
Oh and EnumWindows() probably isn't necessary for DT, though. It's very useful, and a necessity for more advanced window handle searching, but I think it's overkill here. FindWindow() should be fine. Assuming there is only the one possible Windows window class of "OpenGL" you could Simply call FindWindow("OpenGL", "Dwarf Fortress") and that would eliminate it finding explorer.exe. If there are other possible window classes you could just call FindWindow() a couple of times checking each if they return null.
My recommendation is this: If you feel confident that there is only the one possible window class for DF just replace that one line with:
HWND hwnd = FindWindow(L"OpenGL", L"Dwarf Fortress");
otherwise, I'd suggest reading multiple possible values from a new group in game_data.ini and just iterating through them until hwnd != null. I should point out, however, that it's unusual for a developer to change the app's main window class name, so putting it in the .ini instead of hard coding it may also be overkill especially since the project is OSS. If all versions of DF use OpenGL then it's likely they all have the same window class since that's probably being set by the framework.
Oh and to get the window class I use Spy++ but since you likely don't have Visual Studio you may not have access to that. I checked StackOverflow for an alternative and one user recommended
WinDowse but I've never tried it. If it works like Spy++ just target the title bar to get the main window.
The other alternative actually is to use EnumWindows() which will allow you to iterate through all the windows with a name of "Dwarf Fortress" and then select the right one according to some criterion other than window class, but, as I said, that's probably overkill.
Edit:Here's a quick and dirty fix now that I think about it. It'll solve the problem at least for people with a window class of OpenGL and it'll fall back to your current behavior if that's not found:
HWND hwnd = FindWindow(L"OpenGL", L"Dwarf Fortress");
if (hwnd == null) hwnd = FindWindow(NULL, L"Dwarf Fortress");