Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:



kreslene tlacitko - theme

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: kreslene tlacitko - theme

Autor: Fousy

20:45:23 02.04.2010

Diky moc, vyzobnu si to DrawThemeBackground.. a zkusim

Citovat příspěvek

 

Re: kreslene tlacitko - theme

Autor: RadekChalupa

20:36:13 02.04.2010

Tohle je kód třídy která zabaluje uživ. kreslený button vč. výběru stylu themed/klasic. (Slouží k výběru barvy, kterou také zobrazuje "na těle")

[code]
class ButtonVyberBarvy : public CWindowImpl < ButtonVyberBarvy, CWindow >
{
public:
DECLARE_WND_SUPERCLASS(L"RButtonVyberBarvy", WC_BUTTONW)

public:
static const unsigned int hraniceCernaBila = 140;

protected:
static const DWORD OKNO_STAV_VLASTNIBARVA = 0x00000001;
static const DWORD OKNO_STAV_MOUSEOVER = 0x00000002;
static const DWORD OKNO_STAV_TRACKED = 0x00000004;
static const DWORD OKNO_STAV_TRACKLEAVE = 0x00000008;
static const DWORD OKNO_STAV_TRACKHOVER = 0x00000010;
static const DWORD RBUTTON_SIRKA_OKRAJE = 3;

protected:
COLORREF crBarva;
DWORD dwStav;
int sirkaOkraje;
CWindow toolTip;

public:
ButtonVyberBarvy()
{
crBarva = GetSysColor(COLOR_3DFACE);
dwStav = OKNO_STAV_TRACKHOVER;
sirkaOkraje = RBUTTON_SIRKA_OKRAJE;
hTheme = NULL;
}

public:
~ButtonVyberBarvy()
{
if (this->toolTip.IsWindow())
if (!this->toolTip.DestroyWindow())
_com_raise_error(AtlHresultFromLastError());
}

private:
BEGIN_MSG_MAP(ButtonVyberBarvy)
MESSAGE_HANDLER(OCM_COMMAND, OnCommand)
MESSAGE_HANDLER(OCM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(WM_MOUSELEAVE, OnMouseLeave)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()

public:
COLORREF GetBarva()
{
return this->crBarva;
}

#if _WIN32_WINNT >= 0x0501
private:
HTHEME hTheme;

private:
void KreslitPozadi(LPDRAWITEMSTRUCT lpDIS)
{
if (lpDIS->itemState & ODS_DISABLED)
{
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1,4,&lpDIS->rcItem, 0);
return;
}
if (this->dwStav & OKNO_STAV_MOUSEOVER)
{
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1,2, &lpDIS->rcItem, 0);
if (!( lpDIS->itemState & ODS_SELECTED ))
{
InflateRect(&lpDIS->rcItem, -this->sirkaOkraje,-this->sirkaOkraje);
if (this->dwStav & OKNO_STAV_VLASTNIBARVA)
{
HBRUSH hBrush = CreateSolidBrush(this->crBarva);
FillRect(lpDIS->hDC, &lpDIS->rcItem, hBrush);
if (!DeleteObject(hBrush))
_com_raise_error(AtlHresultFromLastError());
}
return;
}
}
if (lpDIS->itemState & ODS_FOCUS)
{
if (lpDIS->itemState & ODS_SELECTED)
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1,3,&lpDIS->rcItem, 0);
else
{
if (lpDIS->itemState & ODS_DEFAULT)
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1,5,&lpDIS->rcItem, 0);
else
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1,1,&lpDIS->rcItem, 0);
}
}
else
{
if (lpDIS->itemState & ODS_DEFAULT)
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1, 5, &lpDIS->rcItem, 0);
else
DrawThemeBackground(this->hTheme, lpDIS->hDC, 1, 1, &lpDIS->rcItem, 0);
}
InflateRect(&lpDIS->rcItem, -this->sirkaOkraje, -this->sirkaOkraje);
if (this->dwStav & OKNO_STAV_VLASTNIBARVA)
{
HBRUSH hBrush = CreateSolidBrush(this->crBarva);
FillRect(lpDIS->hDC, &lpDIS->rcItem, hBrush);
if (!DeleteObject(hBrush))
_com_raise_error(AtlHresultFromLastError());
}
}

#endif // #if _WIN32_WINNT >= 0x0501

private:
void KreslitPozadiStare(LPDRAWITEMSTRUCT dis)
{
HBRUSH hBrush;
if (this->dwStav & OKNO_STAV_VLASTNIBARVA)
{
hBrush = CreateSolidBrush(this->crBarva);
HBRUSH hbOrig = (HBRUSH)SelectObject(dis->hDC, hBrush);
Rectangle(dis->hDC, dis->rcItem.left, dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom);
SelectObject(dis->hDC, hbOrig);
if (!DeleteObject(hBrush))
_com_raise_error(AtlHresultFromLastError());
}
}

private:
LRESULT OnCommand(UINT, WPARAM wParam, LPARAM, BOOL&)
{
if (HIWORD(wParam) == BN_CLICKED)
VybratBarvu();
return 0;
}

private:
LRESULT OnDrawItem(UINT, WPARAM, LPARAM lParam, BOOL&)
{
#if _WIN32_WINNT >= 0x0501
if (IsAppThemed())
{
this->hTheme = OpenThemeData(m_hWnd, L"Button");
KreslitPozadi((LPDRAWITEMSTRUCT)lParam);
}
else
KreslitPozadiStare((LPDRAWITEMSTRUCT)lParam);
#else
KreslitPozadiStare((LPDRAWITEMSTRUCT)lParam);
#endif // _WIN32_WINNT >= 0x0501
unsigned int prumer = (GetRValue(this->crBarva) +
GetBValue(this->crBarva) + GetGValue(this->crBarva)) / 3;
if (prumer > hraniceCernaBila)
SetTextColor(((LPDRAWITEMSTRUCT)lParam)->hDC, 0x00000000);
else
SetTextColor(((LPDRAWITEMSTRUCT)lParam)->hDC, 0x00FFFFFF);
SetBkMode(((LPDRAWITEMSTRUCT)lParam)->hDC, TRANSPARENT);
DrawText(((LPDRAWITEMSTRUCT)lParam)->hDC, L"Vybrat", -1, &((LPDRAWITEMSTRUCT)lParam)->rcItem,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
return 0;
}

private:
LRESULT OnMouseLeave(UINT, WPARAM, LPARAM, BOOL&)
{
this->dwStav &=~ OKNO_STAV_TRACKLEAVE;
this->dwStav |= OKNO_STAV_TRACKHOVER;
this->dwStav &=~ OKNO_STAV_MOUSEOVER;
Invalidate();
return DefWindowProc();
}

private:
LRESULT OnMouseMove(UINT, WPARAM, LPARAM, BOOL&)
{
TRACKMOUSEEVENT tme;
if (this->dwStav & OKNO_STAV_TRACKHOVER)
{
this->dwStav &=~ OKNO_STAV_TRACKHOVER;
this->dwStav |= OKNO_STAV_MOUSEOVER;
RedrawWindow();
}
if (!(this->dwStav & OKNO_STAV_TRACKLEAVE))
{
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.dwHoverTime = HOVER_DEFAULT;
tme.hwndTrack = m_hWnd;
if (!_TrackMouseEvent(&tme) )
{
}
this->dwStav |= OKNO_STAV_TRACKLEAVE;
}
return DefWindowProc();
}

private:
LRESULT OnSetCursor(UINT, WPARAM, LPARAM, BOOL&)
{
SetCursor(LoadCursor(NULL, IDC_HAND));
return TRUE;
}

public:
void Nastavit(HWND hWnd, COLORREF crBarva)
{
ATLASSERT(::IsWindow(hWnd));
if (!SubclassWindow(hWnd))
_com_raise_error(AtlHresultFromLastError());
if (crBarva >> 24)
_com_raise_error(E_INVALIDARG);
ModifyStyle(0, BS_OWNERDRAW);
this->crBarva = crBarva;
this->dwStav |= OKNO_STAV_VLASTNIBARVA;
// Vytvořit a nastavit Tooltip
if (this->toolTip.IsWindow())
if (!this->toolTip.DestroyWindow())
_com_raise_error(AtlHresultFromLastError());
if (!this->toolTip.Create(TOOLTIPS_CLASS, NULL, NULL, NULL, TTS_ALWAYSTIP, 0, 0U, NULL))
_com_raise_error(AtlHresultFromLastError());
RECT rect;
this->GetClientRect(&rect);
TOOLINFO ti;
ZeroMemory(&ti, sizeof(TOOLINFO));
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = m_hWnd;
memcpy(&ti.rect, &rect, sizeof(rect));
ti.hinst = _AtlBaseModule.m_hInst;
ti.lpszText = (WCHAR*)L"Vybrat barvu standardním systémovým dialogem pro výběr barvy";
if (this->toolTip.SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti) == 0)
_com_raise_error(AtlHresultFromLastError());
Invalidate();
}

public:
void VybratBarvu()
{
CHOOSECOLOR cc;
static COLORREF crVlastniBarvy[16] =
{0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF,
0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF,
0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF, 0x00FFFFFF,
0x00FFFFFF};
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = ::GetParent(m_hWnd);
cc.lpCustColors = (LPDWORD)crVlastniBarvy;
cc.rgbResult = this->crBarva;
cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR;
if (!ChooseColor(&cc))
return;
this->crBarva = cc.rgbResult;
Invalidate();
if (::IsWindow(::GetParent(m_hWnd)))
GetParent().PostMessage(WM_APP + 2, this->crBarva, (LPARAM)GetMenu());
}
}; // ButtonVyberBarvy

Radek Chalupa
- vývoj software na zakázku
- školení programování (C/C++, Win32 API, ATL, COM, ActiveX, C#, NET Framework, MFC)
http://www.radekchalupa.cz

[/code]

Citovat příspěvek

 

kreslene tlacitko - theme

Autor: Fousy

20:06:18 02.04.2010

Zdravim, mam uzivatelsky kreslene tlacitko s ikonou a textem. Problem je ze nedokazu aby bylo zobrazeno ve stylu XP (pred vykreslenim styl XP samozrejme ma). Nevite jak na to?
Diky

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: