# Alt-spacebar and native title bars

**URL:** <https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814>\
**Category:** Windows\
**Created:** [April 27, 2006, 12:52am UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814 "2006-04-27T00:52:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [April 27, 2006, 12:52am UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/1 "2006-04-27T00:52:50Z")

</div>

I’ve posted about this before in the main forum, but I learned some more and this is a Windows -only topic.

If you have a window with a native titlebar, then this is OK:

-click on the titlebar  
-press alt-spacebar  
-system menu is shown correctly

This doesn’t work:

-click somewhere in the content component  
-press alt-spacebar  
-system menu doesn’t show up

I did some debugging and I noticed that in both cases, the window is still receiving WM\_SYSCOMMAND. So I’m wondering - is the menu showing up in the second case, but isn’t being painted properly because the z-order is different?

Matt

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2006, 9:26am UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/2 "2006-04-27T09:26:22Z")

</div>

no, the menu’s not appearing, though I can’t figure out why - none of the windows messages that could interfere with it are getting overridden. I’m a bit stumped on that one, actually.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [April 27, 2006, 6:38pm UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/3 "2006-04-27T18:38:11Z")

</div>

I think I figured it out - you only get the menu if the window isn’t set for mouse capture.

So here’s my change to peerWindowProc :

[code] case WM\_SYSCOMMAND :  
if ((styleFlags & windowHasTitleBar) != 0)  
{  
switch (wParam & 0xfff0)  
{  
case SC\_CLOSE :  
handleUserClosingWindow();  
break;

```
					case SC_KEYMENU :
						if (h == GetCapture())
							ReleaseCapture();
						break;
				}
			}

			break;[/code]
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2006, 6:48pm UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/4 "2006-04-27T18:48:19Z")

</div>

aha! Very smart, I could have stared at it for a long time before figuring that one out!

Cheers matt, I’ll put that fix in there.

---

<div class="post-metadata">

**Author:** ![matt](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/matt/32/18340_2.png) [@matt](https://forum.juce.com/u/matt)\
**Post date:** [April 27, 2006, 7:24pm UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/5 "2006-04-27T19:24:05Z")

</div>

Thanks; I just applied my usual technique of poking randomly at it until I learned something. : )

However, the fix I posted broke the demo; if you had the demo in native title bar mode and clicked the close button, my change caused the app to try and shut down twice. First you get the WM\_SYSCOMMAND with SC\_CLOSE, which causes the window to close, followed by WM\_CLOSE, which tries to close the window again.

This results in the JUCE shutdown code running twice, which toggles a jassert.

So I changed it to this:

[code] case WM\_SYSCOMMAND :  
if ((styleFlags & windowHasTitleBar) != 0)  
{  
switch (wParam & 0xfff0)  
{  
case SC\_CLOSE :  
PostMessage(h,WM\_CLOSE,0,0);  
return 0;

```
					case SC_KEYMENU :
						if (h == GetCapture())
							ReleaseCapture();
						break;
				}
			}

			break;

```

[/code]

This doesn’t pass the SC\_CLOSE to DefWindowProc, which prevents the double WM\_CLOSE message. It seems to handle all the cases - pressing alt-F4, double clicking the system menu icon, using the system menu, or pressing the close button.

Matt

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 27, 2006, 7:57pm UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/6 "2006-04-27T19:57:48Z")

</div>

ok, cool. Nice work!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:02am UTC](https://forum.juce.com/t/alt-spacebar-and-native-title-bars/814/7 "2017-05-12T10:02:23Z")

</div>

Closed on May 12, 2017, 10:02am UTC


