Checking focus of program
Blitz3D Forums/Blitz3D Programming/Checking focus of program
| ||
I've written a Blitz3D program in window mode. What I want to know is there any way to check for focus so I can pause the game should the user click on another window or use Alt-Tab? |
| ||
GetActiveWindow GetForegroundWindow Hope that helps ;) |
| ||
How would I get that to work in a program? I triedGraphics3D 640,480,32,2 SetBuffer BackBuffer() Global bank = CreateBank(8) result = CallDLL("user32.dll","GetActiveWindow",bank,bank) Global winhndl = PeekInt(bank,0) ...Do setup While Not KeyDown(1) result = CallDLL("user32.dll","GetActiveWindow",bank,bank) If PeekInt(bank,0) <> winhndl Then Gosub pausegame ...do stuff RenderWorld Flip Wend End .pausegame While PeekInt(bank,0) <> winhndl result = CallDLL("user32.dll","GetActiveWindow",bank,bank) Wend Return I tried replacing GetActiveWindow with GetForeGroundWindow but neither works. |
| ||
Put this in your "Userlibs" folder.;------ Userlib *.decls .lib "User32.dll" GetActiveWindow%() GetForegroundWindow%() Then you can use them like any other command. |
| ||
http://www.blitzbasic.com/codearcs/codearcs.php?code=853 (Same as Papa Lazarou's) |
| ||
That worked, Thanks :-) Quick question though. How would I distribute the program? Would I need to distribute the user32.decls file also? Where would it go because the final user probably wouldn't have Blitz3d installed nor a userlibs folder. |
| ||
It just tells Blitz that your function call uses an extrenal DLL. You never need to distribute the .decls file with your EXE, but in most cases you need to distribute the DLL and put it in the same directory as your EXE. However, this is a special case. The DLL is a standard DLL that all copies of windows have in the windows system folder. Windows will know to use it, so you do not need to distribute the DLL with the EXE for this particular function to work. That's true of any function that uses a standard windows DLL like user32.dll or system32.dll. |