|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library. Contents
IntroductionThe Graphical User Interface classes have been among the most popular MFC extensions available in the Ultimate Toolbox library. Background Painter
The int CBackgroundPainterView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
((CMainFrame*)AfxGetMainWnd())->GetPainter()->Attach(
this,IDB_WALLPAPER); // IDB_WALLPAPER specifies the bitmap
// resource to use
return 0;
}
Bitmap Enhanced Controls
m_btnRound.SetAmbientCoef(m_fAmbient/10,FALSE);
m_btnRound.SetDiffuseCoef(m_fDiffuse/10,FALSE);
m_btnRound.SetLightIntensityCoef(m_fLightIntensityCoef/10,FALSE);
m_btnRound.SetMirrorCoef(m_fMirror/10,FALSE);
m_btnRound.SetPhi(m_fPhi,FALSE);
m_btnRound.SetPhong(m_nPhong,FALSE);
m_btnRound.SetSphereExternalRadius(m_nSphereExtRadius,FALSE);
m_btnRound.SetSphereInternalRadius(m_nSphereIntRadius,FALSE);
m_btnRound.SetThetta(m_fThetta,FALSE);
m_btnRound.SetButtonColor(m_clrButton,FALSE);
m_btnRound.SetLightColor(m_clrLight,FALSE);
m_btnRound.RedrawWindow();
The Font Pickers article shows the use of a bitmap button in in the Calculator
void CCalculatorCtrlDlg::OnBnClickedCalculator()
{
UpdateData();
CRect rc;
GetDlgItem(IDC_BUTTON_CALCULATOR)->GetWindowRect(&rc);
if (m_calc.Pick(m_fValue, ID_OXCALCULATOR_ALIGNBOTTOM, rc))
{
// OK was pressed
m_fValue = m_calc.GetCalculatorCtrl()->GetResult();
UpdateData(FALSE);
}
}
Caption (Title Bar) Customization
// Install caption painter
m_Caption.Attach(this);
COXCaptionInfo* pCI=m_Caption.GetCaptionInfo(TRUE);
pCI->SetBackgroundColor(RGB(128,255,255));
pCI=m_Caption.GetCaptionInfo(FALSE);
pCI->SetBackgroundColor(RGB(255,255,128));
SendMessage(WM_NCPAINT);
Color PickerA customized color picker control. See the Color Picker article for more information on Combo BoxesCComboBox based controls
The samples\gui\HistCombo sample in action. The Templated Combo Box ControlsThe Ultimate Toolbox also provides for the creation of customized combo boxes through the use of
template<class PARENTCOMBOBOX, class PARENTLISTBOX, class PARENTEDIT>
class OX_CLASS_DECL COXBaseSubclassedComboBox : public PARENTCOMBOBOX { ... }
So, for example, you could create a class CHistoryMaskedComboBox :
public COXBaseSubclassedComboBox<COXHistoryCombo, CListBox,
COXMaskedEdit> { ... }
The Context Sensitive HelpThe The To enable context-sensitive help in your application's dialogs, property pages and property sheets, you must derive your classes from static const DWORD m_nHelpIDs[];
virtual const DWORD* GetHelpIDs() {return m_nHelpIDs;}
const DWORD CTest2Page::m_nHelpIDs[] =
{
IDC_TESTCHECK1, IDH_TESTCHECK1,
IDC_TESTCOMBO1, IDH_TESTCOMBO1,
IDC_TESTBUTTON2, IDH_TESTBUTTON2,
IDC_LIST1, IDH_LIST1,
IDC_SCROLLBAR1, IDH_SCROLLBAR1,
IDD_COLOR, IDH_COLOR,
0, 0
};
/////////////////////////////////////////////////////////////////////////////
// CTest2Page message handlers
BOOL CTest2Page::AdjustToolTips()
{
//Set up the Tooltip
BOOL rt = m_Tooltip.AddTool(&m_scroll1, _T("A Scroll Bar"));
ASSERT(rt != 0) ;
rt = m_Tooltip.AddTool(&m_combo1, _T("A Combo Box"));
ASSERT(rt != 0) ;
rt = m_Tooltip.AddTool(&m_check1, _T("A Check Box"));
ASSERT(rt != 0) ;
rt = m_Tooltip.AddTool(&m_button2, _T("A Button"));
ASSERT(rt != 0) ;
rt = m_Tooltip.AddTool(&m_list, _T("A List Box"));
ASSERT(rt != 0) ;
return rt;
}
Cool ControlsVarious controls can be given the 'cool' look with the
Implementing cool controls in your application is as easy as subclassing MFC member variables, and you can elect to apply the template to existing controls or use some of the Ultimate Toolbox's built in implementations: // Dialog Data
//{{AFX_DATA(CPropertyPageListTree)
enum { IDD = IDD_DIALOG_LISTTREE };
COXCoolCtrl<CTreeCtrl> m_tree;
COXCoolCtrl<CListCtrl> m_list;
COXCoolCtrl<CListBox> m_listbox;
COXCoolButton m_btnDisable;
COXCoolCtrl<CHotKeyCtrl> m_hotKey;
COXCoolSpinButtonCtrl m_spinUnattached;
COXCoolSpinButtonCtrl m_spinRight;
COXCoolSpinButtonCtrl m_spinLeft;
COXCoolCtrl<CRichEditCtrl> m_richeditMultiline;
COXCoolCtrl<CEdit> m_editSpinUnattached;
COXCoolCtrl<CEdit> m_editSpinRight;
COXCoolCtrl<CEdit> m_editSpinLeft;
COXCoolCtrl<CEdit> m_editPlain;
COXCoolCtrl<COXEdit> m_editExtended;
COXCoolCtrl<COXNumericEdit> m_editNumeric;
COXCoolCtrl<CEdit> m_editMultiline;
COXCoolCtrl<COXMaskedEdit> m_editMasked;
COXCoolCtrl<COXCurrencyEdit> m_editCurrency;
COXCoolButton m_btnDisable;
DateTime Controls
See the Date Time Picker article for more on these classes and their usage. Directory Picker
Drag and Drop
The 'SHB' in the name of these classes stems from the fact that it was originally intended to be used with a short cut bar, specifically the For more on these classes, please see the overviews in the Graphical User Interface | Drag and Drop section of the compiled HTML help documentation. Edit ControlsDropdown and various specific masked edit classes. ![]() Extended edit controls... More information can be found in the Edit Extensions, Physical Unit Edit Classes, and Masked Edit articles. File Picker
File Preview DialogThe
/////////////////////////////////////////////////////////////////////////////
// CDIBManagerApp commands
CFileDialog* CDIBManagerApp::NewFileDialog(BOOL bOpenFileDialog, DWORD lFlags)
{
// we provide functionality to open more than one file simultenuosly
lFlags|=OFN_ALLOWMULTISELECT;
// create the dialog with Preview capability
return new COXPreviewDialog(bOpenFileDialog,NULL,NULL,
OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT);
}
History/Output LogThe
protected:
COXTabViewPage<coxhistoryctrl /> m_build;
COXTabViewPage<coxhistoryctrl /> m_debug;
COXTabViewPage<coxhistoryctrl /> m_find1;
COXTabViewPage<coxhistoryctrl /> m_find2;
COXTabViewPage<coxhistoryctrl /> m_results;
COXTabViewPage<coxhistoryctrl /> m_SQLdebug;
// build page
if(!m_build.Create(NULL,NULL,WS_CHILD,CRect(0,0,0,0),
&m_TabViewContainer,1))
return -1;
m_TabViewContainer.AddPage(&m_build,_T("Build"));
m_build.AddLine(_T("Generating Code..."));
m_build.AddLine(_T("Linking..."));
m_build.AddLine(_T(""));
m_build.SetTextColor(RGB(255,0,0));
m_build.AddLine(_T("VisualStudioLikeDemo.exe - 0 error(s),
0 warning(s)"));
HyperBarNew in version 9.3, the hyperbar control is an MFC control, derived principally from See the HyperBar article for more on using this class in your application. List Controls
See the Extended List Box article for more on these classes. Layout Manager
m_LayoutManager.TieChild(IDC_OX_GROUP_PAINT_TYPE,
OX_LMS_LEFT|OX_LMS_RIGHT,OX_LMT_SAME);
m_LayoutManager.TieChild(IDC_OX_ALIGN_STRETCH,OX_LMS_RIGHT,OX_LMT_SAME);
m_LayoutManager.TieChild(IDC_OX_ALIGN_TOPRIGHT,OX_LMS_RIGHT,OX_LMT_SAME);
m_LayoutManager.TieChild(IDC_OX_ALIGN_CENTERRIGHT,OX_LMS_RIGHT,
OX_LMT_SAME);
m_LayoutManager.TieChild(IDC_OX_ALIGN_BOTTOMRIGHT,OX_LMS_RIGHT,
OX_LMT_SAME);
See the Layout Manager article for more on structure and usage of this class. Menu
// Let the menu organizer fix our menus
Organizer.AttachFrameWnd(this);
// Set images from toolbar to use with corresponding menu items
Organizer.AutoSetMenuImage();
// explicitly designate images to use with menu items
Organizer.SetMenuBitmap(ID_TEST_PAGE, MAKEINTRESOURCE(IDB_PAGE));
Organizer.SetMenuBitmap(ID_TEST_HELLO, MAKEINTRESOURCE(IDB_HELLO));
Organizer.SetMenuBitmap(ID_TEST_MARKEDPAGE, MAKEINTRESOURCE(
IDB_MARKEDPAGE));
Organizer.SetMenuBitmap(ID_TEST_DISABLED, MAKEINTRESOURCE(IDB_EXPLORE));
Organizer.SetMenuBitmap(ID_TEST_ENABLED, MAKEINTRESOURCE(IDB_EXPLORE));
Menu Bar
![]() Dockable menu bars in action in the samples\advanced\VisualStudioLikeDemo project. To automagically enable these menu bars in your application, simply derive your main frame window from class CMainFrame : public COXMenuBarFrame<CFrameWnd,CDockBar>
or class CMainFrame : public COXMenuBarFrame<CMDIFrameWnd,CDockBar>
Popup Bar
![]() The samples\gui\popupbar sample in action. The Popup Bar control is a top most popup window with items on it that can be chosen using the mouse or keyboard. For example, standard Popup Menu Bar or Color Picker from Word 97 are Popup Bar controls. Below is one example of how our Popup Bar can be graphically represented:
On display, the Popup Bar control captures all mouse messages and hides itself if any mouse button is clicked or the user presses ESC, ENTER or SPACE buttons. If, when clicked the mouse wasn't over any button within the Popup Bar, or the user pressed ESC, then nothing is chosen and the In this handler for the toolbar's void CMainFrame::OnDropDownCustomizeToolbar(NMHDR* pNotifyStruct,
LRESULT* pResult)
{
CFrameWnd* pFrame=GetActiveFrame();
ASSERT(pFrame);
CPopupBarDoc* pDoc = (CPopupBarDoc*)pFrame->GetActiveDocument();
ASSERT(pDoc);
ASSERT_VALID(pDoc);
// this function handles the dropdown menus from the toolbar
NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct;
CRect rect;
COXCoolToolBar* pToolBar=GetCustomizeToolBar();
// translate the current toolbar item rectangle into screen coordinates
// so that we'll know where to pop up the menu
pToolBar->GetItemRect(pToolBar->CommandToIndex(
pNMToolBar->iItem), &rect);
::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft());
::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.BottomRight());
COLORREF clr;
COXColorPickerCtrl colorPicker;
switch(pNMToolBar->iItem)
{
case ID_CUSTOMIZE_TEXT_COLOR:
{
if(::IsWindow(colorPicker.m_hWnd) || colorPicker.Create(pToolBar))
{
clr=pDoc->GetTextColor();
colorPicker.SetSelectedColor(clr);
colorPicker.SetDefaultColor(pDoc->GetDefaultTextColor());
if(colorPicker.Pick(ID_POPUPBAR_ALIGNBOTTOM,&rect))
{
clr=colorPicker.GetSelectedColor();
pDoc->SetTextColor(clr);
}
}
break;
}
case ID_CUSTOMIZE_FILL_COLOR:
...
case ID_CUSTOMIZE_BORDER_COLOR:
...
case ID_CUSTOMIZE_BORDER_STYLE:
...
case ID_CUSTOMIZE_LINE_STYLE:
...
case ID_CUSTOMIZE_DASH_STYLE:
}
pToolBar->InvalidateRect(rect);
pDoc->UpdateAllViews(NULL);
*pResult = TBDDRET_DEFAULT;
}
See the Rollup WindowsThe The samples\gui\rollup sample derives void CRoll32View::OnLButtonDblClk(UINT nFlags, CPoint point)
{
UNREFERENCED_PARAMETER(nFlags);
CMaxVirtDialog *pMaxVirt = new CMaxVirtDialog(this);
TCHAR achBuffer[64];
UTBStr::stprintf(achBuffer, 64,_T("MVT: %ld"),::GetTickCount());
pMaxVirt->CreateRollUp(this,15,achBuffer);
ClientToScreen(&point);
pMaxVirt->SetWindowPos(
NULL,point.x,point.y,0,0,SWP_NOZORDER|SWP_NOSIZE);
pMaxVirt->ShowWindow(SW_SHOWNORMAL);
// if you´re searching for the delete, see maxvirtd.cpp PostNcDestroy
// and OnCloseRollup
}
Ruler Bar
The samples\graphics\ImageViewer sample shows the ruler bar classes in action, through the #ifdef OXSCRLWND_USE_RULER
// --- In : bHorzRuler - horizontal ruler band will be displayed
// bVertRuler - vertical ruler band will be displayed
// --- Out :
// --- Returns: TRUE if COXRulerOrganizer object was successfully
// attached
// --- Effect: attaches to COXRulerOrganizer object which is
// responsible for displaying ruler bars
inline BOOL AttachRuler(BOOL bHorzRuler=TRUE, BOOL bVertRuler=TRUE) {
if(m_ruler.IsAttached())
{
SetShowHorzRulerBar(bHorzRuler);
SetShowVertRulerBar(bVertRuler);
return TRUE;
}
return m_ruler.Attach(this,bHorzRuler,bVertRuler);
}
Scrolling and Scaling Windows
The DIBManager sample implements a COXZoomView derived CDIBManagerView view.
void CDIBManagerView::OnViewZoomIn()
{
// TODO: Add your command handler code here
// up current zoom level on 100% if it is more than 100% already
// or on 10% otherwise
int nZoomLevel=GetZoomLevel();
if(nZoomLevel
The COXImageViewer class is derived from COXScrollWnd, shown here in action in the samples\graphics\imageviewer example.
See the compiled HTML help documentation for complete class references for Separator
// setup vertically oriented separators
static CFont fontVertEnabled;
VERIFY(fontVertEnabled.CreatePointFont(120,_T("Times New Roman")));
m_ctlSepVertRight.SetVertOriented();
m_ctlSepVertRight.SetFont(&fontVertEnabled);
m_ctlSepVertPlain.SetVertOriented();
m_ctlSepVertLeft.SetVertOriented();
m_ctlSepVertLeft.SetFont(&fontVertEnabled);
m_ctlSepVertCenter.SetVertOriented();
m_ctlSepVertCenter.SetFont(&fontVertEnabled);
Spin Control
Static Controls
See the Static Hyperlink and Static Text articles for more on these classes. Status BarAn enhanced wsprintf(buffer, _T("%02.2d:%02.2d:%02.2d"),
datetime.tm_hour, datetime.tm_min, datetime.tm_sec);
if (datetime.tm_sec == 0 || datetime.tm_sec == 30)
{
m_wndStatusBar.ResetBar(1);
m_wndStatusBar.SetBarProgress(1, TRUE, 30, 0);
}
else
{
m_wndStatusBar.SetBarProgress(1, TRUE, 31, datetime.tm_sec % 30);
}
if((datetime.tm_sec % 2) == 0)
m_wndStatusBar.SetPaneText( 5, (LPCTSTR)buffer, RGB(255,0,0),
TRUE);
else
m_wndStatusBar.SetPaneText( 5, (LPCTSTR)buffer);
}
Shortcut Bar (Outlook Style)A popular Outlook style shortcut bar.
// outlook group
sText=_T("Outlook");
shbGroup.nMask=SHBIF_TEXT;
shbGroup.nTextMax=sText.GetLength();
shbGroup.pszText=sText.GetBuffer(shbGroup.nTextMax);
sText.ReleaseBuffer();
m_ctlShortcutBar.InsertGroup(&shbGroup);
// mail group
sText=_T("Mail");
shbGroup.nMask=SHBIF_TEXT;
shbGroup.nTextMax=sText.GetLength();
shbGroup.pszText=sText.GetBuffer(shbGroup.nTextMax);
sText.ReleaseBuffer();
m_ctlShortcutBar.InsertGroup(&shbGroup);
Specially Shaped WindowThe for(nID = IDC_0; nID <= IDC_9; nID++)
{
pKey = (CCalcKey*) GetDlgItem(nID);
ASSERT(pKey != NULL);
// Make them star shaped
pKey->SetStarShape();
// Set color to yellow when not pressed, red when pressed
pKey->SetColors(RGB(0,0,0),RGB(255,255,0),RGB(0,0,0),RGB(255,0,0));
}
Tabbed Views
See the 3D Tab Views article for more on these classes. Tabbed MDI
Implementing a tabbed MDI application is quite simple:
// MTI client window
COXTabClientWnd m_MTIClientWnd;
m_MTIClientWnd.Attach(this);
That's it! You can learn more about the classes in the compiled HTML help documentation. Tree Controls
See the articles on the Network Browser and Option Tree controls for more information on these extensions. Tooltips
Please see the COXToolTipCtrl article for more information. User Customizable Menu
This class provides a way of implementing a special menu in your application where users can insert their own tools. These tools can then be executed from within your application. (Similar to the Tools menu in the Developer Studio IDE). This class features:
To use the const UINT ID_TOOLS_USER_1 = 32771;
const UINT MAX_TOOLS_USER = 10;
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_COMMAND(ID_TOOLS_CUSTOMIZE, OnToolsCustomize)
ON_COMMAND_RANGE(ID_TOOLS_USER_1, ID_TOOLS_USER_1 + MAX_TOOLS_USER,
OnToolsExecute)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
The void CMainFrame::OnToolsExecute(UINT nID)
{
int iIndex = (int)( nID - ID_TOOLS_USER_1 );
if ( -1 < iIndex && iIndex < m_ToolArray.GetSize() )
{
COXUserTool* pTool = (COXUserTool*)m_ToolArray.GetAt( iIndex );
ASSERT( pTool != NULL );
CStringList Replacements;
// ....(fill up a Replacements list)
BOOL bOk = pTool->Execute( &Replacements );
ASSERT(bOk);
if (!bOk)
AfxMessageBox(
"Could not execute Tool", MB_OK | MB_ICONEXCLAMATION);
}
Usertools are created and initialized by newly selecting and assigning the 4 member variables. Note that to keep track of the tools created, a // add some user tools to the UserToolArray
COXUserTool* pNewTool = new COXUserTool();
pNewTool->SetMenuText("NotePad");
pNewTool->SetCommand("c:\\winnt35\\NotePad.exe");
pNewTool->SetArgs("README.TXT");
pNewTool->SetDirectory("c:\\decoder");
m_ToolArray.Add(pNewTool);
The 4 helper functions are :
CMenu* pMenu = NULL; pMenu = GetMenu(); // get a pointer to the main menu if (pMenu != NULL) { // The tools menu is the fourth menu in the main menu // after File, Edit an View (see resource editor) CMenu* pSubMenu = pMenu->GetSubMenu(3); if (pSubMenu != NULL) AppendUserTools(pSubMenu ,ID_TOOLS_USER_1, m_ToolArray); }
See the compiled HTML help documentation for a complete Window Hook
The message hook map (class The purpose of these classes is to create an effective object oriented solution to the "inheritance message handling problem". Let's assume we have an application with many CView derived objects, such as To provide this custom handling across all windows, derive a class from The HistoryInitial CodeProject release August 2007.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||