|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
RememberEnglish/U.S. English is not my first language. I'm Italian. Explaining things to others is not my profession, I'm a cryptic programmer :-) ... I live in a dark dungeon all alone :-) I'm a little ironic, but then, I'm a mad programmer :-). IntroductionI love the Outlook-style controls... I love them very much... My problem is that it's very difficult to find an XP-themed one. So, one day (around a year ago) I decided to build one... I fought against the poor Themes documentation and, in the end, I won. This is the result of my victory... The BAD thingsIt doesn't support: small icons, ellipsis on the buttons, drag and drop, in-place-editing of items, sorting of items, moving items, a good and easily expandable event model, owner-draw items, non-pushable icons (now the pushed icon remembers it was pushed and is drawn in a different style... normally this is an extended style of an OutBar, not the default style), disabling the themed part (the OutBar will work on W95/W98/NT etc.). I'm not even sure it will draw correctly with non-default themes (I've tried it with all the default XP themes, but I don't have StarDock or similar programs). The GOOD thingsIt's quick to redraw (it uses double buffering techniques), it has a dual interface: message based ( The SO 'N' SO thingsIt's licensed under the MIT license (a simplified BSD license), it uses many Windows controls (one for itself, one for each folder, and one for the icons). The last item is in the SO 'N' SO category because I consider a good thing that each part of the OutBar can be controlled separately (and the program can How can I use it?Remember: this code is tested with VC++ 8.0/WTL 7.5!! I don't want to write three pages to tell you things that you can discover yourself simply by opening the wtlOutBarDemo project (hint: all the "important" lines are marked with What are all the classes?
Is there something strange, something magical in your OutBar?Mmm... Yes... The class supports two styles (they are "basic" styles, not-extended).
There are three notifications that the class will throw:
Hey, but I want some documentationYou are lucky, you are very lucky. I decided to learn how to use Doxygen, so I commented all the "user" part of the source (you know, the not-internal part). You can read it in HTML format or in CHM format (the Windows HTML Help format)... and you can read it when you look at the source (because the comments are in the source, the doxygen simply extracts them and creates an easy-to-read file)... So, before leaving you a little baffled, I'll teach you a single thing (a thing I discovered after writing the OutBar). m_wtlOutbar.GetHWNDHandle(-1).ModifyStyleEx(0, WS_EX_STATICEDGE); where Hey, but I'm a little lazy and I really want some examplesOK… I'll explain the wtlOutBarDemo example… Create a Dialog based WTL project. Copy wtloutbar.h and stringcex.h in the folder of the project and add them to the project. Add some icons to the project, and give them IDs like #define _WIN32_WINNT 0x0501
It's required for the Theme support. After the #include <atlcoll.h> #include <atltheme.h> #include <tmschema.h> #include "wtloutbar.h" The first (atlcoll.h) is because I use ATL collections. The second (atltheme.h) is for the themes. The third (tmschema.h) is because Microsoft decided that it was a good thing to split the base header for the themes and the header that contains all the "codes" necessary to write theme based apps. The fourth (wtloutbar.h) is the OutBar library (it will auto-include stringcex.h). Now, you should go to the properties of your project, and in the Linker->Input page, add delayimp.lib to Additional Dependencies and uxtheme.dll to Delay Loaded DLLs. In this way, your program will be compatible with pre-XP systems that don't have the ComCtl32.dll v6 library (the library used for the Themes... Yes... I know, it isn't exactly correct what I've written... it's an oversimplification... so shoot me :-)). Now, go to the mainfrm.h file, and after the #define IDC_OUTBAR 10000 This will be the ID of the control (yes, 10000 is a random number; it shouldn't be used by anyone and then, IDs are local, so it won't be a problem, but if you don't like it, change it!). And under the CWtlOutBarImpl m_wtlOutbar; This is the control. Very simple. Now, go in the CImageList il; il.Create(32, 32, ILC_COLOR8|ILC_MASK, 6, 1); CIconHandle ico; ATLVERIFY(ico.LoadIcon(IDI_ICON1)); ATLVERIFY(il.AddIcon(ico) != -1); ATLVERIFY(ico.Detach()); ATLVERIFY(ico.LoadIcon(IDI_ICON2)); ATLVERIFY(il.AddIcon(ico) != -1); ATLVERIFY(ico.Detach()); This will create an ImageList with a base space for six icons (you can use different values) and that will grow one icon at a time. Then, it'll begin to load the icons and add them to the ImageList. We are loading the icons from the .exe file, so you don't have to truly "free" them after adding them to the ImageList (so the use of the RECT rect;
GetClientRect(&rect);
rect.right /= 3;
This will calculate the area of the client Rect (one third of the width of the window). ATLVERIFY(m_wtlOutbar.Create(m_hWnd, &rect, NULL,
WS_CHILD|WS_VISIBLE|OBS_FORCESELECT, 0, IDC_OUTBAR));
This will create the OutBar. We are using the m_wtlOutbar.SetImageList(il, OBSIL_NORMAL); We set the ImageList of the OutBar. Note that ATLVERIFY(m_wtlOutbar.SetFolderCount(10));
We prepare the memory for 10 folders (we won't use them). ATLVERIFY(m_wtlOutbar.AddFolder(OBFF_TEXT|OBFF_PARAM, _T("[2]"), 3) != -1); ATLVERIFY(m_wtlOutbar.InsertFolder(0, OBFF_TEXT|OBFF_PARAM, _T("[1]"), 5) != -1); We add two folders (technically, we add a folder, and then we insert another folder before the just added folder). We set the caption and the m_wtlOutbar.AddItem(0, OBIF_TEXT|OBIF_IMAGE|OBIF_PARAM, _T("[1-1]"), 1, 10); m_wtlOutbar.AddItem(1, OBIF_TEXT|OBIF_IMAGE|OBIF_PARAM, _T("[2-2]"), 2, 20); m_wtlOutbar.InsertItem(0, 1, OBIF_TEXT|OBIF_IMAGE|OBIF_PARAM, _T("[1-2]"), 3, 30); m_wtlOutbar.InsertItem(0, 2, OBIF_TEXT|OBIF_IMAGE|OBIF_PARAM, _T("[1-3]"), 4, 40); We add two items (one for each folder) and then we insert another two (technically, we use the Insert as an Add (technically, the Add is just a shortcut to the Insert)). We set the text, the image (the 1, 2, 3, and 4 are the icon numbers, zero based), and the Finished!! Now, you have created the OutBar... You can try to compile, then open the dictionary and look for some new bad words (because surely, some small errors creep in the program), correct everything and retry :-) In the example, I even used this in an m_wtlOutbar.SetWindowPos(NULL, 0, 0, LOWORD(lParam) / 3, HIWORD(lParam), SWP_NOMOVE|SWP_NOZORDER); (where NOTIFY_HANDLER(IDC_OUTBAR, OBN_FOLDEROPEN, OnFolderOpen) NOTIFY_HANDLER(IDC_OUTBAR, OBN_ITEMSELECT, OnItemSelect) NOTIFY_HANDLER(IDC_OUTBAR, OBN_ITEMSELECTAUTO, OnItemSelectAuto) Then, create three Notify handlers. To find out what is the new Folder Open, use: int iFolder = m_wtlOutbar.GetOpenFolder();
To find out which item is selected, use: int iFolder = m_wtlOutbar.GetSelectedFolder() int iItem = m_wtlOutbar.GetSelectedItem() Truly finished!! :-) History
LicenseI'm a BSD guy, so I'll license this library under the MIT license (a simplified BSD license). Copyright (c) 2005, 2006 Massimiliano Alberti xanatos(at)geocities.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||