D
Ich stelle mal meinen Quellcode von meinem CXPButton rein... Vieleicht kann mir ja jemand sagen warum mein Button nachdem ich mit meiner Maus ein paar mal rüber gefahren bin irgendwie so aussieht als ob er tiefergesetzt wurde... Ist schon merkwürdig... man könnte zwar im Hauptprogramm dann über nen wm_mousemove abfragen wo sich der zeiger befindet und dann den kompletten Dialog neu zeichnen, aber ich wollte eigentlich alles in meiner CXPButton Klasse unterbringen. So das man sich beim einbinden keinen Kopf mehr machen muss... erst recht wenn es am ende dann vieleicht 10 Button und noch anderer kram ist... kann man das ganze vieleicht mit nem Sendmessage ans Dialogfenster in "onMouseLeave" erreichen? und wenn ja wie?
// XPBUTTON.cpp : implementation file
//
#include "stdafx.h"
#include "XPStyle.h"
#include "XPBUTTON.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ODS_NOFOCUSRECT 0x0200
/////////////////////////////////////////////////////////////////////////////
// CXPBUTTON
IMPLEMENT_DYNAMIC(CXPBUTTON, CButton)
CXPBUTTON::CXPBUTTON(): m_pTheme(NULL)
{
bMouseOverButton = false;
}
CXPBUTTON::~CXPBUTTON()
{
}
BEGIN_MESSAGE_MAP(CXPBUTTON, CButton)
//{{AFX_MSG_MAP(CXPBUTTON)
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXPBUTTON message handlers
void CXPBUTTON::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// wird aufegrufen vom Framework wegen ownerdraw-style
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CString strCaption;
GetWindowText(strCaption);
if (m_pTheme.IsAppThemed())
{
// button state
BOOL bIsPressed = (lpDrawItemStruct->itemState & ODS_SELECTED);
BOOL bIsFocused = (lpDrawItemStruct->itemState & ODS_FOCUS);
BOOL bIsDisabled = (lpDrawItemStruct->itemState & ODS_DISABLED);
BOOL bDrawFocusRect = !(lpDrawItemStruct->itemState & ODS_NOFOCUSRECT);
// Prepare draw... paint button background
DWORD state = (bIsPressed)?PBS_PRESSED:PBS_NORMAL;
if(state == PBS_NORMAL)
{
if(bIsFocused)
state = PBS_DEFAULTED;
if(bMouseOverButton)
state = PBS_HOT;
}
m_pTheme.DrawBackground(lpDrawItemStruct->hDC, BP_PUSHBUTTON, state, &lpDrawItemStruct->rcItem, 0);
int nOldBkgnMode = dc.SetBkMode(TRANSPARENT);
dc.DrawText(strCaption, &lpDrawItemStruct->rcItem, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.SetBkMode(nOldBkgnMode);
if (bIsFocused && bDrawFocusRect)
{
RECT focusRect =lpDrawItemStruct->rcItem;
InflateRect(&focusRect, -3, -3);
DrawFocusRect(dc, &focusRect);
}
}
dc.Detach();
}
BOOL CXPBUTTON::OnEraseBkgnd(CDC* pDC)
{
// wir zeichnen nichts, weil wir das fenster mit den button
// komplett in DrawItem zeichnen
// ausserdem verhindern wir dadurch flickern da der standard hintergrund
// weiss gezeichnet wird
return TRUE;
}
void CXPBUTTON::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_pTheme = CXPTheme(GetSafeHwnd(), L"BUTTON");
CButton::PreSubclassWindow();
}
void CXPBUTTON::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(!bMouseOverButton)
{
bMouseOverButton = TRUE;
TRACKMOUSEEVENT trackmouseevent;
trackmouseevent.cbSize = sizeof(trackmouseevent);
trackmouseevent.dwFlags = TME_LEAVE;
trackmouseevent.hwndTrack = GetSafeHwnd();
trackmouseevent.dwHoverTime = 0;
_TrackMouseEvent(&trackmouseevent);
InvalidateRect(NULL, FALSE);
}
CButton::OnMouseMove(nFlags, point);
}
LONG CXPBUTTON::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
bMouseOverButton = false;
InvalidateRect(NULL, FALSE);
return 0;
}
#if !defined(AFX_XPBUTTON_H__9AE4DC26_E531_4C94_BF39_F53EE333DF78__INCLUDED_)
#define AFX_XPBUTTON_H__9AE4DC26_E531_4C94_BF39_F53EE333DF78__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// XPBUTTON.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CXPBUTTON window
class CXPBUTTON : public CButton
{
DECLARE_DYNAMIC(CXPBUTTON)
// Construction
public:
CXPBUTTON();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CXPBUTTON)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CXPBUTTON();
private:
CXPTheme m_pTheme;
BOOL ScreenPointInButtonRect(CPoint point);
bool bMouseOverButton;
// Generated message map functions
protected:
//{{AFX_MSG(CXPBUTTON)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
LONG OnMouseLeave(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_XPBUTTON_H__9AE4DC26_E531_4C94_BF39_F53EE333DF78__INCLUDED_)
ist bestimmt nur kinderkram für die meisten von euch, aber für mich die halbe c++ welt...