000
20.05.2006, 15:52 Uhr
xXx
Devil
|
Also... ich wollte für eine kleine Anwendung von mir direkt zwischen dem bereich wo die geöffneten Programme alle sind und dem der traybar einen Button mit Text daneben hinsetzen Naja... aber aus irgendeinem Grund hab ich da entweder mich mit den Fenstern vertan oder irgendwas sonnst falsch Evt. sieht ja einer von euch den Fehler
Source File:
C++: |
// ...StateBar.cpp : implementation file //
#include "stdafx.h" #include "....h" #include "...StateBar.h" #include ".\...statebar.h"
// C...StateBar
IMPLEMENT_DYNAMIC(C...StateBar, CButton)
C...StateBar::C...StateBar(void) { m_strText = _T(""); m_bPressed = false; m_bCenterAlign = true; m_nMargin = 20; m_bReadOnly = false; m_memDC.CreateCompatibleDC(NULL); m_pOldObject = NULL; m_bShow = false; m_pwndParent = NULL; m_pwndTray = NULL; m_pwndReBar = NULL; m_pwndTrayNotify= NULL; m_nHeight = 0; }
C...StateBar::~C...StateBar(void) { if(m_hImage) { m_memDC.SelectObject(m_pOldObject); m_pOldObject = NULL; m_bmp.Detach(); ::DeleteObject(m_hImage); } m_memDC.DeleteDC(); }
BEGIN_MESSAGE_MAP(C...StateBar, CButton) ON_CONTROL_REFLECT(BN_CLICKED, OnBnClicked) ON_WM_ERASEBKGND() END_MESSAGE_MAP()
// C...StateBar message handlers
void C...StateBar::PreSubclassWindow(void) { CButton::PreSubclassWindow();
ModifyStyle(0, BS_OWNERDRAW);
CRect rect; GetClientRect(rect);
m_nRadius = 120; if(m_nRadius == 0) m_nRadius = 15; else if(m_nRadius < 0) m_nRadius = (-1) * m_nRadius;
m_nRadius = (int)(rect.bottom * 0.5) - 5;
if(m_nRadius > 6) m_nRadius = 6;
m_ptCenter.x = rect.left + m_nRadius + 1;
if(m_bCenterAlign) m_ptCenter.y = rect.top + (int)(rect.Height() * 0.5 + 0.5); else m_ptCenter.y = rect.top + m_nRadius+1; }
void C...StateBar::SetImage(UINT uBmpRes, UINT nImageWidth) { m_hImage = (::HBITMAP__*)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(uBmpRes), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS); if(!m_hImage) { MessageBox("Fehler beim Laden der Bitmaps!"); return; } m_bmp.Attach(m_hImage); m_uImageWidth = nImageWidth; m_bmp.GetObject(sizeof(::BITMAP),&m_bmpInfo); m_uImageHeight = m_bmpInfo.bmHeight; m_pOldObject = m_memDC.SelectObject(&m_bmp); m_szImage = CSize(m_uImageWidth, m_bmpInfo.bmHeight); m_ptCenter.x = 1; m_ptCenter.y = m_ptCenter.y - m_szImage.cy/2;
if(m_nMargin < m_szImage.cx) m_nMargin = 5 + m_szImage.cx; }
void C...StateBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { /*ASSERT(lpDrawItemStruct != NULL); if(lpDrawItemStruct->itemAction != ODA_DRAWENTIRE) return;
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rcItem = lpDrawItemStruct->rcItem; int nSavedDC = pDC->SaveDC();
pDC->SelectStockObject(NULL_BRUSH); pDC->FillSolidRect(rcItem, ::GetSysColor(COLOR_BTNFACE));
if(m_bPressed) pDC->BitBlt(m_ptCenter.x, m_ptCenter.y, m_uImageWidth, m_uImageHeight, &m_memDC, m_uImageWidth, 0, SRCCOPY); else pDC->BitBlt(m_ptCenter.x, m_ptCenter.y, m_uImageWidth, m_uImageHeight, &m_memDC, 0, 0, SRCCOPY);
if(m_strText.IsEmpty()) GetWindowText(m_strText);
CSize szExtent; CPoint pt;
CRect rcText; CRect rcClient;
GetClientRect(&rcClient); rcText = rcClient; rcText.left += m_nMargin; rcText.right -= 2; if(!m_strText.IsEmpty()) { pDC->SetBkMode(TRANSPARENT); pDC->DrawText(m_strText, rcText, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); int nHeight = rcText.Height(); rcText.top = rcClient.top + (int)((rcClient.Height() - rcText.Height()) * 0.5 + 0.5); rcText.bottom = rcText.top + nHeight; pDC->DrawText(m_strText, rcText, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK); m_rcText = rcText; } rcText.right += 2;
pDC->RestoreDC(nSavedDC);*/ CButton::DrawItem(lpDrawItemStruct); }
bool C...StateBar::IsPressed(void) { return m_bPressed; }
int C...StateBar::GetMargin(void) const { return m_nMargin; }
bool C...StateBar::SetState(bool bPressed) { if(bPressed != m_bPressed) { m_bPressed = bPressed; SetCheck(bPressed ? BST_CHECKED : BST_UNCHECKED); RedrawWindow(); }
return m_bPressed; }
void C...StateBar::SetReadOnly(bool bReadOnly) { m_bReadOnly = bReadOnly; }
void C...StateBar::SetMargin(int nMargin) { m_nMargin = nMargin; }
void C...StateBar::SetText(LPCSTR lpszText) { if(lpszText != NULL) m_strText = lpszText; }
void C...StateBar::OnBnClicked(void) { if(!m_bReadOnly) SetState(!IsPressed()); }
BOOL C...StateBar::Create(LPCSTR lpszCaption, UINT nBmpID, int nWidth) { m_pwndTray = CWnd::FindWindow("Shell_TrayWnd", NULL); m_pwndReBar = CWnd::FindWindowEx(m_pwndTray->GetSafeHwnd(), NULL, "ReBarWindow32", NULL); m_pwndTrayNotify= CWnd::FindWindowEx(m_pwndTray->GetSafeHwnd(), NULL, "TrayNotifyWnd", NULL);
if(!m_pwndReBar || !m_pwndTray || !m_pwndTrayNotify) { MessageBox("Es ist ein Fehler beim erstellen der Status Leiste aufgetreten!", "Fehler", MB_OK | MB_ICONERROR); return FALSE; }
ModifyTaskbar();
SetImage(nBmpID, nWidth);
CRect rcReBar; CRect rcRect; m_pwndReBar->GetWindowRect(&rcReBar);
int nDiff = 3; int nRightSmaller = 5; int nCenter = 0;
if((rcReBar.right - rcReBar.left) >= (rcReBar.bottom - rcReBar.top)) { m_nHeight = rcReBar.bottom - rcReBar.top; if(m_nHeight > 30) { nCenter = (m_nHeight - 15) / 2; m_nHeight = 15; }
nDiff = m_nHeight / 10;
rcRect.SetRect(rcReBar.right, 0 + nDiff + nCenter, rcReBar.right + 15 - nRightSmaller, m_nHeight - nDiff + nCenter); } else if((rcReBar.right - rcReBar.left) < (rcReBar.bottom - rcReBar.top)) rcRect.SetRect(0 + nDiff, rcReBar.bottom, rcReBar.right - rcReBar.left - nDiff, rcReBar.bottom + 15 - nRightSmaller);
return CButton::Create(lpszCaption, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, rcRect, m_pwndTray, 1); }
void C...StateBar::ModifyTaskbar(void) { CRect rcReBar; CRect rcTrayNotify; CRect rcTray; m_pwndReBar->GetWindowRect(&rcReBar); m_pwndTrayNotify->GetWindowRect(&rcTrayNotify); m_pwndTray->GetWindowRect(&rcTray);
if ((rcReBar.right - rcReBar.left) >= (rcReBar.bottom - rcReBar.top)) { m_rcReBarWnd.left = rcReBar.left + rcTray.left; m_rcReBarWnd.right = rcTrayNotify.left - rcReBar.left - 15 + rcTray.left; m_rcReBarWnd.bottom = rcReBar.bottom - rcReBar.top; m_rcReBarWnd.top = 0; } else if ((rcReBar.right - rcReBar.left) < (rcReBar.bottom - rcReBar.top)) { m_rcReBarWnd.left = 0; m_rcReBarWnd.right = rcTrayNotify.right - rcTrayNotify.left; m_rcReBarWnd.top = rcReBar.top + rcTray.top; m_rcReBarWnd.bottom = rcTrayNotify.top - 15 - rcReBar.top + rcTray.top; }
m_pwndReBar->MoveWindow(&m_rcReBarWnd); }
BOOL C...StateBar::OnEraseBkgnd(CDC* pDC) { return TRUE; }
|
Header File:
C++: |
#pragma once
// C...StateBar
class C...StateBar : public CButton { DECLARE_DYNAMIC(C...StateBar)
public: C...StateBar(void); virtual ~C...StateBar(void);
public: BOOL Create(LPCSTR lpszCaption, UINT nBmpID, int nWidth);
public: void SetImage(UINT idBmp, UINT nImageWidth); bool SetState(bool bPressed); void SetReadOnly(bool bReadOnly = true); void SetText(LPCSTR lpszText); void SetMargin(int nMargin = 20);
public: int GetMargin(void) const; bool IsPressed(void);
protected: virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual void PreSubclassWindow(void);
protected: int m_nMargin; int m_nRadius; int m_nPane; CRect m_rcButton; CPoint m_ptCenter; CRect m_rcText; bool m_bPressed; bool m_bCenterAlign; bool m_bReadOnly; CSize m_szImage; CString m_strText; protected: CDC m_memDC; ::HBITMAP__* m_hImage; CBitmap m_bmp; UINT m_uImageWidth; UINT m_uImageHeight; CGdiObject* m_pOldObject; BITMAP m_bmpInfo;
protected: CWnd* m_pwndParent; CWnd* m_pwndTray; CWnd* m_pwndTrayNotify; CWnd* m_pwndReBar; CRect m_rcReBarWnd; bool m_bShow; int m_nHeight;
protected: void ModifyTaskbar(void); void ReModifyTaskbar(void);
protected: afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnBnClicked(void); DECLARE_MESSAGE_MAP() };
|
Ich habs halt imo Einfach mit nem normalen TrayIcon gelöst... aber das ist nicht das wahre D.h. hab ich mich dran gesetzt diese Klasse zu entwickeln... aber funzt halt noch net ganz |