Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I tell if a glut window has focus? Im using c#/tao, Ill use p/invokes if necessary.

Basically I want to ignore input if it doesn't have focus.

share|improve this question
    
I've not used glut before, but it seems odd that a window would be receiving input messages if it didn't have focus. Are you sure this is something you need to do manually? –  Mike Strobel Aug 9 '10 at 20:40
    
Since these are not game development exclusive topics, this question belongs at Stack Overflow stackoverflow.com where you should get a much better response. –  Ricket Aug 9 '10 at 20:41
    
Im using GetAsyncKeyState for input rather that glut. –  Sam Aug 12 '10 at 14:53
add comment

2 Answers

I'd guess you have to use the regular win32 func to get the active window handle and compare it to your own. GLUT's focus functions don't behave as expected in Windows as they're based on move over to focus.
http://stackoverflow.com/questions/466354/how-can-i-tell-if-a-window-has-focus-win32-api

Edit: Wait...I assumed Windows. Not sure that's a correct assumption.

share|improve this answer
    
On Windows, he may want to compare his window handle to both the active window and the foreground window, ensuring that both match. I vaguely recall a strange edge case in which the active window was not necessarily the foreground window. Or perhaps I've simply gone mad. –  Mike Strobel Aug 11 '10 at 16:29
add comment

Here's the solution I've got so far

[DllImport("User32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
static extern IntPtr GetFocus();

public bool HasFocus(string windowName)
{
    IntPtr windowHwnd = FindWindow(null, windowName);
    if (windowHwnd == IntPtr.Zero)
        return false;
    return windowHwnd.ToInt32() == GetFocus().ToInt32()
}
share|improve this answer
    
If you are ok with windows specific code, this would work fine i guess –  Toad Aug 14 '10 at 13:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.