|
In Tools.cpp, comment the
extern "C" WINUSERAPI BOOL WINAPI TrackMouseEvent (LPTRACKMOUSEEVENT lpEventTrack);<br /> and change TrackMouseEvent with _TrackMouseEvent, in the following way:
<br />
bool CMouseMgr::OnMouseMove (HWND hTrack)<br />
{<br />
ASSERT(m_hWnd != NULL);<br />
if ( hTrack == NULL ) hTrack = m_hWnd;<br />
<br />
if ( !m_bOver )<br />
{<br />
m_bOver = true;<br />
<br />
if ( m_wFlags & MMS_PAINT )<br />
{<br />
::InvalidateRect (m_hWnd, NULL, false);<br />
}<br />
if ( m_wFlags & MMS_NCPAINT )<br />
{<br />
::SetWindowPos (m_hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);<br />
}<br />
TRACKMOUSEEVENT tme = { sizeof TRACKMOUSEEVENT, TME_LEAVE, m_hTrack = hTrack, 0 };<br />
::_TrackMouseEvent (&tme);<br />
<br />
return true;<br />
}<br />
if ( hTrack != m_hTrack )<br />
{<br />
TRACKMOUSEEVENT tme = { sizeof TRACKMOUSEEVENT, TME_CANCEL, m_hTrack, 0 };<br />
::_TrackMouseEvent (&tme);<br />
<br />
tme.dwFlags = TME_LEAVE;<br />
tme.hwndTrack = m_hTrack = hTrack;<br />
::_TrackMouseEvent (&tme);<br />
}<br />
return false;<br />
}<br />
I've tried with Win95 IE 5.5 and it does work.
A lot of greetings & kisses.
|
|
|
|
|
Hi Jean,
Thanks for a set of cool XP controls.
I've been trying to change the height of the combo without success.
How come I can only change the width through the create () function?
Please help!
Thanks in advance.
In programming you can do anything (by Paul DiLascia)
|
|
|
|
|
I have tested you example and I have compiled it on VC.NET and I have run it and it worked good. But just an adjust but I use XP standart blue theme, and the disabled button's image seems a little orange, it just a small difference from Word's buttons. I think if you adjust it the buttons will seem exacly like word's buttons!
|
|
|
|
|
as I am interested in using this cool XP-Menu effect, I just started with downloading and running the .exe sample provided.
The sample runs but NO XP style effect appears, just the regular 'old fashioned' windows menus.
For information, I'm using Windows XP and Office 2K. Do I need to install Office XP in order to have this sample run as shown on the previous screenshot ?
Please let me know.
|
|
|
|
|
Message written on 01/24/02:
"The demo is compiled with VC6/SP5 under NT4.
If you don't have the same compiler version, please use the source files."
To minimize the exe file size, I didn't link statically with MFC librairies. It seems to be the reason of your problem.
|
|
|
|
|
When I use CComboEditXP context menu,there is a big bug.
|
|
|
|
|
You can add the code below to avoid the crash.
in Tools.cpp
bool CMouseMgr::OnMouseOut (HWND hTrack)
{
// Temporary fix for the context menu crash
if (!m_bOver)
return false;
|
|
|
|
|
I have tested your code on Win2K SP2 machine. Everything seems OK but the toolbar is looking as it is simple, not as it is on the demopicture - with shadows, highlight, etc - just simple Windows toolbar. What is wrong?
|
|
|
|
|
my machine also win2k and the result is just like old plain CToolbar!!!
and i didnt managed to compile the source code using vc6.
|
|
|
|
|
i create a new MDi project and pull in the draws.cpp, tools.cpp, toolbarXp.cpp and now it works nicely.
thanks
|
|
|
|
|
Bonjour Jean-Michel. Je suis développeur d'un logiciel freeware de gestion de médiathèque et collections et je souhaiterais y incorporer le style XP.
Auriez-vous un exemple de code incluant l'ensemble des exemples présents sur ce site (menus + barres d'outils) et d'autres éventuels contrôles XP ? Je recherche un squelette d'application MFC Vc++ 6.x incluant ces fonctions.
Merci d'avance.
Stephane.
|
|
|
|
|
WTF??!
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Hey you're on an English spoking site, so you could translate or put the two languages. Otherwise, why posting here and not just dropping him an email?
tu pourrais traduire ca quand même. t'es sur un site anglais. et en plus il me semble que tu pourrais te démerder tout seul avec le code source de l'exemple.
bye.
|
|
|
|
|
I am writing all of my software using C and the windows API.
I am now trying to learn how to create my own window class for
a couple of specific things that I want to do. I am having
trouble finding information on how to do this without using
MFC. Does anyone know of any examples or locations where
I would be able to find the most information on this. Also
how do you integrate other classes into my software.
Thanks,
|
|
|
|
|
Maybe you should check the ATL, WTL sections.
|
|
|
|
|
I also wanted to display text on the toolbar buttons so I added the following code.
The text will be centered, however the image is always drawn in the upper left corner. This should only be a problem if you want large buttons with small images I guess it can look weird. But I just size the buttons so that the image appears centered.
You will need to set the text for each button using the SetButtonText function.
Then you will need to resize the buttons using the SetSizes function so that the button is large enough for the text to be displayed.
You will need to add the following changes to the the OnPaint message handler.
NOTE: If you want to use CToolBarXP as a base class you must provided a OnPaint handler for your new class and comment out the //CPaintDC dc(this); // device context for painting. And add a call to CToolBarXP::OnPaint();.
///////////////////////////////////////////////////////////////////////////////
// Paint the toolbar
void CToolBarXP::OnPaint ()
{
if ( m_bDelayedButtonLayout )
{
Layout();
}
CPaintDC cpDC (this);
CBufferDC cDC (cpDC);
CRect rcClip;
cDC.GetClipBox (rcClip);
cDC.SetBkMode (TRANSPARENT);
//Added by Jason Gurgel for drawing text on button
BOOL bList=(GetStyle() & TBSTYLE_LIST);
TEXTMETRIC tm;
//Select default GUI font
cDC.SelectObject (CFont::FromHandle ((HFONT)GetStockObject (DEFAULT_GUI_FONT)));
//Get the text metrics and height of the font
cDC.GetTextMetrics(&tm);
//Fill toolbar background color
cDC.FillSolidRect (rcClip, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0));
CPoint ptCursor;
::GetCursorPos (&ptCursor);
ScreenToClient (&ptCursor);
CClientRect rcClient (this);
HIMAGELIST m_hImageList = (HIMAGELIST)DefWindowProc (TB_GETIMAGELIST, 0, 0);
TBBUTTON tbbutton;
int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0);
int nHotItem = GetToolBarCtrl().GetHotItem();
for ( int i = 0; i < nCount; i++ )
{
VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton));
if ( !IS_VISIBLE(tbbutton) )
{
continue;
}
CRect rcButton;
VERIFY(DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcButton));
if ( !CRect().IntersectRect (rcClip, rcButton) )
{
continue;
}
bool bOver = nHotItem == i && IS_ENABLED(tbbutton);
bool bPressed = false;
if ( IS_INDETERMINATE(tbbutton) )
{
CPenDC pen (cDC, ::GetSysColor (COLOR_3DSHADOW));
cDC.MoveTo (rcButton.left, rcButton.bottom);
cDC.LineTo (rcButton.left, rcButton.top);
cDC.LineTo (rcButton.right-1, rcButton.top);
cDC.LineTo (rcButton.right-1, rcButton.bottom-1);
cDC.LineTo (rcButton.left, rcButton.bottom-1);
bOver = true;
}
//If mouse over or button is checked
else if ( bOver || IS_CHECKED(tbbutton) )
{
bPressed = KEYDOWN(VK_LBUTTON) && rcButton.PtInRect (ptCursor);
if ( IS_DROPDOWN(tbbutton) && bPressed )
{
bPressed = ptCursor.x < rcButton.right-13;
if ( bPressed )
{
rcButton.right -= 13;
}
}
COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT);
CPenDC pen (cDC, crHighLight);
CBrushDC brush (cDC, bPressed||(bOver&&IS_CHECKED(tbbutton)) ? HLS_TRANSFORM (crHighLight, +50, -50) : (bOver ? HLS_TRANSFORM (crHighLight, +70, -57) : HLS_TRANSFORM (crHighLight, +80, -66)));
//Draw mouse over rectangle & background
//Draws a rectangle using the current pen.
//The interior of the rectangle is filled using the current brush.
cDC.Rectangle (&rcButton);
if ( IS_DROPDOWN(tbbutton) )
{
if ( bPressed )
{
int nLeft = rcButton.left;
rcButton.left = rcButton.right-1;
rcButton.right += 13;
brush.Color (HLS_TRANSFORM (crHighLight, +70, -66));
cDC.Rectangle (&rcButton);
rcButton.left = nLeft;
}
else
{
cDC.MoveTo (rcButton.right-14, rcButton.top);
cDC.LineTo (rcButton.right-14, rcButton.bottom);
}
}
}
if ( IS_SEPARATOR(tbbutton) )
{
CPenDC pen (cDC, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -15, 0));
if ( IS_WRAP(tbbutton) )
{
cDC.MoveTo (rcClient.left+2, rcButton.bottom-4);
cDC.LineTo (rcClient.right-2, rcButton.bottom-4);
}
else
{
cDC.MoveTo ((rcButton.right+rcButton.left)/2-1, rcButton.top+2);
cDC.LineTo ((rcButton.right+rcButton.left)/2-1, rcButton.bottom-2);
}
}
else if ( !IS_CONTROL(tbbutton) )
{
if ( IS_DROPDOWN(tbbutton) )
{
CPenDC pen (cDC, ( bOver && !IS_INDETERMINATE(tbbutton) ) ? RGB(0,0,0) : ::GetSysColor (IS_ENABLED(tbbutton) ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
cDC.MoveTo (rcButton.right-9, (rcButton.top+rcButton.bottom)/2-1);
cDC.LineTo (rcButton.right-4, (rcButton.top+rcButton.bottom)/2-1);
cDC.MoveTo (rcButton.right-8, (rcButton.top+rcButton.bottom)/2);
cDC.LineTo (rcButton.right-5, (rcButton.top+rcButton.bottom)/2);
cDC.SetPixel (rcButton.right-7, (rcButton.top+rcButton.bottom)/2+1, pen.Color());
rcButton.right -= 14;
}
//Draw Icons on buttons
if ( tbbutton.iBitmap >= 0 )
{
//Draw disabled and mouse over buttons
if ( !IS_ENABLED(tbbutton) || (bOver && !bPressed) )
{
HICON hIcon = ImageList_ExtractIcon (NULL, m_hImageList, tbbutton.iBitmap);
cDC.DrawState (CPoint (rcButton.left + ( bOver ? 4 : 3 ),
rcButton.top + ( bOver ? 4 : 3 )),
m_sizeImage, hIcon, DSS_MONO,
CBrush (bOver ? (IS_INDETERMINATE(tbbutton) ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -20, 0) : HLS_TRANSFORM (::GetSysColor (COLOR_HIGHLIGHT), +50, -66)) : HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -27, 0)));
DestroyIcon (hIcon);
}
//Draw enabled buttons
if ( IS_ENABLED(tbbutton) )
{
::ImageList_Draw (m_hImageList, tbbutton.iBitmap, cDC.m_hDC,
rcButton.left + ( (bOver && !bPressed) ? 2 : 3 ),
rcButton.top + ( (bOver && !bPressed) ? 2 : 3 ),
ILD_TRANSPARENT);
}
}
//Draw text on buttons (New Code added by Jason)
//
//If list style draw text to right of button
if (bList)
{
cDC.ExtTextOut(rcButton.left + m_sizeImage.cx + 6,
(rcButton.top + rcButton.Height() / 2) - (tm.tmHeight / 2),
ETO_CLIPPED,&rcButton,
GetButtonText(i),NULL);
}
else
{
//Align text to center of button
cDC.SetTextAlign(TA_CENTER);
//Draw text
cDC.ExtTextOut(rcButton.left + rcButton.Width() / 2,
rcButton.top + m_sizeImage.cy + 4,
ETO_CLIPPED,&rcButton,
GetButtonText(i),NULL);
}
}
}
}
There you go. The TBSTYLE_LIST causes the text to be drawn to the right of the button and the default TBSTYLE_TRANSPARENT causes the text to be drawn at the bottom of the button.
I hope this helps.
|
|
|
|
|
These are good, have you also thought about doing an XP style edit control, this would be useful to me, also in your example the button in the about box does not work quite right.
|
|
|
|
|
For the Edit control here is what you can do:
Create you own CEditXP derived from CEdit..
Override the messages:
WM_NCPAINT // Painting the frame
WM_KILLFOCUS //
WM_SETFOCUS // These four are needed for changing the frame colors
WM_MOUSEMOVE // when the control gets/looses focus
WM_MOUSEOUT //
Then put the following code in the message handlers:
void CEditXP::OnNcPaint()
{
CClientRect rc(this);
CClientDC cDC(this);
bool bInToolbar = ::ChildOfDockedToolbar (this);
bool bFocus = (::GetFocus() == m_hWnd || ::GetParent (::GetFocus()) == m_hWnd) && bInToolbar;
CPenDC pen (cDC, ::GetSysColor (( bFocus || m_MouseMgr.MouseOver() )
? COLOR_HIGHLIGHT
: (bInToolbar ? COLOR_WINDOW : COLOR_3DSHADOW)));
cDC.SelectObject (::GetStockObject (NULL_BRUSH));
rc.InflateRect(2, 2);
cDC.Rectangle (rc);
pen.Color (::GetSysColor (IsWindowEnabled() ? COLOR_WINDOW : COLOR_3DFACE));
rc.InflateRect (-1, -1);
cDC.Rectangle (rc);
}
void CEditXP::OnSetFocus (CWnd* pOldWnd)
{
CEdit::OnSetFocus (pOldWnd);
if ( ::ChildOfDockedToolbar (this) )
{
Invalidate();
}
OnNcPaint();
}
void CEditXP::OnKillFocus (CWnd* pNewWnd)
{
CEdit::OnKillFocus (pNewWnd);
if ( ::ChildOfDockedToolbar (this) )
{
Invalidate();
}
OnNcPaint();
}
void CEditXP::OnMouseMove (UINT, CPoint)
{
Default();
m_MouseMgr.OnMouseMove();
OnNcPaint();
}
void CEditXP::OnMouseOut ()
{
m_MouseMgr.OnMouseOut ();
OnNcPaint();
}
Christos Efstratiou
|
|
|
|
|
Close, but no cigar!
If you want to retain the highlighted border colour on the focus edit control (which is not what other L&F bits in this section do) then you need to add two more bits of code or else the highlighting gets screwed up.
Solution 1: (with persistent highlight)
Override the PreSubclassWindow() method and add the following code.
void CEditXP::PreSubclassWindow()
{
m_MouseMgr.Init (m_hWnd, MMS_NCPAINT);
}
Now go to the message map in the same file and ' ON_WM_NCPAINT(). It should look something like the following depending on your version of VS.
BEGIN_MESSAGE_MAP(CEditXP, CEdit)
ON_WM_NCPAINT()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEOUT()
ON_WM_NCPAINT()
END_MESSAGE_MAP()
Solution 2:
If you want to use highlighting in keeping with the rest of the Office L&F project then:
Override the PreSubclassWindow() method and add the following code.
void CEditXP::PreSubclassWindow()
{
m_MouseMgr.Init (m_hWnd, MMS_NCPAINT);
}
Now go to the message map in the same file and ' ON_WM_NCPAINT(). It should look something like the following depending on your version of VS.
BEGIN_MESSAGE_MAP(CEditXP, CEdit)
ON_WM_NCPAINT()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEOUT()
ON_WM_NCPAINT()
END_MESSAGE_MAP()
Now change the following bits, too
void CEditXP::OnNcPaint()
{
Default();
CWindowDC cDC (this);
CWindowRect rc (this);
CPenDC pen (cDC, ::GetSysColor (m_MouseMgr.MouseOver() ? COLOR_HIGHLIGHT : COLOR_3DSHADOW));
cDC.SelectObject (::GetStockObject (NULL_BRUSH));
cDC.Rectangle (0, 0, rc.Width(), rc.Height());
}
void CEditXP::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus (pNewWnd);
}
void CEditXP::OnSetFocus(CWnd* pOldWnd)
{
CEdit::OnSetFocus (pOldWnd);
}
void CEditXP::OnMouseMove(UINT nFlags, CPoint point)
{
Default();
m_MouseMgr.OnMouseMove();
}
void CEditXP::OnMouseOut()
{
m_MouseMgr.OnMouseOut ();
}
|
|
|
|
|
Does anyone know how to set button text for each of the buttons on the toolbar without the buttons being all the same size in width?
|
|
|
|
|
When I use CToolBarXP without docking property
there are some spots on the toolbar
why?
|
|
|
|
|
Hi,
I tested your code on an XP machine and I had the same problem.
To correct it, you can add the OnEraseBkgnd handle on my class CToolBarXP:
BOOL CToolBarXP::OnEraseBkgnd (CDC* pDC)
{
CWindowRect rc (this);
rc.OffsetRect (-rc.TopLeft());
pDC->FillSolidRect (rc, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0));
return true;
}
|
|
|
|
|
Is there a way to get the text labels to appear on the right of the button? Somewhat like IE6.
Thanks.
|
|
|
|
|
You must use the TBSTYLE_LIST style when you create the toolbar. You can try to change it after you create it but this can cause some redraw problems.
|
|
|
|
|
Great Code.
What is the best way to use your class as a base class?
I have some Toolbars and other controls with a lot of my own code and would like to add
the XP look to some of them.
I tried something like this "class CMyToolBar : public CToolBarXP" but this does nothing.
If I add an onpaint message handler and then call the base class CToolBar::OnPaint() it works ok but I think there is a better way?
Thanks.
|
|
|
|
|