Sign in to follow this  
reaperrar

Keys Alt & F10 freeze my window

Recommended Posts

Doing some windows API / opengl related stuff and a problem I've run into is the window freezes if ALT or F10 are pressed (on the key up event). It unfreezes if the window receives any input (even from alt/f10).

It also appears that a small amount of time has passed (1 second or so) even if it is frozen for 10seconds.

Why is it doing this and how can I fix it?

I've tried:

[code]
case WM_KEYUP:
{
switch (a_wParam)
{
case VK_F10:
{
return DefWindowProc(a_hHandle, 0, 0, 0);
break;
}

default:
{
break;
}
}

break;
}
[/code]

Inside my WindowProc function, but the keyup event only triggers if the pressed key is not ALT or F10

EDIT: After some research I found the problem is related to how I create my window. Using the "WS_SYSMENU" style allows a menu or something and when I press alt or F10 with that style enabled the window tries to open that menu I believe. Disabling it will solved the problem, but it will also remove my exit, maximise and minimise buttons. How can I solve the problem without removing the "WS_SYSMENU" style.

Share this post


Link to post
Share on other sites
I've been having this exact same problem, but couldn't figure out what the cause was. Your findings make perfect sense. Thanks for the info!

Update:

After trying a few things, I discovered two ways to solve it. The first is to disable WS_SYSMENU. I'm actually using SlimDX & C#, so I simply created a new descendant class of RenderForm and put in an override for the CreateParams function, like so:[code]


protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.Style &= ~WS_SYSMENU;
return createParams;
}
}[/code]
Unfortunately, this also removed the "X" button in the top right of the window, which I want to keep, so this technique wouldn't cut it for me.

I then discovered another technique, which is to override the ProcessDialogKey() function and tell the form to ignore the Alt and F10 keys. The code ended up as follows:

[code]
protected override bool ProcessDialogKey(Keys keyData)
{
if ((keyData & Keys.Alt) == Keys.Alt || (keyData & Keys.F10) == Keys.F10)
{
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}[/code]
I did a quick test, and I'm able to capture the F10 key for my own purposes through my normal key handler and it doesn't trigger the menu "freeze".

Share this post


Link to post
Share on other sites
I discovered that the second solution I gave above also disables ALT-F4, which isn't ideal, so I modified the code to allow that combination. For those who are interested, the final code is:


[code]
protected override bool ProcessDialogKey(Keys keyData)
{
if (((keyData & Keys.Alt) == Keys.Alt && (keyData & Keys.F4) != Keys.F4) || (keyData & Keys.F10) == Keys.F10)
{
return true;
}
else
{
return base.ProcessDialogKey(keyData);
}
}[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this