C++ Windows add option to menu - c++

In windows, when you click the small icon in the upper left of the window, you get a menu with Move, Minimize, Maximize, and Close options.
Is there anyway I can add my own options to that menu?

Absolutely.
GetSystemMenu(hWindow, FALSE) gets you menu handle and you are free to modify it.
A nice way is to add a separator and append your additional items like "About...". ATL code snippet is here: http://www.assembla.com/code/roatl-utilities/subversion/nodes/trunk/FilterGraphSpy/GraphBuilderCallbackPropertySheet.h#ln1392 lines 1392-1396.

Related

Replace system menu popup on windows

I want to replace the default sys menu(Restore, Move, Size etc.) with my custom entries. The menu I'm talking about can be opened either by clicking left button on window icon or by clicking right button on window title.
I can remove all the items and populate this menu with my own entries. But if I remove all entries then minimize, maximize and close buttons become inactive. So they depend on those menu items.
I want to have min, max, close buttons working as usual but system menu which contains my own items(like it is done in Windows Media Player).
I'm using Qt, but I'm almost sure it can't be done with it so any solution would be appreciated.
Do not remove Min/Max/Close items from system menu. It's much better to process WM_SYSCOMMAND message instead (SC_MINIMIZE, SC_MAXIMIZE, SC_RESTORE, SC_CLOSE).

Changing program icon dynamically

In C++, is there anyway to let the user chose the icon of the app? For example, Winamp lets you select which icon you wish to use from a list of icons in it's preferences. How is it done?
There is the icon that you see in explorer. This is a resource in your executable. You could change that, but I wouldn't advise you too. Virus scanners can get nervous if executables are modified, and in Windows Vista you will not even be allowed to write in the Program Files folder.
But the icon that is displayed on the task bar or in the system tray can be changed. This is actually the icon of your application window and it can be set by sending a WM_SETICON message.
And there are shortcuts. They can be changed too, and in a shortcut you can specify which icon should be used.
I found a discussion on changing icons that has information about the first two options.
For Visual Studio 2010 in an MFC dialog based app
A. In the resource view, rightclick Icon folder and add icon. Give it an ID like IDI_MYICON. Leave it as is or draw something nice.
B. Go to OnInitDialog. Add the following two lines of code:
HICON hMyIcon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_MYICON) );
SetIcon( hMyIcon, FALSE ); // FALSE == use as small icon
You can read about these functions in the help to understand what is happening.
This sets the icon as icon for the sysmenu (topleft) and in the taskbar. This is however not automatically reflected in all situations. E.g. for a systray icon you need to explicitly specify the icon again in the call to Shell_NotifyIcon().

How to change the tooltip 'Active Files' on the CMFCtabCtrl's TabbedDocumentsMenu?

We have two ways in which we scroll through the tabs in the CMFCTabCtrl, either using the two buttons to scroll the window tabs or an interface that displays a pop-up menu of tabbed windows. This option depends on the EnableTabDocumentsMenu method in the CMFCTabCtrl. Be defualt the tooltip option on this button(menu) is "Active Files".
Same tabbed control seems to be used in Visual Studio even and I see the same tooltip there?
Is there any way we can change this tooltip text?
The tool tip is set to IDS_AFXBARRES_OPENED_DOCS ("Active Files") in afxtabctrl.cpp when you EnableTabDocumentsMenu. To change it try calling:
m_btnScrollRight.SetToolTip(_T("My Customized ToolTip"));
Your main problem is that m_btnScrollRight is protected so you're probably best off inheriting from CMFCTabCtrl and doing it in your own class (after calling EnableTabDocumentsMenu).

Win32 Window Menu is appearing along left side instead of across top of window

I think I may be using a wrong window style or something or maybe just adding the menu to the window incorrectly. I'll post a link to an image here so you can see what I mean about the menu not diplaying correctly:
http://img707.imageshack.us/img707/4828/wtfmenu.jpg
And here's a link to the code that creates the menu and the window:
http://pastebin.com/CBrSVXUD
I'm sure I'm missing something simple and dumb in the labyrinth of styles, settings and etc that are part and parcel for the Win32 API. Has anyone seen this before and know what I'm doing wrong? I just want a 'normal' menu bar along the top, snug against the title bar.
Thanks in advance for any advice.
The MF_MENUBREAK flag you use when adding the popups causes this—that flag is only required if you want the menu item to appear on a new line in the menu bar. Take out both of the MF_MENUBREAK flags and all will be well.

"Sticky" MFC popup menu

I currently have some toolbar buttons with a small arrow on the side (TBSTYLE_EX_DRAWDDARROWS) that, when clicked, result in a popup context menu being displayed under the button. This is done by constructing a custom popup menu and calling TrackPopupMenu.
The client now wants to be able to select multiple options from the menu before it closes, so that multiple options can be be modified without the need to re-open the menu and wait for an intermediate redraw between each change.
For example:
User clicks dropdown button
Dropdown menu appears (modal, waits indefinitely for user action)
User clicks some item (e.g., toggle a checkmark)
Timer (e.g., 500ms) starts
If timer expires, the menu is closed and all selected actions are executed.
User clicks another item before the timer expires, go back to 4.
The best I can come up with is to redisplay the menu by calling TrackPopupMenu multiple times. This makes the menu "flicker" when you select an item, and will probably require me to start a thread in order to do the timeouts, which I would rather avoid.
Rather than a menu, put up a dialog box with the options on it. A dialog can easily do all that is required.
A menu that doesn't close when you click it will just seem wrong. A dialog that closes by itself will seem wrong too, but it's probably the least of two evils.
Edit: If there's anything I've learned with Microsoft, it's don't try to fight the default behavior. You're asking for trouble if you do.
If you're building your menu dynamically I can see how automatic sizing can be handy, but it's not hard to do in a dialog either - make the dialog really big and before it becomes visible, enumerate the children and take a union of all their rectangles, then resize to that. Checking the boundaries to make sure they're on-screen is just a few if statements with OffsetRect. Checkboxes are trivial; icons less so, but still not bad.
One additional enhancement that would be easy to add is to dismiss the dialog immediately on a double-click.
Following #Mark Ransom's answer, you should put up a dialog box. But you can make the dialog modeless and make it close itself when you click outside of it (i.e., the dialog loses focus). That way it could behave more like a menu.
Notice that normal menus never go away by themselves, you always have to click somewhere outside the menu (or one of its options) to make it disappear.