This is a brother's code: csplitterwnd to hide/display the column pan//////////////////////////////////////// /// // Splitex. h // (c) 1997, Oleg G. galkinclass csplitterwndex: Public csplitterwnd {protected: int m_nhidedcol; // hide column number,-1 if all columns // are shownpublic: csplitterwndex (); void showcolumn (); void hidecolumn (INT colhide); // classwizard generated virtual function overrides // {afx_virtual (csplitterwndex) //} afx_virt Ual // generated message map functionsprotected: // {afx_msg (csplitterwndex) // note-The classwizard will add and remove member // functions here. //} afx_msg declare_message_map ()}; //////////////////////////////////////// /// // splitex. CPP // (c) 1997, Oleg G. galkin # include "stdafx. H "# include" splitex. H "# ifdef _ debug # define new debug_new # UNDEF this_filestatic char this_fi Le [] = _ file __; # endif ////////////////////////////////////// /// // csplitterwndexcsplitterwndex:: csplitterwndex (): m_nhidedcol (-1) {} void csplitterwndex: showcolumn () {assert_valid (this); Assert (m_ncols <m_nmaxcols); Assert (ignore! =-1); int colnew = m_nhidedcol; m_nhidedcol =-1; int cxnew = m_pcolinfo [m_ncols]. ncursize; m_ncols ++; // Add a column assert (m_ncols = m_nmaxcols); // fill the Hidden Column int Col; For (int row = 0; row <m_nrows; row ++) {cwnd * ppaneshow = getdlgitem (afx_idw_pane_first + row * 16 + m_ncols); Assert (ppaneshow! = NULL); ppaneshow-> showwindow (sw_showna); For (COL = m_ncols-2; Col >=colnew; col --) {cwnd * ppane = getpane (row, col ); assert (ppane! = NULL); ppane-> setdlgctrlid (idfromrowcol (row, Col + 1);} ppaneshow-> setdlgctrlid (idfromrowcol (row, colnew ));} // new panes have been created -- recalculate layout for (COL = colnew + 1; Col <m_ncols; Col ++) m_pcolinfo [col]. nidealsize = m_pcolinfo [col-1]. ncursize; m_pcolinfo [colnew]. nidealsize = cxnew; recalclayout ();} void csplitterwndex: hidecolumn (INT colhide) {assert_valid (this); Assert (M _ Ncols> 1); Assert (colhide <m_ncols); Assert (m_nhidedcol =-1); m_nhidedcol = colhide; // If the column has an active window -- change it int rowactive, colactive; If (getactivepane (& rowactive, & colactive )! = NULL & colactive = colhide) {If (++ colactive> = m_ncols) colactive = 0; setactivepane (rowactive, colactive );} // hide all column panes for (int row = 0; row <m_nrows; row ++) {cwnd * ppanehide = getpane (row, colhide); Assert (ppanehide! = NULL); ppanehide-> showwindow (sw_hide); ppanehide-> setdlgctrlid (afx_idw_pane_first + row * 16 + m_ncols); For (INT Col = colhide + 1; Col <m_ncols; col ++) {cwnd * ppane = getpane (row, col); Assert (ppane! = NULL); ppane-> setdlgctrlid (idfromrowcol (row, col-1) ;}} m_ncols --; m_pcolinfo [m_ncols]. ncursize = m_pcolinfo [colhide]. ncursize; recalclayout ();} begin_message_map (csplitterwndex, csplitterwnd) // {afx_msg_map (csplitterwndex) // note-The classwizard will add and remove mapping macros here. //} afx_msg_mapend_message_map ()
View Splitting: The Code previously written is also used today. We have added some new things to share with you .. Split the view, hide the view, and so on. Whether the split is moved or not.
The following code is used:
Header file:
# Pragma once # include "afxext. H" # include "2darray. H" class csplitterwndex: Public csplitterwnd {public: csplitterwndex (void); Virtual ~ Csplitterwndex (); typedef STD: List <int> list_int; // template function // attributespublic: // operationspublic: voidshowcolumn (); // display the column view voidhidecolumn (INT colhide); // hide the column view boolcreatestatic (cwnd * pparentwnd, int nrows, int ncols, DWORD dwstyle = ws_child | ws_visible, uint nid = afx_idw_pane_first); voidinit (); // initialize boolcreateview (INT row, int Col, cruntimeclass * pviewclass, size sizeinit, ccreatecontext * pcontext); protected: publish (); voidremovecolinfo (INT place, int col); Forward (int I, Int J); intreltoabsposition (list_int & vis_list, list_int & hid_list, int cur_index); boolispanevisible (INT row, int col); // overrides // classwizard generated virtual function overrides // {afx_virtual (csplitterwndex) //} afx_virtual // implementationpublic: void oninverttracker (const crect & rect ); void ondrawsplitter (CDC * PDC, esplittype ntype, const crect & rectarg); // generated message map functionsprotected: // {afx_msg (csplitterwndex) declare_message_map () afx_msg void onlbuttondown (uint nflags, cpoint point); afx_msg void onmousemove (uint nflags, cpoint point); afx_msg bool onsetcursor (cwnd * pwnd, uint nhittest, uint message ); // note-The classwizard will add and remove member functions here. ///} response: list_int comment; // shown column listlist_int m_hid_cols; // Hidden Column listlist_int comment; // shown rows listlist_int m_hid_rows; // hidden rows listprotected: c2darray comment; // array of pointers to splitter panescrowcolinfo * m_psavedcolinfo; crowcolinfo * m_psavedrowinfo; protected: int m_nhidedcol; // hide column number,-1 if all columns };# Include "stdafx. H "# include" splitterwndex. H "csplitterwndex: csplitterwndex () {// modify the split bar and pane spacing m_cxsplitter = m_cysplitter = 1; m_cxsplittergap = m_cysplittergap = 1;} csplitterwndex ::~ Csplitterwndex () {If (m_psavedcolinfo! = NULL) {Delete [] m_psavedcolinfo; m_psavedcolinfo = NULL;} If (m_psavedrowinfo! = NULL) {Delete [] records; records = NULL ;}} begin_message_map (csplitterwndex, csplitterwnd) values () on_wm_mousemove () values () end_message_map () void csplitterwndex :: onlbuttondown (uint nflags, cpoint point) {// todo: add your message handler code here and/or call defaultcwnd: onlbuttondown (nflags, point);} void csplitterwndex :: onmousemove (uint nflags, cpoint point) {// Do: add your message handler code here and/or call defaultcwnd: onmousemove (nflags, point);} bool csplitterwndex: onsetcursor (cwnd * pwnd, uint nhittest, uint message) {// todo: add your message handler code here and/or call defaultreturn cwnd: onsetcursor (pwnd, nhittest, message);} // draw the split window feature void csplitterwndex :: ondrawsplitter (CDC * PDC, esplittype ntype, const crect & rectarg) {If (PDC = NULL) {redraw Window (rectarg, null, rdw_invalidate | rdw_nochildren); return;} assert_valid (PDC); // otherwise, actually drawcrect rc = rectarg; Switch (ntype) {Case splitborder: // re-draw the border of the split window to make it green PDC-> draw3drect (RC, RGB (0,200, 0), RGB (0,200, 0); RC. inflaterect (-1,-1); PDC-> draw3drect (RC, RGB (0,100, 0), RGB (0,100, 0); return; Case splitbox: PDC-> draw3drect (RC, RGB (0, 0), RGB (0, 0); RC. inflaterect (-1,-1); PDC-> draw3drect (RC, RGB (0, 0, 0), RGB (0, 0); RC. inflaterect (-1,-1); PDC-> fillsolidrect (RC, RGB (0, 0); PDC-> draw3drect (RC, RGB (0, 0, 0 ), RGB (, 0); return; Case splitbar: // redraw the split string to green PDC-> fillsolidrect (RC, RGB (, 0); RC. inflaterect (-1,-1); PDC-> draw3drect (RC, RGB (200, 200), RGB (,); return; default: assert (false);} // fill the middlepdc-> fillsolidrect (RC, RGB (0,200, 0);} // draw the split entry void csplitterwndex: oninverttracker (const re CT & rect) {assert_valid (this); Assert (! Rect. isrectempty (); Assert (getstyle () & ws_clipchildren) = 0); // pat-BLT without clip children oncdc * PDC = getdc (); // flip paint brush mode cbrush * pbrush = CDC: gethalftonebrush (); hbrush holdbrush = NULL; If (pbrush! = NULL) holdbrush = (hbrush) SelectObject (PDC-> m_hdc, pbrush-> m_hobject); // create the bit mode PDC-> patblt (rect. left, rect. top, rect. width (), rect. height (), patinvert); If (holdbrush! = NULL) SelectObject (PDC-> m_hdc, holdbrush); releasedc (PDC);} void csplitterwndex: showcolumn () {assert_valid (this); Assert (m_ncols <m_nmaxcols ); assert (m_nhidedcol! =-1); int colnew = m_nhidedcol; m_nhidedcol =-1; int cxnew = m_pcolinfo [m_ncols]. ncursize; m_ncols ++; // Add a columnassert (m_ncols = m_nmaxcols); // fill the hidden columnint Col; For (int row = 0; row <m_nrows; row ++) {cwnd * ppaneshow = getdlgitem (afx_idw_pane_first + row * 16 + m_ncols); Assert (ppaneshow! = NULL); ppaneshow-> showwindow (sw_showna); For (COL = m_ncols-2; Col >=colnew; col --) {cwnd * ppane = getpane (row, col ); assert (ppane! = NULL); ppane-> setdlgctrlid (idfromrowcol (row, Col + 1);} ppaneshow-> setdlgctrlid (idfromrowcol (row, colnew ));} // new panes have been created -- recalculate layoutfor (COL = colnew + 1; Col <m_ncols; Col ++) m_pcolinfo [col]. nidealsize = m_pcolinfo [col-1]. ncursize; m_pcolinfo [colnew]. nidealsize = cxnew; recalclayout () ;}// hide the view void csplitterwndex: hidecolumn (INT colhide) {assert_valid (this); Assert (m_ncols> 1); Assert (colhide <m_ncols); Assert (m_nhidedcol! =-1); m_nhidedcol = colhide; // If the column has an active window -- change itint rowactive, colactive; If (getactivepane (& rowactive, & colactive )! = NULL & colactive = colhide) {If (++ colactive> = m_ncols) colactive = 0; setactivepane (rowactive, colactive );} // hide all column panesfor (int row = 0; row <m_nrows; row ++) {cwnd * ppanehide = getpane (row, colhide); Assert (ppanehide! = NULL); ppanehide-> showwindow (sw_hide); ppanehide-> setdlgctrlid (afx_idw_pane_first + row * 16 + m_ncols); For (INT Col = colhide + 1; Col <m_ncols; col ++) {cwnd * ppane = getpane (row, col); Assert (ppane! = NULL); ppane-> setdlgctrlid (idfromrowcol (row, col-1) ;}} m_ncols --; m_pcolinfo [m_ncols]. ncursize = m_pcolinfo [colhide]. ncursize; recalclayout () ;}// create bool csplitterwndex: createstatic (cwnd * pparentwnd, int nrows, int ncols, DWORD dwstyle, uint NID) {bool ret; ret = csplitterwnd: createstatic (pparentwnd, nrows, ncols, dwstyle, NID); Init (); return ret;} void csplitterwndex: Init () // initialize {int I, j; m_pane_ptr_arra Y. init (m_nmaxrows, m_nmaxcols); for (I = 0; I <m_nmaxrows; I ++) {m_shown_rows.push_back (I);} For (j = 0; j <m_nmaxcols; j ++) {topology (j);} m_psavedcolinfo = new crowcolinfo [m_nmaxcols]; m_psavedrowinfo = new crowcolinfo [m_nmaxrows];} // create a bool csplitterwndex :: createview (INT row, int Col, cruntimeclass * pviewclass, size sizeinit, ccreatecontext * pcontext) {bool ret = csplitterwnd: createview (row, Col, Pviewclass, sizeinit, pcontext); cwnd * pwnd = getpane (row, col); Assert (pwnd); m_pane_ptr_array (row, col) = pwnd; return ret;} void csplitterwndex:: renumeratepanes () {int I, j, ID; for (I = 0; I <m_nmaxrows; I ++) {for (j = 0; j <m_nmaxcols; j ++) {cpoint Pos = reltoabsposition (I, j); cwnd * ppane = (cwnd *) m_pane_ptr_array (POS. x, POS. y); Assert (ppane! = NULL); Id = afx_idw_pane_first + I * 16 + J; int r = ppane-> setdlgctrlid (ID); Assert (r); If (ispanevisible (POS. x, POS. y) ppane-> showwindow (sw_show); elseppane-> showwindow (sw_hide) ;}} void csplitterwndex: removecolinfo (INT place, int col) {assert (m_ncols <= m_nmaxcols); m_psavedcolinfo [col] = m_pcolinfo [place]; for (INT I = place; I <m_ncols; I ++) {m_pcolinfo [I] = m_pcolinfo [I + 1] ;}} cpoint csplitterwndex: reltoabsposition (int Row, int col) {cpoint Pos; POS. X = reltoabsposition (m_shown_rows, m_hid_rows, row); POS. y = reltoabsposition (values, m_hid_cols, col); Return Pos;} values: reltoabsposition (list_int & vis_list, list_int & hid_list, int cur_index) {int org_index; int I; list_int:: iterator it; if (cur_index <(INT) vis_list.size () {It = vis_list.begin (); for (I = 0; I <cur_index; I ++) {It ++;} org_index = * it;} else {It = hid_l Ist. begin (); for (I = 0; I <cur_index-(INT) vis_list.size (); I ++) {It ++;} org_index = * it ;} return org_index;} bool csplitterwndex: ispanevisible (INT row, int col) {bool brow, bcol; Assert (m_nrows <= m_nmaxcols); If (m_shown_rows.end ()! = STD: Find (m_shown_rows.begin (), m_shown_rows.end (), row) {brow = true;} else {brow = false;} assert (m_ncols <= m_nmaxcols ); if (m_shown_cols.end ()! = STD: Find (m_shown_cols.begin (), m_shown_cols.end (), col) {bcol = true;} else {bcol = false;} return brow & bcol ;}