A good outlookbar control, cxtoutbarctrl

Source: Internet
Author: User

This control comes from Xtreme toolkit. I modified it so that it does not rely on the class library to exist independently. Because I did not use other XT classes, you may think it is not gorgeous in the class library, but it is very rare for its small physique.

The source file includes two header files: xtmemdc. H, xtmemdc. cpp, xtoutbarctrl. H,
Xtoutbarctrl. cpp.

Xtmemdc is a CDC inheritance class for auxiliary functions.

How to use this control:

1. Use mfc sdi Wizard to generate a sub-SDI program.

2. Add # include "xtoutbarctrl. H" to the mainfrm. h header"

3. Add a member variable in mainfrm. h.

Csplitterwnd m_wndsplitter;
Cxtoutbarctrl m_wndoutlookbar;
Cimagelist m_imagelarge;
Cimagelist m_imagesmall;
Bool m_bdestroy;
4. added the message ing function to cmainframe.
Bool cmainframe: oncreateclient (lpcreatestruct lpcs, ccreatecontext * pcontext)
{
// Create splitter window
If (! M_wndsplitter.createstatic (this, 1, 2 ))
Return false;

// Here we create the outbar control using the splitter as its parent
// And setting its ID to the first pane.
If (! M_wndoutlookbar.create (ws_child | ws_visible | ws_clipchildren, crect (0, 0, 0 ),
& M_wndsplitter, m_wndsplitter.idfromrowcol (0, 0), obs_xt_default ))
{
Trace0 ("failed to create outlook bar .");
Return false;
}

If (! M_wndsplitter.createview (0, 1, pcontext-> m_pnewviewclass,
Csize (100,100), pcontext ))
{
M_wndsplitter.destroywindow ();
Return false;
}

// Set the background and text color of the outlook bar.
M_wndoutlookbar.setbackcolor (RGB (0x3a, 0x6e, 0xa5 ));
M_wndoutlookbar.settextcolor (RGB (0xff, 0xff, 0xff ));

// Set the default sizes for the splitter panes.
Crect R;
Getclientrect (& R );
M_wndsplitter.setcolumninfo (0, R. Width ()/4, 0 );
M_wndsplitter.recalclayout ();

// Add items to the outlook bar.
Initializeoutlookbar ();
Return true;
}

5. added the member function void cmainframe: initializeoutlookbar () to the cmainframe ()
{
// Create the image lists used by the outlook bar.
M_imagesmall.create (16, 16, ilc_color16 | ilc_mask, 2, 1 );
M_imagelarge.create (32, 32, ilc_color16 | ilc_mask, 2, 1 );

// Initiailize the image lists.
For (INT I = 0; I <11; ++ I)
{
Hicon = afxgetapp ()-> loadicon (nicons [I]);
Assert (hicon );

M_imagesmall.add (hicon );
M_imagelarge.add (hicon );
}

Int ifolder; // index of the added folder
// Set the image lists for the outlook bar.
M_wndoutlookbar.setimagelist (& m_imagelarge, obs_xt_largeicon );
M_wndoutlookbar.setimagelist (& m_imagesmall, obs_xt_smallicon );

// Add the first folder to the outlook bar.
Ifolder = m_wndoutlookbar.addfolder (_ T ("Shortcuts 1"), 0 );

// Add items to the folder, syntax is folder, index, text, image, and item data.
M_wndoutlookbar.insertitem (ifolder, 1, _ T ("item 1"), 0, null );
M_wndoutlookbar.insertitem (ifolder, 2, _ T ("item 2"), 1, null );
M_wndoutlookbar.insertitem (ifolder, 3, _ T ("item 3"), 2, null );
M_wndoutlookbar.insertitem (ifolder, 4, _ T ("item 4"), 3, null );
M_wndoutlookbar.insertitem (ifolder, 5, _ T ("Item 5"), 4, null );
M_wndoutlookbar.insertitem (ifolder, 6, _ T ("item 6"), 5, null );

// Add the second folder to the outlook bar.
Ifolder = m_wndoutlookbar.addfolder (_ T ("Shortcuts 2"), 1 );

 

// Add items to the folder, syntax is folder, index, text, image, and item data.
M_wndoutlookbar.insertitem (ifolder, 1, _ T ("item 1"), 0, null );
M_wndoutlookbar.insertitem (ifolder, 2, _ T ("item 2"), 1, null );

// Add the tree control to the outlook bar.
// Xu ifolder = m_wndoutlookbar.addfolderbar (_ T ("tree control"), & m_wndtreectrl );

// Set the default font used by the outlook bar.
// Xu m_wndoutlookbar.setfontx (& xtafxdata. font );

// We want to receive notification messages.
M_wndoutlookbar.setowner (this );

// Select the first folder in the bar.
M_wndoutlookbar.setselfolder (ifolder );

// Sizing for Splitter
Crect R;
Getclientrect (& R );
M_wndsplitter.setcolumninfo (0, R. Width ()/7, 0 );
M_wndsplitter.setcolumninfo (1, R. Width ()/5, 0 );
// M_wndsplitter1.setsplitterstyle (xt_split_nofulldrag );
}

6. added the message ing lresult cmainframe: onoutbarnotify (wparam, lparam) to the cmainframe)
{
Int nbaraction = (INT) wparam;

// Cast the lparam to a xt_outbar_info * struct pointer.
Xt_outbar_info * pobinfo = (xt_outbar_info *) lparam;
Assert (pobinfo );

Switch (nbaraction)
{
Case obn_xt_itemclick:
Trace2 ("item selected: % d, name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_folderchange:
Trace2 ("folder selected: % d, name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_onlabelendedit:
Trace2 ("item Edited: % d, new name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_ongroupendedit:
Trace2 ("folder Edited: % d, new name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_dragitem:
Trace3 ("dragging from: % d, to: % d, name: % S. \ n", pobinfo-> ndragfrom,
Pobinfo-> ndragto, pobinfo-> lpsztext );
Break;
Case obn_xt_itemhover:
Trace2 ("Hovering item: % d, name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_deleteitem:
If (! M_bdestroy & afxmessagebox (_ T ("are you sure you want to remove this folder shortcut? "),
Mb_iconwarning | mb_yesno) = IDNO)
{
// The user selected no, return false to abort the action.
Return false;
}
Trace2 ("item deleted: % d, name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
Case obn_xt_deletefolder:
If (! M_bdestroy & afxmessagebox (_ T ("are you sure you want to remove the specified folder? "),
Mb_iconwarning | mb_yesno) = IDNO)
{
// The user selected no, return false to abort the action.
Return false;
}
Trace2 ("folder deleted: % d, name: % S. \ n", pobinfo-> nindex, pobinfo-> lpsztext );
Break;
}

Return true;
}

For more information, see the source program. May this control be helpful for your programming? Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.