Keywords: custom control, C ++, Win32 SDK
This article published a custom control that I developed at work. The first is the multi-choice control, which is mainly inspired by the explorerbar, that is, the DirectDraw section on the left side of the Resource Manager, such as opening a folder, the "folder task" composed of multiple panels that can be expanded and shrunk on the left. The development requirement of this control is mainly used for fast and convenient selection and positioning in many items, so I call it a multi-choice control. In terms of appearance, it is arranged from top to bottom on some column panels (we call a group a child of the control, that is, the linesize of the first layer subnode = 1 ), the main difference between it and the outlook sidebar is that multiple panels share a common Greater customer zone, that is, only one panel is usually visible at the same time (similar to tabcontrol ), obviously, this feature is sometimes needed, but sometimes we don't want it. That is, the exploerbar and the current control are simultaneously visible to multiple panels. For example, a tabpage is usually divided into multiple pages by function group. These pages are highly independent and independent from each other, therefore, it is better to see only one page at a time. The multiple choice space we need to do is essentially the same. Therefore, I hope to display multiple pages in a composite manner. This gives us a flexible and broad combination of global and local perspectives, this feature is the feature of javasebar.
To sum up the demand for this control, we need to select Multiple widgets and use multiple panels to ensure flexible and fast positioning. That is, we need to classify items and add them to the Panel, it can be folded at any time. To provide a flexible view. In the panel, because of the small and many features of items, layout them from left to right using an icon view similar to listview. In this way, we can save space in the vertical direction than the Treeview (because each node of the Treeview occupies one row). In this control, there is a border between each element and the interval between elements, margin and other elements, these elements will obviously waste some space.
The organizational structure of this control is managed by a class at the top level representing the window. It has a group set. Each group contains items. Each item is the basic unit, similar to a checkbox. Each group consists of a header and a "customer zone. You can click the header to expand and collapse it, and the button on the left uses seven frames to get the rotation animation. As follows:
Another control is the clock control, which imitates the alarm setting control on the Windows Mobile System. It is mainly used to set the time (such as the alarm clock). It has two built-in attributes: hour and minute, with no date. Therefore, this is the main difference between it and datetimepicker. You can drag the sub-needle and the hour hand to set the time. The clock control is mainly provided for users to set the time. Therefore, the principle pursued in drawing is efficient and time-aware, not in the beautiful and gorgeous interface, therefore, it looks "simple ". The default unit of the sub-needle drag in the control is 5 minutes (you can also set it to the minimum 1 minute resolution, the movement is more stable when dragging), and the pointer capture Error Buffer is about 3 minutes.
Both controls use the memory rendering technology to prevent flickering.
Due to the urgent development process, in particular, the multi-choice control still lacks sufficient testing. Some interface methods may need to be further improved, and some interfaces need to be added. I will not use it here because of limited energy.CodeFor more information, see the demo project code. There is a mulselctl. h header file in the release folder. I have defined some corresponding macros to imitate the Windows SDK practice. For time reasons, I have not provided specific instructions.
Finally, we will add some technical summary:
(1) When reading and writing text files, try to avoid using Unicode functions (such as fgetws) Because garbled characters may occur during Chinese reading and writing. Therefore, this control first converts Unicode to ANSI and then interacts with the file.
(2) When writing a text file, you should convert "\ r \ n" to a single "\ n". Otherwise, when writing a text file, the underlying function provides proprietary translation, \ r \ n is written as \ r \ n. This is especially important when you exchange data between text and files in a text box.
(3) To write a custom control as a DLL to be loaded and used by other processes, add the cs_global style to the classstyle. Otherwise, other processes cannot create their instances.
(4) A custom control may be created for multiple instances, so the window process cannot use static variables to hold internal data (Status) related to the window instance ). This is different from the process of writing common Windows (Main Window, modal dialog box). Because they are generally unique within the process range, you can use static variables to hold window data, pay special attention to this. When registering the window class, inform the system to reserve the size of extra window data for each window, and allocate and fill in data during wm_nccreate.
The download link between the demo project and the control release package (*. H, *. Lib, *. dll) is as follows:
Http://files.cnblogs.com/hoodlum1980/MulSelCtl_BIN.zip
[Update]
[1]. Fixed a bug in the multiple-choice control. When you click the checkbox on the groupheader, the internal status is not updated. The status of the checkbox is incorrect when you click it later. ;
[2]. In the demo project dialog box, the drag unit setting (1 or 5 minutes) of the new clock control is added ). 2013-5-5.