开发者

How to create Modern Menus in Win Api?

By modern menus I mean menus like those made using MFC or Windows Forms(MenuStrips). I know that it is possible since I have seen some apps that use it which are developed in the Windows Api. It has also been done in the Win32++ library, and MFC and WinForms are just Win Api wrappers so if they contain modern menus, Win Api must contain them too. But my question is... How开发者_开发知识库 can I make a menustrip directly in the Windows Api? Is it included in the CommonControls? Or do i have to implement it myself? If so then how? Example code needed, but not necessary.

Menus somewhat like this

How to create Modern Menus in Win Api?


MFC and Winforms use very similar approaches to implement these custom menus. They start with generic support in their ToolBar/ToolStrip classes and specialize them for the menu bar/item classes.

You'll find the MFC implementation in vc/atlmfc/src/mfc. The afxtoolbarxxx.cpp source code files are about 24,000 lines of C++ code. Menu class specializations are in afxmenuxxx.cpp, another couple of thousand source code lines.

You can obtain the source code for the Winform classes from the Reference source. The ToolStripxxx.cs source code files are about 40,000 lines of C# code. Menu class specializations are in Menuxxx.cs, another couple of thousand source code lines.

Both use lots of support classes provided in their respective frameworks, basic stuff like window wrappers and image/text rendering support. Hard to guess how much of that they pull in.

Numbers like this are about an order of magnitude beyond what most programmers would consider feasible to rewrite themselves. You can certainly do better by shaving off features, both the MFC and the Winforms implementations have a lot of bells and whistles. Winforms more so, the basic reason it has so much more source code. This kind of feature support was however added with the express intent to provide a class library that you'd use instead of try to replace. Recommended.


MFC and WinForms are just Win Api wrappers so if they contain modern menus, Win Api must contain them too

This is not true. The basic menu handling code exists in the Win32 code libraries (basically user32.dll), and this enables you to create, draw, and handle messages to make the menus work, but they are very basic menus (just plain text). MFC works by calling the Win32 functions and handling the messages just as anyone else would, but it uses custom drawing routines to spice up how they look. And this is exactly how every other library does it. The only other way to do it is to draw the entire menu yourself (it's just another window), drawing any icons, handling the highlighting as the mouse moves over it, handling button clicks, etc, all yourself, which is a waste of time if you can get Win32 to do it.

So, if you want to have menus that look like that, you either have to code it yourself, or use a library that others have coded. It's as simple as that.


You probably have to implement it yourself, or use some 3rd party implementation.

See: How can i change the appearance of Windows 7 menus?


go to http://www.winprog.org/tutorial/simple_window.html you will find everything about window api programming tutorials


You'll need a 3rd party library such as CodeJock's Extreme Toolkit.

If you can't afford the budget, you may want to dig Code Project for some free source code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜