Author: Alexander Bischofberger translation: Aweay
Click here to download the sample program Click here to download the source code
I didn't fully translate in accordance with the original text, add some of my understanding, if everyone is not satisfied with the practice, please refer to the original text
Introduction
In WindowsXP, do you pay attention to a special folder similar to the control panel, I have collected pictures, they have a window similar to the above picture to display the user's most common operation, because Windows helps you think you may think What to do, this makes novices very easy to use it. I think this kind of user help also applies to my program, so I wrote a class to simulate such controls.
background knowledge
In fact, the control with such a behavior is not difficult to write, I found that Windows uses a lot of different colors (specifically different blue), but I don't know how to get these colors without relying on the topics. Therefore, regardless of whether the method is correct, I am just simply getting similar colors, I hope to support the theme in the near future.
There is also a feature of such an interface, that is, if you use Spy to view the information of the window, you will find that you can only get the DirectUI class, and all child forms can not be obtained, even those who must be a child form. For example, the editor that can correspond to the keyboard message, etc., they look directly up. Maybe this is why it is called Directui.
About code
This class has now supported theme style. If you want to activate them, you only need to define the USE_THEMES macro in stdafx.h, otherwise I will use the XP style of my analog (translated, the article may be updated, so the author is not there. Support XP topics, here is supported, and there is also its simulated style).
Add two files into your project and make sure there is a CMEMDC class in your project, or the code already provided in the direct use of the example.
Insert CWndDirectui as a normal control in any location you like. Before you start compiling, make sure you have a hand-type cursor resource file called IDC_myHand.
By default, the control uses the subject style (such as screenshot above). You can manually change the drawing style - using CWndDirectui :: styleExpClassic, CWndDirectui :: StyleXP or CWndDirectui :: StyletHemed, CWndDirectui :: StyletHemed, CWndDirectui :: StyletHemed, CWndDirectui :: StyletHemed the setStyle () function. Use the getStyle () function to get the current drawing style. Be careful when using the Office style, because this type of style is not folded, unfolding the button, so the group that has been folded cannot be expanded when using such a style.
For manual folding, unfolding functions using ExpandGroup (Groupnr, Expand).
The best way to fill the control is to use the initFromMenu (Uint ID) function to pass a menu ID that contains a 2D menu (excluding submenu). This function will automatically create a menu entry to the group (Group, is a Directui interface collection meaning). If you like, you can insert a toolbar, which is a SETTOOLBARIMAGES (UITOIToolbar) function. Please put all the entries in a Toolbar, because this function can only use one Toolbar at the same time. In addition, the scroll bar will be automatically displayed when the space is not enough.
{...
M_Wnddirectui.initFromMenu (idR_direct1); m_wnddirectui.settoolbarimages; ...}
In order to use more than 16-color images, you need to call SettoolbarImages (Uitoolbar, UIALNATEIMAGES, NWIDTH) functions, parameter descriptions:
uiAlternateImages: high color image resource id nFlagColor:. See for more info Default is ILC_COLOR8 for 256 color images clBackground: Background color used for maps (default is purple) nWidth: Button width (default is 16)
For manual adding groups (Group) and entry (Item), refer to the definitions and functions of the class and the function addGroup, AddItemCommand, etc. So this is like using List, when the user selects an entry in the list, your program is like processing the normal menu commands to handle these commands. If you want to use a parked form, there have been many classes to implement these, you can find it, I have no reason to inven invented the wheels.
Use static text and edit control
So far, CWndui also includes two new entry: static text and editor controls. If you want to use them, you can only manually call the AddItemCommand function. So using the quadrature and editor controls similar to:
{... int ngroup; ngroup = m_wnddirectui.addgroup ("test group");
m_wndDirectUI.AddItem (nGroup, new CDirectUIItemStatic (_T ( "This is / na multiline / ntest text"))); m_wndDirectUI.AddItem ( "! Edit this" nGroup, new CDirectUIItemEdit (_T (), & m_wndDirectUI)); m_wndDirectUI.AddItemCommand (Ngroup, "item 1", id_number1); ...}
These two new controls cause the code to be slightly changed, CDirectuiiteMedit uses popular CINPLACEEDIT classes, this class is written by Zafir Anjum (I have modified some to adapt to my class), thank him. In the screenshot above, I didn't put into cdirectuiitemstatic and cdirectuiitemedit, because I didn't know what the official draw method would look like, I only used my idea to draw them. If you have any details, please tell me.
Areas for improvement
The following features are not implemented in the first edition:
Keyboard support, only the mouse can be used to access these control focus boxes, when the button is pressed, there is no focus box, and you cannot respond to any focus to reach the message.
This is my first in the code, if I may tell me the mistake.
Compatibility test
The code uses Windowxp and VC6 test, he should be able to pass on the operating system and VC5 above Windows98, I don't do a detailed test, if there is any problem, please tell me. I am very sorry that the resources in the example program mixed English and German.
Copyright and honor
As long as you add the following information to your program document, you can use the code in any type of application (free, shared or even commercial software): Thanks a lot to keith rule for his cmemdc class! Thanks to david yuheng zhao for his CVisualStylesXP class. Thanks to all of you who found a bug (see discussions below), you are mentioned inside the code! Thanks to Zafir Anjum for his CInPlaceEdit class I used! Thanks to Mathieu Dubaele for his help with the edit item.
Maintenance history
July 27, 2004: Two New Items Added, Lot of Code Changed May 8, 2004: Now Supports Themes As A New Style May 2, 2004: Support for Hi-Color Icons, Thank Dany Cantin For His Code for Hi-Color Toolbars december 1, 2003: Bugfix (GDI resources), thanks to Michel Wassink and the others who helped me finding the bug March 1, 2003:. BugFix: When a group is collapsed you can still select an item (OnHittest) BugFix: When scrolled the OnHittest returns wrong results BugFix: Warning for IDC_HAND is fixed Example: How to use in a dialog (select the menu item DIRECTUI_WINDOW, Show dialog for an example) January 5, 2003: Scrolling, expand collapse, new styles, minor changes. Class and files renamed for cjobwnd to cdirectui november 19, 2002: First Version
About the author Alexander Bischofberger
Start contact programming is on C64, when using the method of "error in the error", many years later, the parents bought me the first PC (Atari PC4, AT 8 MHz), which is using Turbo Pascal, later The Turbo Pascal, VC1.52 on Windows is started, and the last VC6 is started. I have a lot of large software development experience, such as:
Can be operated independently, support automatic restart, disk encryption ... government department's strategic decision system MLM marketing tools Maintain a demo plan system and other TV software all my code, experience and help from this site Www.codeproject.com, thank you again for those who have helped me, don't learn anything, I will try my best to share my code (those valuable code) to help more people. Click here to check the author's personal information.
About translation by means of aweay