December 13th, 2013, 02:12 PM
I recently created a dll for Final Fantasy 8 PC that injects into the main process, and then loads a form. The form contains a timer and plays music through calls to bass.dll. All of this is trivial anyway because none of that is the cause of the issue.
Basically, I need to open a form without focus. So the focus will stay on the game. I can't use setforegroundwindow because by that time, focus has already been lost and the game minimizes. At the moment I am being forced to use showmodal as follows:
The problem is showmodal will always take the focus (unless there is some way to override that behaviour?). So next I tried:
This indeed works, but then the issue is when the game is closed down, an exception is always raised saying that the window handle is invalid.
So... anyone have any idea how I can show a form from a dll without it gaining focus away from the game? I am forced to use these methods because with a normal show method, the thread ends.
December 15th, 2013, 12:14 PM
Hi, my most humble opinion.
Using your code example:
Do a .show within your thread and immediately thereafter start a repeat until loop which will only evaluate to true once the form is closed. This way you don't have to use showmodal (hence not gaining the focus unnecessarily) - assuming the show doesn't take focus.
i first tried with app.processmessages but noticed it will eat up a lot op cpu cycles. Then tried checking what showmodal usually does and it seems to use .handlemessage instead.
hope it helps.
December 15th, 2013, 01:48 PM
Thank you! Finally, this is solved. This is what I did...
Then, in the oncreate of form1:
form1.visible:=true; (so it doesn't override the shownoactivate)
This has no error message on game close (from what I can see the error only happens with XP anyway), and it solves all other issues.
December 16th, 2013, 04:22 AM