Create a right list box in the status bar

zhaozj2021-02-16  44

Create a right list box in the status bar

This code can create a list box in any place in the status line.

1. Select Resource Symbols from the View menu, add a new id (assuming to IDC_LIST in this case), allowing the computer to assign a value for the ID.

2. Look for an Indicators array in Mainfrm.cpp, then add the added ID above this array, put it behind other IDs, which will make the future list box appear on the rightmost right side, if you Do not want the list box to appear on the right, you can also place the ID in other places you want to appear. In this example: static uint indeicators [] = {id_separator, // status line indeficator IDC_List file: // The area of ​​this paragraph, this example is used to store listCtrl controls};

3. Open the string table in the resource file and insert a new string. You can join a new character table through the INSERT menu, or click the right button on the string table. This example is empty. character.

4. The character of the string is a new id, then add the appropriate space. (Added spaces to be larger than the established list box)

Now we have established an empty rectangle, then we have to put it in a list box here.

1. Declare a public variable clistctrl m_list in mainfrm.h;

2. Declare a protective variable BOOL M_BLISTCREATE in Mainfrm.h;

3. CMAINFRAME :: CMAINFRAME () {m_blistcreate = false;}

4. Declare the Void SetList (Void); function, the function is used to initialize the list box to implement the setList () function in the mainfrm.cpp, the specific: Void CMAINFRAME :: setList (void) {file: // crete THE LISTVIEW Rect MyRect; // Substitution 4 with the Zero-based Index of Your Status Bar Pane. // for Example, IF You Put Your Pane First in The Indicators Array, // You 抎 Put 0, SECOND You 抎 Put 1, Etc. m_wndstatusbar.getitemRect (1, & myRect);

if (m_bListCreate == FALSE) {LV_COLUMN lvc; lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT; lvc.fmt = LVCFMT_CENTER; AfxMessageBox ( "ok"); m_list.Create (WS_CHILD | WS_VISIBLE | LVS_ALIGNLEFT | LVS_REPORT | WS_BORDER, MYRECT, & M_WNDSTATUSBAR, 1); M_List.setBkcolor (: getSyscolor (color_infobk)); m_list.setTextBkcolor (: getSyscolor (color_3dface);

Lvc.isubitem = 0; lvc.psztext = _t ("AM point to"); lvc.cx = 60; if (m_list.insertcolumn (1, & lvc) == 0) AFXMessageBox ("false"); lvc.isubitem = 1; lvc.psztext = _t ("lunch"); lvc.cx = 60; m_list.insertcolumn (2, & lvc); file: // afxMessageBox ("ok"); m_blistcreate = true;} else afxMessageBox ("HAS BEEN Created! ");

} This function can be implemented according to your needs.

5. In this example, the list box is initialized while the program is initialized, so put the initial code of the list box in the onCreate () function initially generated by the primary frame. As follows: int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) {if (CFrameWnd :: OnCreate (lpCreateStruct) == -1) return -1; if (m_wndToolBar.CreateEx (this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER |! CBRS_ToolTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||! M_wndtoolbar.loadtoolbar (idR_mainframe)) {trace0 ("failed to create toolbar / n"); return -1; // fail to create}

IF (! m_wndstatusbar.createex (this, sbars_sizegrip) ||! m_wndstatusbar.setindicators (Indicators, Sizeof (Indicators) / SizeOf (TRACE0 ("Failed to Create Status Bar / N); RETURN-1; / / fail to create}

m_WndStatusBar.getStatusbarCtrl (). setminHeight (40); // This statement is used to set the height of the status bar. SetList (); // Used to initialize the list box, place the list box in the appropriate location of the status bar. // Todo: Delete these Three Lines if you don't want the toolbar to // be dockable m_wndtoolbar.enabledocking (CBRS_ALIGN_ANY); EnableDocking (CBRS_ALIGN_ANAY); DOCKCONTROLBAR (& M_WndToolbar);

Return 0;}

6. If the window changes the size after the window is created, the list box will not be re-adjusted, and we must add your own code in the WM_SIZE event to adjust the list box:

Void CMAINFRAME :: Onsize (uint ntype, int cx, int CY) {cframeWnd :: Onsize (NTYPE, CX, CY); if (m_blistcreate == true) {Rect Rc; M_WndstatusBar.GetItemRect (1, & RC);

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

New Post(0)