One of the CommON family (reposted) in the driver VC

zhaozj2021-02-16  59

Disclaimer: Due to the use of many VC novices and VC controls in the 9CBS forum. I just have a previously downloaded information, which is more detailed. So send out and share it. But due to time long, you are no longer available to download the address. So you can only publish in a collection method. The following is the original author's unit and name. Apo here!

Song Libo, Tieling Municipal Committee, Liaoning, Tieling, Liaoning Province, Tieli, Tie Libo 1. Song Libo 1. Image List Control Image List 3. List Control and View List Control & List View 4. Tree Control and View Tree Control & Tree View 5. TAB Control & Tab View 6. Toolbar Control Toolbar Control 7. Schedule Control Progress Control 8. Slide strip Control Slider Control 9. Rotate Button Control Spin Button Control 10. Status strip Control Status bar Control, most of There are two packages forms in the MFC class library, namely control classes, and view classes, the control class is mainly provided by direct use control, and the viewing class is provided by indirect use, the optimism can be better. The control class is integrated into the MFC structure, and the use of reference categories can be used to direct the control of the nested in these controls. Both don't have much difference in the method of use, take list control classes and view classes, when you create a list, you can use the ClistCtrl & Ctrllist = getListCtrl () member function to get the view class reference Ctrllist, you can use a list. The view function is performed on each operation (Ctrllist.Add, etc.).

Chapter 1 Exercises Chetctrl Header Control (CHEADERCTRL) is usually applied to the list of text or data in the window. Generally, the title of the data column may include a plurality of portions, and the user can drag each portion and control the width of each column. The header control class provides the basic method of normal header control, only in the Windows 95, which is included in the version of the system, which is included in the AFXCMN.H file, generally used in combination with the tag control (CTabCtrl) and list control (ClistCtrl). 1.1 Head Control of Object Structure 1.1.1 Header Control Objects Creating Method Creating Header Control Object Create Creating Head and Binding Object CheaderCtrl :: Create The format is as follows: BOOL CREATE (DWord DWStyle, Const Rect, CWND * PPARENTWND, UINT NID); its return value is not zero initialization, otherwise it will fail. The parameter DWSTYLE is used to determine the header control type; RECT is used to determine the size and position of the header control; the PARENTWND is used to determine the parent window of the header control; NID is used to represent the flag of the header control. The header control style includes: HDS_BUTTONS represents the top control appearance and a button; HDS_HORZ indicates that the header is controlled horizontally; HDS_VERT indicates that the header is controlled to vertical; HDS_HIDDEN indicates that the header control is hidden mode. It can also use ordinary type control style, including: CCS_BOTTOM setting control position at the bottom of the parent window, the same width as the parent window; CCS_NODIVIDER forms two pixels on the top; CCS_NOHILITE forms a pixel on the top of the control District; CCS_Nomovey resets the size and horizontal arrangement when responding to the WM_SIZE message; CCS_NoparentAlign enables control to automatically close to the top or bottom of the parent window; CCS_NORSIZE sets the initial size or new value to make the control usage default width and height; CCS_TOP set in the parent window customer area The top and the same width as the parent window; the same head control can also use the window control style, including: ws_child creates a sub-window, cannot be used for the WS_POPUP window type; WS_Visible builds an initial invisible window; WS_DISABLED establishes an initial time Invalid window; WS_GROUP determines the control group that can be moved by cursor; WS_TABSTOP determines that the TAB controls the mobile site; the header control is generally divided into two steps, first determines the data structure of the header control, and then establish the header control and bind the object. . 1.1.2 The properties of the attribute header control of the header control include obtaining the number of projects in the header control, obtaining the contents of a project in the header control, and setting the contents of a project in the header control. 1.1.3 Operation Method of Header Control Header Control The operation method includes inserting a new project insertItem in the header control, deleting a project deleteItem and drawing the project DrawItem in the header in the header control.

1.2 The data structure of the header control is first controlled using the header, first must establish a data structure HD_Item, which is defined as follows: typedef struct _hd_item {uint maask; file: // Structural member Valid bit int Cxy; File: // The width of the header project is lpstr psztext; file: // Header project content hbitmap hbm; file: // The location handle of the header item INT CCHTextMax; file: // Header content string length int FMT; File: // Table The format of the header project lParam LParam; file: // application defined 32-bit data} HD_Item; shield control bit illustrates the valid data included in the data structure member, which can be a combination of the following flag: HDI_bitmap HBM member valid HDI_Format FMT member is valid HDI_LPARAM LPARAM Members Valid HDI_Text Psztext and CchtextMax Members Valid HDI_WIDTH CXY Members Valid and determine that the project width value format flag bit FMT can be combined with the following flag: HDF_CENTER header project HDF_LEFT header project left align HDF_Right header project right align HDF_bitmap header Displaying a bitmap HDF_OWNERDRAW By the main window Sheet Project HDF_String Header Project to a String 1.3 Head Control Application Skills Since the header control cannot be used separately, it is primarily a list of list control and label control, and more text Heads are more common, INSERTITEM, SETITEM, and GETITEM are commonly used methods. If you use INSERTCOLUMN attributes when listing, you can add a list of text titles, specific usage and skills, see list control, and label control. The following is specifically described below to add a list of tables in list control: lvcol.psztext = "Name"; // Set the first list of head name lvcol.isubitem = i; file: // Table column number lvcol.cx = 70; file: // Table column width m_listctrl.insertColumn (i , & lvcol); // Insert a table column lvcol.psztext = "Number"; // Set the second list of head name LVCol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); // Insert a table list ... // Other code

Chapter 2 Drive CIMAGELIST Image List Control (CIMAGELIST) is a collection of the same size image, each collection is based on the index serial number of the image, and the image list is typically constructed of a large icon or bitmap, including transparent bitmap mode. . You can use the Windows32-bit application interface function API to draw, build and delete images, and increase, delete, replace, and drag images. Image list control provides the basic method of controlling image lists, which can be implemented in Windows 95 and later. 2.1 Image Control Object Structure 2.1.1 Image Control Data Members M_HIMAGELIST Control Handle 2.1.2 Image Control Creation Method CIMAGELIST & ImagList Create Control Object Structure Create Initializing Image List and Binding Object Image Control The establishment method is as follows: BOOL Create (int cx, int cy, UINT nFlags, int nInitial, int nGrow); BOOL Create (UINT nBitmapID, int cx, int nGrow, COLORREF crMask); BOOL Create (LPCTSTR lpszBitmapID, int cx, int nGrow, COLORREF crMask) Bool Create (CIMAGELIST & Imagelist1, Int Nimage1, Cimagelist & Imagelist2, Int Nimage2, Int DX, INT DY); The meaning of each parameter is: CX defines the width of the image, the unit is pixel; CY defines the height, unit of the image For pixels; NFLAGS determines the type of an image list, which can be a combination of the following values: ILC_COLOR, ILC_COLOR4, ILC_COLOR8, ILC_COLOR16, ILC_COLOR24, ILC_COLOR32, ILC_COLORDDB and ILC_MASK; Ninitial is used to determine the number of images included in the image list; NGROW is used to determine The image list can be controlled. NbitmapID is used to determine the bitmap flag value of the image list contact; Crmask represents the color mask bit; the lpszbitmapID is used to determine the identity string containing the bitmap resource; image list pointing to a pointer to the image list control object; NiMage1 Image list 1 included Number of images included in the NIMAGE1 image list 1 Quantity; ImageList2 points to a pointer to the image list control object; the number of images included in the NIMAGE2 image list 2; DX represents the image width in pixels; DY represents the image height of the pixel. Similarly, the establishment of image control also includes two steps, first establish an image list structure, and then establish an image list control. 2.1.3 Image Control Attribute Class Image Control The attribute class includes returning m_himagelist. Control handle GetSafeHandle, obtain the number of images in the image list GetImageCount, set the background color setbkcolor of the image list, the background color setbkcolor of the image list, and obtain the image Information setbkcolor. 2.1.4 Image Control Operation Method Image Control The operation method includes binding an image list to an object on an object, releasing the image list on the object and returns a handle DETACH, deleting an image list deleteimagelist, add an image to an image In the image list, add and remove an image from the image list. 2.2 Image Control Application Skills For image control, the same cannot be used separately, and must be combined with list control, tree control, and label control, and the specific application skills are introduced below.

2.2.1 Image Control In List Control 2.2.1.1 Setting Image Control ClistCtrl :: SetImageList's call format as follows: CIMAGELIST * PIMAGELIST (CIMAGELIST * PIMAGELIST, INT NIMAGELIST); its return value refers to a forward image list control A pointer, if there is no previous image list, null; where the parameter PIMAGELIST is the identifier of the image list, NIMAGELIST is the type of image list, which can be the following value: Lvsil_NORMAL uses a large icon list; lvsil_small uses small icon mode Make an image list; LVSIL_STATE performs an image list in an image state; 2.2.1.2 acquired image control CListCtrl :: getImagelist's call format is as follows: CIMAGELIST * GetImageList (Int nimagelist) const; its return value is a pointer to the image list control, where NimageList is used To determine the value of the image list of the return value, the value is the same as the set image list function. 3 Image Control Application Example CIMAGELIST CIL1, CIL2; file: // Defines the size of the size of the size of the image CVCListApp * PAPP = (CVCListApp *) AFXGetApp (); // Number of list control program CIL1.CREATE (32, 32, True, 2, 2); File: // Established 32-bit image control cil1.add (PAPP-> Loadicon (IDi_gj))); // Increase the selected status image cil1.add (PAPP-> loadicon (IDI_XS)); // Increase the non-selection status image Cil2.create (16, 16, true, 2, 2); file: // Establish 16-bit image control Cil2.add (PAPP-> Loadicon (IDi_gj)); // Increase the selected status image CIL2. Add (PAPP-> Loadicon); // Increases non-selection status image m_listctrl.setimagelist (& Cil1, Lvsil_NORMAL); / / Set large icon control M_ListCtrl.setimageList (& Cil2, lvsil_small); // Set small icon control 2.2. 2 Application Skills in Tree Control 2.2.2.1 Setting Image Control CTreeCtrl :: SetImageList's call format is as follows: CIMAGELIST * SETIMAGELIST (CIMAGELIST * PIMAGELIST, INT NIMAGELISTTTTTYPE); its return value is a pointer to the front image list, Otherwise, the NULL; the parameter pimagelist is the identifier of the image list. If the PimageList is NULL, all images will be cleared from the tree control; nimageListType is the type setting of the image list, which can be one of the following: TVSIL_NORMAL Set the normal image list These include selected and non-selecting two icons; TVSIL_State Sets the image list state, refers to the user-defined state; 2.2.2.2 acquisition image control CTreeCtrl :: getImagelist's call format is as follows: CIMAGELIST * GetImageList (uint nimage); if the call is successful Returns the image list control pointer, otherwise null NIMAGE is identical to the image list type of the return value, which is identical to the acquisition of the image list.

2.2.2.3 Image Control In Tree Control In Tree Control CIMAGELIST CIL1, CIL2; // Defines Size Mark Number List CVCTreeApp * PAPP = (CVCTreeApp *) AFXGetApp (); // Get application pointer Cil1.create (16, 16, 16, 16, ILC_COLOR, 2, 2); // Establish image control Cil1.add (PAPP-> Loadicon (IDi_PM))); // Increase the selected status image cil1.add (PAPP-> loadicon (IDi_cj)); // Increase non-selection state Image m_treectrl.setimagelist (& CIL1, TVSIL_NORMAL); // Setting the image control list then sets the following settings in the structural definition of tree control: tcitem.Iimage = 0; file: // Setting an unselected image index number Tcitem.Item.item. ISELECTEDIMAGE = 1; // Setting When selected Image quotation marks 2.2.3 Image Control in the label 2.2.4 Signing application skills 2.2.4.1 Set image control CTabCtrl :: setimagelist CTABCTRLIST * SETIMAGELIST (CIMAGELIST * PIMAGELIST); The return value is a pointer to the forward image list, and if there is no previous image list, it is null; PimageList is an image list pointer that identifies the Tab control. 2.2.4.2 Acquisite Image Control CTABCTRL :: GetImagelist () himagelist getimagelist () const; its return value is a list pointer to the Tab control, and is NULL if the call is unsuccessful. Its application skill is more simple than the first two, and details will not be described here.

Chapter 3 Exercises CLIST3.1 List Control of List Control and List Control & View This is primarily used to display a set of data records in various ways to make various operations, Windows98 / 95 in Explorer in Resource Manager "Large Icon | Small Icon | List | Detailed Resources" is a very good typical application. The records in the list may include a plurality of data items, or may include a size icon indicating the data content to indicate various attributes of data records. The list control provides the basic method for the Windows list function, and the list of view functions using the list can perform a variety of operations, and obtain a reference to the list-dependent list control by calling the member getListCtr (getListCtrl & ctrllist = getListCtrl. )), You can perform various operations as the list control. Operating a list of basic methods for: Creating list controls; create list of images required for list control; add table columns and entries to the list; for a variety of controls, mainly include find, sort, delete, display Ways, arrangements, and various message processing functions, etc .; finally undo list control. For a list control, its most commonly used display control mode is: large icon mode (LVS_ICON), small icon mode (lvs_liston), list display mode (LVS_LIST), and detailed information (ie report LVS_REPORT) display mode. This can be implemented by setting its display mode properties. To control the style of the window where the list is located, you can implement the functionality getWindowlong and SetWindowLong. To control the alignment of the list icon, you can implement the style lvs_aligntop or LVS_ALIGNLIGNTOP or LVS_ALIGNLEFT of the list window, 3.2 list controls 3.2.1 list control Establishment Method CListCtrl & ListCtrl Defines the Structure Create Creating List Control and Bind Object List Control CListCtrl :: Create The call format is as follows: Bool Create (DWord DWStyle, Const Rect, CWnd * PparentWnd, uint NID); parameter DWStyle To determine the style of the list control; RECT is used to determine the size and position of the list control; PParentWnd is used to determine the parent window controlled by the list, which is usually a dialog; NID is used to determine the logo of the list control.

The style of the list control can be a combination of the following value: LVS_alignleft is used to determine the size icon of the entry to display the left alignment; LVS_ALIGNTOP is used to determine the size of the entry to display; LVS_AUTOARRANGE is used to determine the size of the entry The icon is displayed automatically; the LVS_EDITLABELS setting entry text can be edited, the parent window must have a LVN_ENDLABELEDIT style; LVS_ICON is used to determine the display mode of the large icon; LVS_LIST is used to determine the list mode display; LVS_nocolumnheader is used to determine how to determine when detail The list header is not displayed; LVS_NOLabelwrap is used to determine the text item of the icon in a single line; lvs_noscroll is used to block the scroll bar; LVS_NOSORTHEADER is used to determine that the list head cannot be used as a button function; LVS_OWNERDRAWFIXED allows the self-painted window when it is a detailed list; LVS_Report To determine the display method in detail; LVS_SHAREIMAGELISTS is used to determine a list of shared images; LVS_SHOWSELALWAYS is used to determine the selected entry mode; LVS_SINGLESEL is used to determine if there is only one selected; lvs_smallicon is used to determine Small icon display mode; LVS_SORTASCENDING is used to determine the description of the entry text; LVS_SORTDESCENDING is used to determine the description of the item text when sorted by the entry; 3.2.2 list control of the attribute class list control Attribute classes include the background color GetBKColor, setting list control, set, list-controlled image list GetImageList, set the list of images, the number of list items GetItemcount, get the list of attributes GetItem, obtained The item related data GetItemData, settings table item properties setItem, settings related to the entries, setItemData, get the associated next entry GetNextItem, set list-controlled text color setTextColor, get list-controlled text background color GetTextBkcolor, Maximum number of setup items setItem COUNT and the number of getSelectedCount, which obtained the selected entry. 3.2.3 List The list of operation method list controls the operation method of controlling a new entry INSERTITEM, delete a group DeleteItem, the location of the Sortest, the test list hittest, redraw the item RedrawItems, insert a list of INSERTCOLUMN Delete a table color deleteColumn, edit a table entry text EditLabel and redraw a table item DrawItem et al. 3.3 List Control of Data Structure List Control contains two very important data structures LV_Item and LV_COLUMN.

LV_item is used to define a list of list controls, and LV_COLUMN is used to define a list of list controls, and its definition format is: typedef struct _lv_item {uint maask; file: // Structural member mask IIITEM; file: // Tablet index number int ISUBITEM; file: // Sub-forms index number uint state; file: // entry status uint statemask; file: // Status Validity mask bit LPTSTSTSTSTEXT; file: // Table Name text INT Cchtextmax; file: // Table Name The maximum length IImage; // Test number of the table item icon LParam lparam; / / 32-bit number related to the entry}} lv_item; typef struct _lv_column {uint maask; file: // structure Members Validity Shield INT FMT; File: // Table Column Alignment INT CX; File: // Table Column Pixel Width LPTSTSTSTSZTEXT; File: // Table of Top Name INT CCHTextMax; File: // Table The text length INT ISUBITEM; file: / / The sub-table item index number} lv_column associated with the table column; where the FMT can take the lower value: LVCFMT_CENTER table column alignment LVCFMT_LEFT table column left alignment 3.4 list control application skills example this article Give the specific instance demonstration list control and application skills for the previous header control and image list.

The steps are as follows: 1. "File-> New-> Projects-> MFC AppWizard (EXE)" establishes a project named VCLIST, selecting a dialog based application during the establishment process; the default in the dialog box Control delete and set the Language field in all dialog properties to Chinese (PRC) to support the application to support Chinese; create two icons IDi_gj and IDi_xs to represent the icon selection and non-selective state, for each icon 32x32 and 16x16 sizes should be established to ensure the needs of the program; 3. Design the combination box (Group box) in the dialog window, set four wireless buttons (Radio) "large icons | small icons | list | Information, simultaneous setting, delete, and turn off three control buttons (button), and set size appropriate list control (List Ctrl) in the dialog, the corresponding identifier is as follows: Control Name Title Name Identifier Symbol list Control IDC_ListCtrl Combination box mode IDC_STATIC wireless button large icon IDC_STDICON small icon IDC_SMLICON list IDC_LIST information IDC_REPORT button sequence IDC_SORT Delete IDC_DEL Turn Close IDOK 4, when setting the wireless button, it is necessary to note that only large icons have the group attribute of only the large icon. The state of the other wireless buttons is the default. 5, select the list control control, select "View-> ClassWizard-> Memory Variables", and use IDC_ ListCtr to introduce member variables, the variable type is: Variable Name Variable Type M_ListCtrl Control ClistCtr, using "Messages Map" for each wireless button And the command button to increase the control function.

6, then add the following code in the included file and code file: (1) Add data structure and definition TypeDef struct tagsps {file: // definition structure char SZPM [10]; file: // Product Name INT LX; file: // 0-gj 1-xs char szsl [10]; file: // quantity char szdj [10]; file: // Price char szje [10]; file: // amount} sps; int CALLBACK Comparefunc (LParam LParam1, LParam LParam2, LParam LParams); (2) Increasing the initialization data and program definition file: / / Input at the beginning of Vclistdlg.cpp Add the data structure Initialization SPS SPS [] = {// Information {"Red plum", 0, "1000", "30", "30000"}, {"Huangmei", 0, "1000", "29", "29000"}, {"Green Mei", 0, "1000", "28", "28000"}, {"Qingmei", 0, "1000", "27", "27000"}, {"Baimei", 0, "1000", "31", "31000" "}, {" Red plum ", 1," 1000 "," 30 "," 30000 "}, {" Huangmei ", 1," 1000 "," 29 "," 29000 "}, {" Green Mei ", 1, "1000", "28", "28000"}, {"Qingmei", 1, "1000", "27", "27000"}, {"Baimei", 1, "1000", "31", "31000"}}; CIMAGELIST CIL1, CIL2; // Size Image List (3) Increases Head, Images, and List Control Creating Code Bool CvClistdlg :: OnNInitdialog (); File: ONInitDialog (); file: //......// Other code // Todo: Add Extra Initialization Here Added LV_i Tem Lvitem; LV_COLUMN LVCOL; INT I, IPOS, IITEMNUM; CVClistApp * PAPP = (CVClistApp *) AFXGetApp (); // Create an image list Cil1.create (32, 32, True, 2, 2); Cil1.Add ( PAPP-> LOADICON (IDI_GJ)); Cil1.Add (PAPP-> Loadicon); Cil2.create (16, 16, True, 2, 2); Cil2.Add (PAPP-> Loadicon (IDI_GJ)); Cil2.add (PAPP-> Loadicon);

// set the image list m_ListCtrl.SetImageList (& Cil1, LVSIL_NORMAL); m_ListCtrl.SetImageList (& Cil2, LVSIL_SMALL); // add to the table column list lvcol.mask = LVCF_FMT control | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.fmt = LVCFMT_CENTER ; // hit i = 0; lvcol.psztext = "Name"; lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); lvcol.psztext = "Number"; lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); lvcol.psztext = "single price"; lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); lvcol. PSZText = "Gold); lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); file: // Add item IIITEMNUM = SizeOf (SPS) / sizeof (SPS) For (i = 0; I

void CVCLISTDlg :: OnStdicon () // set large icons displayed {// TODO: Add your control notification handler code here LONG lStyle; lStyle = GetWindowLong (m_ListCtrl.m_hWnd, GWL_STYLE); // get the current window type lStyle & = ~ LVS_TYPEMASK File: // Clear the display mode LStyle | = LVS_ICON; File: // Set the display mode setWindowlong (m_listctrl.m_hwnd, gwl_style, lstyle); // Settings window type} void cvclistdlg :: OnSmlicon () file: // Set Small icon display method {// Todo: add your control notification handler code here long lstyle; lserve = getWindowlong (m_listctrl.m_hwnd, gwl_style); // Get the current window type LStyle & = ~ LVS_TYPEMASK; File: // Clear display mode LStyle | = Lvs_smallicon; file: // Sets the display mode setWindowlong (m_listctrl.m_hwnd, gwl_style, lstyle); // Setting window type} Void CVClistdlg :: OnList () file: // Settings list display method {// Todo: add your = Control Notification Handler Code Here Long Lstyle; LStyle = getWindowlong (m_listctrl.m_hwnd, gwl_style); // Get Current Window Type LStyle & = ~ LVS_TYPEMASK; File: // Clear Display Method LStyle | = LVS_List; File: // Set display method Setwindowlong (m_listctrl.m_hwnd, gwl_style, lstyle); // Settings window type} void cvclistdlg :: onreport () file: // Details display method {// Todo: add your control notification handler code here LONG lStyle; lStyle = GetWindowLong (m_ListCtrl.m_hWnd, GWL_STYLE); // get the current window type lStyle & = ~ LVS_TYPEMASK; file: // clear the display bit lStyle | = LVS_REPORT; file: // set the display SetWindowLong (M_ListCtrl.m_hWnd, GWL_Style, LStyle); // Setting Window Type} (5) Implementation of Delete Features To implement the delete function, you must obtain the number of options and entry of the selected entry, and need to be deleted from the back forward, The reason is that after each entry is deleted, the index number of each item will decrease, and if the method from the backward deletion is taken, it will cause the selected entry that cannot be properly deleted, and its function code is as follows: Void cvclistdlg :: Ondel () file: // Delete button function {// Todo: add your control notification handler code here int i, istate; int nitemselected = m_listctrl.getSelected COUNT (); // Selected table item number int nInmcount = M_ListCtrl.getItemcount (); // Extrame IF (NItemSelected <

1) RETURN; for (i = nitemcount-1; i> = 0; i -) {uState = m_listctrl.getItemState (i, lvis_selected); if (istate! = 0) m_listctrl.deleteItem (i);}} 6) The implementation list of the sorting function has a special feature. When displayed in a detailed information, the top head of the list can be used as a button, which can be controlled by the list of created. When the mouse point hits the list name, the list control sends an LNV_COLUMNCLICK message to its parent window. Use the LNV_ColumnClick message corresponding to the list control IDC_ListCtrl in the class-oriented to add the corresponding processing function, and can be arranged in a particular order. Its function is used to see the program, where ISORT is sorted back column index number, (pfnlvcompare) Comparefunc is a specific sorted callback function, that is, the sorting process implemented by the mouse click is a dedicated sort of third-party development. The function is implemented, the sort function is just the specific comparison operation of the implementation entry, and the entire sorting process is implemented by the SortItems property by continuously calling this function. The normal sorting process is an ascending mode. By switching the parameter values ​​in the sort function, you can replace the sequence arrangement, and the PARAM1 is changed to the PARAM2. The first two parameters of this callback function are the index number of the table item in the table, and the third parameter is sorted.

void CVCLISTDlg :: OnColumnclickListctrl (NMHDR * pNMHDR, LRESULT * pResult) {file: // click the left mouse button handler header NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR; // TODO: Add your control notification handler code here static int iSorted = -1; // arrangement order number if (pNMListView-> iSubItem == iSorted) return; iSorted = pNMListView-> iSubItem; m_ListCtrl.SortItems ((PFNLVCOMPARE) compareFunc, iSorted); * pResult = 0;} file: / / Sort When comparing the callback function INT CALLBACK Comparefunc (LParam LPARAM1, LPARAM LPAR * TEXT1, * TEXT2; Switch (LParamsort) {Case 0L: Text1 = SPS [lparam1] .szpm; Text2 = SPS [lParam2] .szpm; break; case 1L: text1 = SPS [lParam1] .szsl; text2 = SPS [lparam2] .szsl; break; casse 2l: text1 = SPS [lparam1] .szdj; text2 = SPS [lparam2]. SZDJ; Break; Case 3L: Text1 = SPS [lParam1] .szje; Text2 = SPS [lparam2] .szje; break;} return (strcmp (text1, text2)); / / result is> 0 = 0 <0} You can also achieve the sorting function by a dedicated button, such as the function code corresponding to the sort button of this article is as follows: Void CvClistdlg :: Onse inrth () {// Todo: Add Your Control Notification Handler Code Here M_ListCtrl.SortItems ((PFNLVCompare) Compa REFUNC, 0);} 7, the drill tips for the list are in the list, the method is basically the same as the list control, but the list is implemented in the window and the list control is implemented in the dialog box. The various functions are implemented by the menu and the list control is implemented by a button, and the list control needs to create a list control control in the dialog and the list is directly occupied by the entire window. Just use the button and list during the design process. The control design process becomes a menu design, and note that the function increase is in the class wizard is to operate through the menu command, and the acquisition of the column watch reference is increased in front of each function function (ClistCtrl & ListCtrl = getListCtrl ()), and the rest The data structure and code do not need to be modified, and it is easier to implement. The list of the list controls and views of the author is as follows: list control drill sample results list view drill sample results

Chapter 4 Exercises CTREE4.1 Tree Control Main Tree Control and View (Tree Control & View) is mainly used to display data items with a hierarchy, such as disk directory in the resource manager, etc., for users to carry out various kinds of select. Each data item in the tree control includes a text string of the data item name and an image for representing the data item, and each data item can contain each subkey, and the entire structure is like a directory tree. For data items containing various sub-items, you can deliver or closely through the mouse, which can achieve different display forms of tree control by controlling the different styles of the tree. These styles include: tvs_haslines indicates that connects the parent and its subtries below, which can make the display hierarchy of the tree clearer, but there is no connection between the individual subtries without parents; TVS_LinesTroot Indicates that there is a connection between the subtries under the root without the parent; TVS_HASBUTTONS indicates a button with " " or "-" in front of the parent with children, which makes the user You can implement the subkey's expansion and closing by clicking this small button. When there is a child, the initial state of the button is " ". When the child is expanded, press the small button by " " to "-" Number, when the child is closed, the small button is "-" becomes " ", which is also invalid for roots. If you need to be implemented by combining the TVS_LinesTroot style; TVS_EDITLABELS means allowing users to click on input focus Data items to modify their name. For tree control, the MFC is also encapsulated in two forms, namely tree control (ctreectrl), and ctreeView, to meet the different needs of users. For general requirements, users are applied in the dialog box, using tree control comparison Convenient, for users with high requirements, there is also a variety of convenience characteristics of the view window when using the tree, can better meet the requirements of the document / view structure. When the tree is used in the window, the tree will be adjusted by the customer area full of two windows and automatically adjusts the adjustment of the frame structure of the window, and can have a variety of menus, accelerator keys, and toolbars. Command message. When using the tree, you can use its member function ctreeView to get one reference, you can apply as soon as tree control: CTreeCtrl & TreeCtrl = getTreeCtrl (). 4.2 Tree Control Object Structure 4.2.1 Tree Control Establishment Method CTREECTRL & TreeCtr CTREECTRL & TREECTRL Creating Tree Control Structure Create Creating Tree Control and Binding Object Tree Control CTREECTRL :: CREATE Call format as follows: BOOL CREATE (DWord DWStyle, Const Rect, CWnd) * PParentWnd, Uint Nid); where parameter dWStyle is used to determine the type of tree control; RECT is used to determine the size and position of tree control; PParentWnd is used to determine the parent window controlled by the tree, and general is a dialog and cannot be null; NID; NID; NID Used to determine the logo of tree control.

The style of the tree control can be a combination of the following value: TVS_haslines indicates that the tree control is connected between the subtries; TVS_LINESATROOT indicates that the tree control is connected between the roots; TVS_HASBUTTONS indicates that the tree control is expanded on the left side of the parent. Close the control button; TVS_EDitLabels indicates that the name can be controlled by the mouse click; TVS_ShowseLalWays indicates that the selected item remains selected even when the window will lose the focus; tvs_disabledRagDrop indicates that the tree control sends a TVN_BEGINDRAG message 4.2.2 Tree control attribute class The control attribute class includes acquiring the number of items in the tree control, acquires the deviation value of the tree control relative to the parent, acquire the tree control image list control handle GetImageList, set the tree control image list control handle setimagelist, get the next tree Item GetNextItem, determined whether the given tree item contains child item ItemHaschildren, obtain the tree item getchildIndItem, get the next type of tree item GetNextSiblingItem, get the top of the same tree item getPrevsiblingItem, get the parent tree getParentItem, get the first visual tree Item GetFirstvisibleITEM, get the next visual tree item GetNextVisible Item, get the previously visible tree item getPrevvvisibleItem, get the selected tree item getSelectedItem, get the root tree GetrootItem, get the property GetItem, set the property setItem setting tree , Obtain the state of the tree item, setting the status of the tree item setItemState, get the GetItemImage associated with the tree item, set the image of the tree item associated image setItemImage, get the tree item text GetItemText, set the tree item text setItemtext and get the tree item editing control handle GetitControl Wait. 4.2.3 Tree Control Operation Method Tree Control The operation method includes inserting a tree term INSERTITEM, deleting a tree item DeleteItems, deleting the child expleteAllItems, unfolding or closing the child item EXPAND, selecting a specific tree item SelectItem, select one The tree item is the first visual tree item SelectSetFirstvisible, editing a visual tree item EditLabel and sorting the sub-tree item SortChildren, which is given to the parent tree. 4.3 Tree Control Data Structure You need to understand two very important data structures TV_Item and TV_INSERTSTRUCT when using tree control, the previous data structure is used to represent tree-controlled tree item information, and the latter data structure is used to define the tree The item is added to the data content required in the data control.

In addition, the three data structures of NM_TreeView, TV_Dispinfo, and TV_HitTestinfo have been needed. The definition methods of these data structures are as follows: 4.3.1 Basic data item structure TypedEf struct _tv_item {uint mask; file: // Structural member Valid shield bit htreeItem Hitem File: // Data Item Control Handle Uint State; File: // Data Item Status Uint Statemask; File: // Status Valid Shield LPSTR PSZText; File: // Data Item Name Strings INT CCHTextMax; File: // The maximum length of the data item name; file: // data item icon index INT ISELECTEDIMAGE; // selection data item icon index number int cchildren; file: // child ID LPARAM LPARAM; File: // Program definition 32 Bit Data} TV_ITEM, FAR * LPTV_ITEM; 4.3.2 Insert Tree Item TypeDef Struct_TV_INSER TSTRUCT {HtreeItem HParent; File: // Parent Control Handle HtreeItem HinsetAfter; File: // Insert Tree Item Tv_Item Item; File: / / Data item structure} TV_INSERTSTRUCT, FAR * LPTV_INSERTSTRUCT; where the insertion is inserted, if it is TVi_first or TVi_last, the first or last side of the tree control is inserted, and if it is TVi_sort, the inserted tree is automatically inserted into the right position. .

4.3.3 Tree Control Notification Message Structure TypeDef Structure_nm_treeView {NmHDR HDR; File: // Notification Message Handle Uint Action; File: // Notification Message Sign TV_Item ItemOLD; File: // The original data structure TV_Item ItemNew; file: // New data structure Point PTDRAG; file: // Drag pointer} nm_treeview; 4.3.4 acquire or set data structure TYPEDEF STRUCT _TV_DISPINFO {TVDI NMHDR HDR; file: // Notification Message Control Handle TV_Item Item; File: // Data Item Structure} TV_DISPINFO; 4.3.5 Refers to 4.3.6 Pin Test Data Structure TypeDef struct_tvhittestinfo {TVHTST POINT PT; File: // Customer Area Screen Card Pointer Uint Flags; File: / / Store Variables of Test Results HtreeItem Hitem; File: / / Test data item structure} TV_HITTESTINFO, FAR * LPTV_HITTESTINFO; where the FLAGS test results can be as follows: TVHT_ABOVE In the customer area, TVHT_BELOW is in the customer area and in the last item below TvHT_ONITEM is associated with tree items TvHT_ONITEMBUTTON on bitmap or tag on the button associated with the tree items on the bitmap associated with the tree item, TVHT_ONITEMLABEL on the link associated with the tree item, TvHT_ONITEMRIGHT on the right side of the tree item TVHT_ONITEMSTATEICON in the area on the user-defined status icon on the left side of the TVHT_TOLEFT in the customer area TvHt_toright Application Skills in the right side of the customer area 4.4 Tree control application Skills still introduce tree control and its and image list-based application skills based on dialog-based presentation: "File-> New-> Projects-> MFC AppWizard (EXE) "Establishing the project named VCTree, select the application based on dialog based" during the establishment process; delete the default control in the dialog, set the Language field in all dialogatures to Chinese (PRC To enable the application to support Chinese; establish two icons IDi_PM and IDi_cj to indicate the selection and non-selective state of the icon, and for each icon, two sizes should be established to ensure the needs of the program; Add Tree Control in the box window, set five buttons "Add | Delete | View | Sort | Off", its correspondence identifier is as follows:

Control Name Title Name Logo Sign Tree Control IDC_TREECTRL button Add Idc_ADD Delete IDC_DEL Search IDC_SORT Close Idok 5, Select Tree Control Control, Select "View-> ClassWizard-> Memory Variables. 骺刂 DC_TREECTRL Introduction Member variable, its variable type is: Variable Name Variable Type M_TreeCtrl Control CTreeCtrl Simultaneously Use "Messages Map" to add control function functions for each command button.

6, then add the following control code in the code file VCTREEDLG.CPP: (1) Add image list to define CIMAGELIST CIL1, CIL2; // Size Map Number List (2) Add Code Bool CvcTreedlg in the initialization file :: OnNitDialog () {cdialog :: OnInitdialog (); ... // Other code // Todo: add extra initialization here // Started Add Code CVCTreeApp * PAPP = (CVCTreeApp *) AFXGetApp () ; // Create an image list Cil1.create (16, 16, ILC_COLOR, 2, 2); Cil1.Add (PAPP-> Loadicon); cil1.add (PAPP-> Loadicon); M_TreeCtrl. SetImageList (& Cil1, TVSIL_NORMAL); file: // set the image list DWORD dwStyles = GetWindowLong (m_TreeCtrl.m_hWnd, GWL_STYLE); // get the original style tree control dwStyles | = TVS_EDITLABELS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT; SetWindowLong (m_TreeCtrl.m_hWnd , GWL_Style, DWStyles); // Setting style Char * CJ [4] = {"Yuxi Cigarette Factory", "Yunnan Cigarette Factory", "Shenyang Cigarette Factory", "Chengdu Cigarette Factory"}; // Root Data Name Char * PM [4] [5] = {{"Red plum one", "Hongmei Second", "Red plum three", "Hongmei Four", "Red Mei 5"}, // Product Data Item {"Bai Meiyi "," Bai Mei II "," Bai Mei Three "," Bai Mei 5 "}, {" Green Mei Yi "," Green Mei 2 "," Green Mei Three "," Green Mei Four "," Green Mei 5 "}, {" Qingmei 1 "," Qingmei Second "," Qingmei Three "," Qingmei Four "," Qingmei 5 "}}; INT I, J; HtreeItem Hroot, HCUR; / / Tree Control Project Handle TV_INSERTSTRUCT TCITEM; // Insert data item data structure Tcite m.hparent = TVi_root; // Increase the root TCITEM.HINSERTAFTER = TVi_last; // After the last item, tcitem.tem.mask = TVif_text | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; // set the mask Tcitem.Item.pszText = "Data Selection "; Tcitem.item.lparam = 0; // serial number Tcitem.Item.iImage = 0; // Normal icon TCITEM.Item.iselectedImage = 1; // Select the icon hroot = m_treectrl.insertitem (& tcitem); // Return Root hip for (i = 0; i <4; i ) {// increase the various manufacturers tcitem.hparent = hroot; tcitem.Item.psztext = CJ [i];

Tcitem.Item.lParam = (i 1) * 10; // child sequence hcur = m_treectrl.insertitem (& tcitem); for (j = 0; j <5; j ) {// increase each product TCITEM.hparent = Hcur; tcitem.Item.psztext = pm [i] [j]; tcitem.Item.lParam = (i 1) * 10 (j 1); // child serial number m_treectrl.insertitem (& tcitem);} m_treectrl .Expand (HCUR, TVE_EXPAND); // Expand tree} m_treectrl.expand (hroot, tve_expand); // Expand the previous tree Return True; // return true unless} (3) Increase the tree When the implementation of the item function is increasing the tree item function, in addition to the data structure of the insertion tree, it is necessary to note that the name of the new tree item is "new data", which is incremented to allow users. Set the custom name to the data item. Pay special attention to m_treectrl.editlabel (Hinsert) when programming; there is no other program command, otherwise this editing instruction is invalid. Void cvctreedlg :: onadd () {file: // Add sub-function function htreeItem HSEL = m_treeCtrl.getSelectedItem (); // Get the selection of the option handle if (hsel == null) return; // None options Return Static Int NADDNO = 100; // Number is greater than 100 for new data TV_INSERTSTRUCT TCITEM; / / Define Insert Items TCITEM.HPARENT = HSEL; File: // Set the parent handle TCITEM.HINSERTAFTER = TVi_last; // In the final increase TCITEM. item.mask = tvif_text | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; // Sets the mask TCITEM.Item.psztext = "Add Data"; TCITEM.Item.lParam = NADDNO ; // Index number increase tcitem.Item.iimage = 0; / / normal icon TCItem.item.iSelectedImage = 1; icon HTREEITEM hInsert = m_TreeCtrl.InsertItem (& TCItem) // when selected; // Add m_TreeCtrl.Expand (hSel, TVE_EXPAND); m_TreeCtrl.EditLabel (hInsert); // modify added Data} (4) Removing Tree Item Implementation When you implement the delete function, you should prompt the tree item where the child item is prompted to warn whether the user is deleted along with its child.

Void cvctreedlg :: Ondel () {file: // Delete subkey function function htreeItem HSEL = m_treeCtrl.getSelectedItem (); // acquire the option handle; if (hsel == null); // None options Return IF ( m_treectrl.ItemHaschildren (HSEL)) / / Judgment whether there is sub-IF (MessageBox ("manufacturer's product name, delete it together?" 5) The implementation of the sorting function is sorted in the order of all child items selected in characters. If you want to sort in other rules, you should use the sortchildrenitembc () function to make self-developing sorting procedures, this self-development The function is substantially the same as the functions implemented in the list control, and the reads of interest can be tested. Void cvctreedlg :: onsort () {file: // Sort subkey function HTREEITEM HSEL = m_treeCtrl.getSelectedDITEM (); // acquire the option handle; if (hsel == null); // None options Returns M_TreeCtrl. SortChildren (HSEL);} (6) Viewing the implementation viewing function to view the information of the selected tree item, the text name and identification number of the tree item is displayed in the function, you can find these two information as a lookup keyword, To view other more detailed information. Void cvctreedlg :: onview () {file: // View selected item function function htreeItem HSEL = m_treeCtrl.getSelectedDITEM (); // get the option handle; if (hsel == null) return; // None options Return CTRING CText = m_treectrl.getItemText (HSEL); // acquire data item name long IDs = m_treectrl.getitemdata (hsel); // acquire data item number char TEMP [100]; WSPrintf (TEMP, "Manufacturer:% s number:% 05D" , ctext, ids); MessageBox (Temp, "Select Information");} (7) Implementation of Modifying Functions If other processing, it will find that it is not modified after modifying the text name of the tree item, because it is because it is not modified. The modified result is not saved in the program, which is to be processed using the TV_DISPINFO structure and the SETITEMText function to process TVN_ENDLABELEDIT, which can correctly implement the modification function.

void CVCTREEDlg :: OnEndlabeleditTree (NMHDR * pNMHDR, LRESULT * pResult) {TV_DISPINFO * pTVDispInfo = (TV_DISPINFO *) pNMHDR; // TODO: Add your control notification handler code here if (pTVDispInfo-> item.pszText == 0) return; // User cancels the operation m_treectrl.setitemtext (ptvdispinfo-> item.hitem, ptvdispinfo-> item.psztext); // Set new data * PRESULT = 0;} 7 When the tree is as follows, the method is basically the same as tree control, but the tree control is implemented in the window and the tree control is implemented in the dialog, and the various functions of the tree are implemented by the menu and the tree control is passed. Buttons and other methods, tree control needs to create a tree control control in the dialog and the tree is directly occupied, as long as the button and tree control design process becomes the menu design during the design, and pay attention to the function function is The class wizard is to operate through the menu command, while adding a command to obtain a list of column watch references in front of each function function (CTREECTRL & TreeCtrl = GetTreeCtrl ()), and the remaining data structure and code do not need to be modified, and it is easier to implement. The operation results of the tree control and viewing procedures implemented are as follows: Tree control Example results Summit Examples Chapter 5 Exercise CTAB5.1 Script 5.2 Signing Control (Tab Control) is used in one window Such as the same user area in dialog, etc. Control the group display information or control information, control different information prompts by a set of tags, and the label can be a text description or a icon representing text meaning, or two A combination of people. For different selection labels, there will be a set of prompt information or control information corresponding to the user to interact, which is the most common in the attribute table of Windows 98. There is also a special type of label, namely TBS_BUTTONS style label, such a label appearance, a button, clicking change status through a mouse, generally used to perform some functions instead of being used to display or control information. When it comes to the label, the fastest thinking should be the property sheet, and the cooperation apps can be seen everywhere. The property sheet dialog is sometimes referred to as a multiPle-page Dialog or a tab dialog (Table Dialog), you can set up to 24 property pages, select different attribute pages through the top tags. . There is also a special property table dialog, just like the class wizard AppWizard in VC 5.0, there is no label for the user to select, but control the display of the property page in order, and there is a general property page. "Confirm", "Previous", "Previous", "Complete" and "Help". The label is controlled only in the MFC, that is, control class CTabctrl. You can add directly to the dialog box when you use the label, or you can use it as a sub-window in the window.

5.3 Sign 5.4 Signing Object Structure 5.4.1 Script 5.4.2 Signing Control Control CTABCTRL & TabCtr The Tag Control Object Structure CREATE Creation Label Control and Bind Object Tag Control CTabCtrl :: Create The call format is as follows: Bool Create (DWord DWStyle ": BOOL CREATE , Const Rect & Rect, CWND * PParentWnd, UINT NID); where parameter dWStyle is used to determine the tag control style; RECT is used to control the size and position of the label; PParentWnd is used to determine the parent window handle of the tag; NID to determine the label The identifier of the control. The tag-controlled style can be a combination of the following: tcs_buttons Indicates that the appearance of the label is defined as a similar button TCS_FixedWidth makes all tags with the same width TCS_FOCUSNEVER to make a specific tag to receive input focus TCS_FOCUSONBUTTONDOWN When the label is clicked by the mouse Click to receive input focus, and TCS_BUTTONS combined TCS_FORCEICONLEFT forced icon on the left, the remaining portion of the label is centered TCS_FORCELABELLEFT make icons, labels are left aligned TCS_MULTILINE allow the label to control multiple rows label TCS_OWNERDRAWFIXED allows the parent window painting from the tag TCS_RIGHTJUSTIFY label right aligned TCS_SHAREIMAGELISTS when the control label control is revoked Image None Underated TCS_ToolTips allows tag control to control the tool prompt control TCS_TABS tab normal display, for the default status TCS_SINGLINE Label only in one line, the default state TCS_RAGGEDRIGHT does not automatically fill the control area, the default state, the label control is also Some of the control style using the window: WS_CHILD Controls the Label Control Create a sub-window, can only create an initial visual label with WS_POPUP style to control WS_DISABLED to establish an initial unacceptable label to control the first one of the first one Controlling WS_TABSTOP Establishing a Tab Moved Label Control 5.4.3 Script 5.4.4 The attribute class tab control of the list of property classes includes obtaining the image list GetImageList associated with the label control, setting the label controlled image list setImageList, obtain tag control The total number of labels GetItemcount, obtain the relevant information of the specific tag in the label control GetItem, some or all of the properties of the label setItem, detection Before the selected label getcursel, set a label to select the status setcursel and obtain the label setcursel with the current input focus. 5.4.5 Sign 5.4.6 Operation Method Tag Control Method Tag Control Inclusion Insert a tag INSERTITITEM, delete a tag deleteItem, delete all items DELETEALLITEMS from tag control, remove an image list RemoveImage And draw specific one DrawItem in label control. 5.5 Sign 5.6 Signing Data Structure When using tag control, the function that must be used is inserted into the label in the label control.

The original shape of the function INSERTITEM is as follows: BOOL INSERTITEM (INT NITEM, TC_ITEM * PTABCTRLITEM); the TC_Item in this function is the data structure of the information used when the label is added, and the definition method of its data member is as follows: typedef struct _tc_item {uint mask; / / Determine the mask of the structure or set bit UINT LPRESERVED1; // Keep unused ilred lpreserved2; // Reserved unused LPSTR PSZTEXT; / / Label Name String INT CCHTextMax; // Label Name String Buffer Size Int Iimage; // Label controlled image index number LParam lparam; // application definition related 32-bit data} Tc_Item; When the mouse click on the label in the label control, the tag control sends a related notification message to its parent window, by processing These notification messages, the program can achieve various functions. 5.7 Basic Uses of Property and Properties Pages In tag control, the property sheet dialog and property page are essential. In the MFC class library, the property sheet dialog box CPRopertySheet is derived from the CWND class, and the property page CPROPERTYPAGE is derived from the CDIALOG class, and their usage is basically the same: 1. Create all the property pages. The method of creating a property page is the same as the method of creating a general dialog, using a dialog editor to create a dialog template for each property page, the difference is that the property should be selected when using the class wizard classwizard to generate a class. Page CPropertyPage as base classes, rather than uses general dialog box CDialog as base classes; 2. Create a property sheet dialog box, and add each property page created in advance, and the order of creation can be interchangeable, but To add the property page to the Property table dialog box after being created; 3, Display the Property table dialog. Although the property table dialog box CPROPERTYSHEET is not derived by the dialog class CDialog, the operation is very similar, calling the Domodal () function will display a modal property meter dialog, and call the create () operation Displays a non-modal property table dialog; 4, processing of data exchange. Similar to the dialog, the data exchange between the property sheet dialog and the object is also implemented by the data member 2, just the property table itself without data members, and actually exchange data members in the property page; 5, Treatment of the wizard dialog. If you want to display a wizard dialog, you should first call the SetWizardMode () function for the Wizard dialog for special processing. For the presence button, you should call setWizardButtons () to customize the button function of the wizard dialog. At the end of the user operation, the setFiniText () function should be called to set the "Complete" button to a valid state. 5.8 Skill 5.9 Signing Application Skills Example Program This article gives a document-based label application instance. The actual application skills of the label control are demonstrated by simply setting up menu, labels, and property tables in the Example Program. The program pops up to set the textual color, font, and modified attribute meter dialog boxes by selecting the menu option.

The actual steps are as follows: 1. Use the application wizard AppWizard to create a document-based engineering Tab, select a single document when selecting an engineering type; 2. Use the menu generator in the resource to delete the unused menu, and increase the following menu structure menu Name Identifier Setting (S) (Subset Menu Name) Background Set (B) IDM_BKGRND Prospect Setting (F) IDM_FRGRND 3 The property page CPROPERTYPAGE should be used as the base class, and all the belongings of the dialog box and menu are changed to Chinese. The four property pages and the control contents thereof are: (1) Text Properties dialog includes a text input box for input text, used to enter and modify text displayed on the window; (2) The font properties dialog includes three The box is used to determine the displayed font modification; (3) The word spacing property dialog includes a tag for displaying a prompt information and a text input box for inputting a word spacing size; (4) Color Properties dialog includes one Set the group box and three single-selection rounds; (5) Set a label for displaying input text.

The above-controlled setting parameters are as follows: Control Name Title Name Identifier String Label Control IDC_Tabctrl State Text Word Spacing (10-100) IDC_STATIC1 Edit Box IDC_LIST set Box Color IDC_STATIC2 radio button Black IDC_BLACK Red IDC_RED Blue IDC_BLUE Text Box (Edit Box) ) IDC_Text Setting Font (check button) Bold IDC_BOLD Body IDC_ITALIC Underline IDC_UNDERLINE button confirmation IDOK Cancel Idcancel Using class wizard CTABDLG, Property Page dialog CTEXTPAGE, Properties Page dialog CTEXTPAGE and CStyLEPAGE, respectively, add the following data members: Identifier Type Data Member IDC_TABCTRL CTABCTRL M_TABCTRL IDC_DIST INT M_NDIST IDC_BLACK INT M_ncolor IDC_Text CString M_CText IDC_Bold Bool M_BBold IDC_ITALIC Bool M_BITALIC IDC_UNDERLINE BOOL M_BUNDERLINE The above data members can also use manual methods in tabdlg.h, stylepage.h and textpage.h. 4. Add data exchanges to be displayed to the view class, and to perform data exchange between the dialogs, and initialize them in the initialization function. (1) Add the following code in tabview.h: #include "tabdlg.h" #include "textpage.h" #include "stylepage.h" Class CTabView: PUBLIC CVIEW {public: int ndist; // Numerical Int Ncolor // Color CString Ctext; // Chinese string Bool BBold, Bitalic, Bunderline; // Font Properties} (2) Perform the following initialization in TabView.cpp.

CTabView :: CTabView () {ndist = 20; ncolor = 1; ctext = CSTRING ("Label Control Demo Instance"); bbold = BITALIC = BunderLine = false;} (3) Add label to control in tabdlg.cpp, To implement background settings. BOOL CTabDlg :: OnInitDialog () {CDialog :: OnInitDialog (); TC_ITEM tcItem; // add tags tcItem.mask = TCIF_TEXT; tcItem.pszText = "character spacing"; m_tabCtrl.InsertItem (0, & tcItem); tcItem.pszText = "Color Settings"; m_tabctrl.insertitem (1, & tcitem); m_tabctrl.setcursel (1); Return True;} When the label switch is switched, the tag control will automatically send a TCN_SELCHANGE notification message to the dialog window, and it needs to be selected according to the selected The label index number is switched and hidden on the display and hide of the property page. It should be perfected with an onselchangetabctrl () function: void ctabdlg :: OnsetAbctrl (nmHDR * PNMHDR, LRESULT * PRESULT) {int ipage = m_tabctrl.getCurseel (); // selected label No. Switch (ipage) {case 0: // Word spacing getdlgitem (idc_static2) -> showwindow (sw_hide); // Hide Select button getDLGITEM (IDC_BLACK) -> showwindow (sw_hide); // Hide Select button getdlgitem (IDC_RED) - > ShowWindow (sw_hide); // Hide Select Button Getdlgitem (IDC_BLUE) -> ShowWindow (SW_HIDE); // Hide Select Button Getdlgitem (IDC_STATIC1) -> ShowWindow (SW_SHOW); // Display Input Item Getdlgitem (IDC_Dist) -> ShowWindow; // Displays the number of input items; Case 1: // Color Set getdlgitem (idc_static1) -> showwindow (sw_hide); // Hidden item Enter Getdlgitem (IDC_Dist) -> showwindow (sw_hide); // Hidden items Enter Getdlgitem (IDC_STATIC2) -> ShowWindow (sw_show); // Display Option Select getDlgitem (idc_black) -> showwindow (sw_show); // Display Options Select getDlgitem (IDC_red) -> showwindow (sw_show); // Display Options Select getDLGITEM (IDC_BLUE) -> showWindow; // Display Options Selection Break;} * pResult = 0;} (4) The improvement of the menu function.

When performing the corresponding menu function, the corresponding function function of the class wizard must be perfect, which is to handle the TabView.cpp file, the background setting function function is as follows: void ctabview :: onbkgrnd () {ctabdlg ctd; ctd.m_ndist = ndist; ctd.m_ncolor = ncolor; if (CTD.Domodal () == idcancel) return; ndist = ctd.m_ndist; ncolor = ctd.m_ncolor; invalidate (); // Re-draw window}, also to prospect Set function functions Perfect: void ctabview :: onfrgrnd () {CPROPERTYET CPS ("foreground setting"); // Create a property table object ctextPage Ctp; file: // Display text property page cStypage CSP; // Display Font Properties page CTP .m_ctext = ctext; csp.m_bbold = bbold; csp.m_bitalic = BITALIC; csp.m_bunderline = burnderLine; cps.addpage (& CTP); // Add Properties Page CPS.Addpage (& CSP); if (cps.domodal () = = IDCANCEL) RETURN; ctext = ctp.m_ctext; bbold = csp.m_bbold; bitalic = csp.m_bitalic; buridine = csp.m_bunderline; invalidate (); // Resend window} (5) In order to fully demonstrate the label control and each attribute The data exchange function between the pages should implement the label to control the window display function after the data exchange between each property page and the user. The function function implemented by the author displays the font and background grid function entered by the property page, TabVIEW. The corresponding function code in the CPP is as follows: Void CTabView :: Ondraw (CDC * PDC) {CTABDOC * PDOC = getDocument (); assert_valid (pdoc); // Todo: Add Draw Code for Native Data Hererect RC; GetClientRect (& RC); INT I, J, K; CPEN PEN, * POLDPEN; ColorRef Color; Switch (Ncolor) {Case 0: Color = RGB (0,0,0); File: // Set black Break; case 1: color = RGB (0xFF, 0, 0); // Set red break; case 2: color = RGB (0, 0, 0xff); // Set blue breaf; Pen.createpen (PS_SOLID, 1, Color); Poldpen = PDC-> SelectObject (& Pen); // Draw background grid J = rc.right / ndist 1; k = rc.bottom / ndist 1; for (i = 0; i MoveTo (i * ndist, 0); PDC-> LineTo (0, i * ndist); if (i Moveto (i * Ndist, 0); PDC-> Lineto (rc.right, (ji) * ndist);} else {PDC-> Moveto (0, (ij) * ndist); PDC-> Lineto (rc.right, i * ndist );}} PDC-> SelectObject (& PoldPen); cfont font, * PoldFont;

转载请注明原文地址:https://www.9cbs.com/read-22427.html

New Post(0)