Click here to Skip to main content
15,303,572 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a Win32 app with C++ in Visual Studio (no .net). I created a function to make my app go full screen using the code below:

DWORD dwStyle = GetWindowLong(h_main, GWL_STYLE);
DWORD dwNewStyle = dwStyle & ~dwRemove;
SetWindowLong(h_main, GWL_STYLE, dwNewStyle);
SetWindowPos(h_main, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE 
HDC hDC = GetWindowDC(NULL);
SetWindowPos(h_main, NULL, 0, 0, GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES), SWP_FRAMECHANGED);

The problem I am having is that I can't figure out how to hide the App menu bar. Does anyone know the command for hiding the menu? I have managed to hide the File menu toolbar, taskbar, and border, but can't figure out how to disable or hide the App menu. Anyone know?

Update: I'm wondering if the problem lies in the fact that I created the menu in the resource file. Maybe if it is defined in the resource file, then there is no way to remove it. It looks like there are ways to dynamically create an app menu, so maybe I'll try that instead.
Updated 10-Sep-10 20:58pm
Sandeep Mewara 11-Sep-10 2:59am
Use PRE tags to format code part from next time. It makes the question readable.


Use ::SetMenu(hWnd, NULL) to hide the menu, ::SetMenu(hWnd, hMenu) to show it.

This should do what you wish :)

// This should be kept for reverse operation
DWORD dwStyle = ::GetWindowLong(m_hWnd, GWL_STYLE);
HMENU hMenu = ::GetMenu(m_hWnd);
::GetWindowPlacement(m_hWnd, &wp);

// Hide the menu bar, change styles and position and redraw
::LockWindowUpdate(m_hWnd); // prevent intermediate redrawing
::SetMenu(m_hWnd, NULL);
::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle & ~dwRemove);
HDC hDC = ::GetWindowDC(NULL);
::LockWindowUpdate(NULL); // allow redrawing
::SetWindowPos(m_hWnd, NULL, 0, 0, GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES), SWP_FRAMECHANGED);

The reverse operation is left to you as a homework, you may find an implementation (without menu handling, I will add that if I update) in my article : Frame Related Classes and Message Map Macros for Windows Mobile and Desktop WTL Applications (Part 1)[^]

Edited for code and syntax correctness AR
And added some more styles to remove AR
weylspinor 11-Sep-10 5:16am
You're a genius, thanks! It would have taken me about 3 weeks to figure out the LockWindowUpdate part. The reverse part is easy, no? Just use:

LockWindowUpdate(m_hWnd); NULL);
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle & dwRemove);
HDC hDC = GetWindowDC(NULL);
LockWindowUpdate(NULL); // allow redrawing
SetWindowPos(m_hWnd, NULL, 0, 0, GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES), SWP_FRAMECHANGED);

BTW How important are the double colons in front of the functions? I've never seen anyone do that before.
Alain Rist 11-Sep-10 5:38am
The double colons let you paste the code without name clash even when you are (for instance) deriving from ATL::CWindow which defines members with the same names, but different signatures :)
weylspinor 12-Sep-10 3:10am
My guess above was wrong. It should be:
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle & ~dwRemove);
This is logical since you are getting the previous state, and doing the opposite for the selected options. For some reason it doesn't work, however... Not sure why.
Alain Rist 12-Sep-10 3:27am
See my referenced article :)
Just reverse :
- Set original menu
- Set original styles
- Set original position
That's all :)
weylspinor 17-Sep-10 5:12am
Okay... I read the articles you created linked to above. They are very nice. Correct me if I'm wrong... Are you saying that it's not possible to set the orignial menu and original styles without using ATL or MFC?
Alain Rist 18-Sep-10 2:59am
I certainly don't say that. The CFullScreenImpl::SetFullScreen(bool bFullScreen) code resolves to Win32 API calls. cheers.
This solution is a bit misleading because it does not HIDE the menu. Instead, it COMPLETELY REMOVES the menu, resulting in total unavailability of the menu functions. This means that, for example, if you had a typical menu that include a FILE popup that contained an EXIT item, and that 'F' and 'X' were tagged as menu hot keys, all of the users who had learned to exit your program by pressing Alt+F, Alt+X would discover that no longer works in full screen mode when this approach to "hiding" the menu is used. Exiting may not be important, but all other menu hot key operations would, obviously, be similarly non-functional. If you do not define hot keys and use only accelerators, you will avoid this but at the expense of being a slightly non-standard Windows program, since menu hot keys are reasonably standard and expected.

I've been searching for quite some time for a way to actually hide a menu without deleting/disabling it completely, but had no luck. Of course, you can leave the menu enabled and set the top of your window to the height of a menu above the top of the screen, but that's not good if there happens to be a display above the screen where you're full screened -- then your menu will be visible on the screen above. If that isn't an issue, change the top coordinate of your window from the top line of the screen to the top line minus
and leave the menu alone. You won't see it and it will work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900