Creating a menustrip in WinAPI? - c++

Is there a way to get a menustrip instead of an HMENU when using the WinAPI? Like menus that .Net applications use? Because the HMENU just doesn't fit my color scheme, I need a darker menu.
Thanks

If you don't like the system defaults, you can owner-draw the menu. If you only need to support Windows Vista and higher, you can follow this article. Otherwise you need to call ModifyMenu() on your menu items and set MF_OWNERDRAW and everything that comes with that.

Related

WinAPI check if a window has a regular title bar

I want my program to reliably determine if a window (given its handle) has a regular windows style title bar (like windows explorer, control panel and most of the desktop apps) or a custom one (google chrome, visual studio, spotify, store apps).
Is there a specific flag in GWL_STYLE or GWL_EXSTYLE, or is there an other way to check the title bar style?
You will have to define what you consider "regular" and, therefore, what is "custom".
For instance, typical applications will have WS_CAPTION and WS_BORDER set, if I recall correctly. If you consider that "normal", then it is easy to consider everything else custom and you are done.
To decide on your criteria, I suggest you inspect the applications you mention and others, and finally decide what is the set of conditions you need.
Further information:
Window Styles
Extended Window Styles
Window Types

How to make customized widgets take keyboard events like textctrls

Platform Windows
Created a control using windows API: CreateWindowExW and set it's parent to a panel hwnd
But it seems the control does not handle arrow keys, enter keys and tab keys properly.
Is there any flag on wxwidgets give any control created by CreateWindowExW the same ability like edit controls to capture arrow keys, enter keys and tab keys?
The problem might be due to not using WS_EX_CONTROLPARENT for your control when creating it, this style is needed for the built-in tab navigation to work.
And while I don't think it's going to help with your particular problem, I'd still like to say that embedding a native control in an application using wxWidgets is not quite as simple as just giving it the HWND of an existing control as parent, you may want to look at wxNativeWindow (new in wxWidgets 3.1.0) for how to do it correctly.

How to hide a window's menubar?

I'm trying to hide the menubar in a C++ application using the windows API. I'm using AppendMenu / RemoveMenu to edit items. But I'm sick of the whole menu based interface and I just want to hide the whole application menubar. How can I do that using the windows API?
Call SetMenu with a NULL HWND parameter, according to the docs.

Extend an external application's menu

I am currently writing a plugin for a third party application.
As the plugin framework does not provide any way to access the UI I am now trying to do this manually via the WinAPI.
More specifically, I want to add a custom menu item for my plugin in the "File" menu.
My first attempt using FindWindow to retrieve the handle of the main window and the using GetMenu was not successful, as GetMenu simply returned NULL.
My next step was to use EnumChildWindows and search for a child having the text "&File" (I really don't like this approach as it makes localization quite terrible). However, I only found out the handle of the menu item, but I need the corresponding HMENU to use AppendMenu then, don't I?
Simply casting does not work and results in an "Invalid menu handle".
Is it actually possible to achieve what I am trying? How?
Thanks for your ideas in advance!
It more than likely just isn't a HMENU. Custom menu implementations are common, the one Window provides is dated and inflexible. Compare to Windows Forms' MenuStrip for example.
Of course, that blows a gaping hole in your approach.

How to add custom item to system menu in C++?

I need to enumerate all running applications. In particular, all top windows. And for every window I need to add my custom item to the system menu of that window.
How can I accomplish that in C++?
Update.
I would be more than happy to have a solution for Windows, MacOS, and Ubuntu (though, I'm not sure if MacOS and Ubuntu have such thing as 'system menu').
For Windows, another way to get the top-level windows (besides EnumWindows, which uses a callback) is to get the first child of the desktop and then retrieve all its siblings:
HWND wnd = GetWindow(GetDesktopWindow(), GW_CHILD);
while (wnd) {
// handle 'wnd' here
// ...
wnd = GetNextWindow(wnd, GW_HWNDNEXT);
}
As for getting the system menu, use the GetSystemMenu function, with FALSE as the second argument. The GetMenu mentioned in the other answers returns the normal window menu.
Note, however, that while adding a custom menu item to a foreign process's window is easy, responding to the selection of that item is a bit tricky. You'll either have to inject some code to the process in order to be able to subclass the window, or install a global hook (probably a WH_GETMESSAGE or WH_CBT type) to monitor WM_SYSCOMMAND messages.
Once you have another window's top level handle, you may be able to call GetMenu() to retrieve the Window's system menu and then modify it, eg:
HMENU hMenu = GetMenu(hwndNext);
You can use EnumWindows() to enumerate top level Windows.
I don't have a specific answer for the second part of your question, but if you subclass the window, I imagine you can modify the system menu.
EDIT: or do what Chris said: call GetMenu()
Re: the update - please note that not even Microsoft Windows requires windows to have a sytem menu. GetMenu( ) may return 0. You'll need to intercept window creation as well, because each new top window presumably needs it too.
Also, what you propose is rather intrusive to other applications. How are you going to ensure they don't break when you modify their menus? And how are you going to ensure you suppress the messages? In particular, how will you ensure you intercept them before anyone else sees them? To quote Raymond Chen, imagine what happens if two programs would try that.