double buffering

Intrebari despre programarea cu VC++ incluzand mediul de dezvoltare, instalare, setari, debugger, compilator, linker si documentatie.
Post Reply
azhi_dahaka
Junior
Junior
Posts: 9
Joined: 27 Nov 2008, 13:17
Judet: Sibiu

double buffering

Post by azhi_dahaka » 27 Nov 2008, 13:27

salut! va rog dati-mi si mie o mana de ajutor....am urmatoarea functie care-mi schimba culoarea barei de titlu:

void OnNCPaint()
{
Default();

CRect rc;
CWindowDC dc(this);

GetWindowRect(rc);


//get buttonWidth
int buttonWidth = GetSystemMetrics(SM_CXSIZE);

rc.bottom = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);

CDC *pDC= GetWindowDC();

double TitleBarColor = RGB( 0, 0, 0);
double TextColor = RGB( 255, 255, 255);

//title bar
CBrush brush(TitleBarColor);
CBrush* pOldBrush = dc.SelectObject(&brush);

CPen pen(PS_SOLID, 3, TitleBarColor);
CPen* oldPen = dc.SelectObject(&pen);

dc.Rectangle(5,5,rc.Width()-5,rc.bottom-2);

dc.SelectObject(oldPen);
dc.SelectObject(pOldBrush);

//set the text
pDC->SetBkMode(TRANSPARENT);
CString szCap;

int TitleTabSpace = GetSystemMetrics(SM_CYCAPTION)+5;

GetWindowText(szCap);
pDC->SetTextColor(TextColor);
pDC->TextOut(TitleTabSpace,rc.bottom/5,szCap);

// Put the buttons on the caption
CRect closeRect;
closeRect.left = rc.right - rc.left - buttonWidth - 3;
closeRect.top = GetSystemMetrics(SM_CYFRAME) + 2;
closeRect.right = rc.right - rc.left - 5;
closeRect.bottom = GetSystemMetrics(SM_CYSIZE) + 2;

dc.DrawFrameControl(closeRect,
DFC_CAPTION,
DFCS_CAPTIONCLOSE );

CRect maxRect;
maxRect.left = rc.right - rc.left - buttonWidth - buttonWidth - 3;
maxRect.top = GetSystemMetrics(SM_CYFRAME) + 2;
maxRect.right = rc.right - rc.left - buttonWidth - 2 - 3;
maxRect.bottom = GetSystemMetrics( SM_CYSIZE ) + 2;

if(!IsZoomed())

{
dc.DrawFrameControl(maxRect,
DFC_CAPTION,
DFCS_CAPTIONMAX );
}

else
{
dc.DrawFrameControl(maxRect,
DFC_CAPTION,
DFCS_CAPTIONRESTORE );
}

CRect minRect;
minRect.left = rc.right - rc.left - buttonWidth - buttonWidth - buttonWidth - 3;
minRect.top = GetSystemMetrics(SM_CYFRAME) + 2;
minRect.right = rc.right - rc.left - buttonWidth - buttonWidth - 2 - 3 ;
minRect.bottom = GetSystemMetrics( SM_CYSIZE ) + 2;

dc.DrawFrameControl(minRect,
DFC_CAPTION,
DFCS_CAPTIONMIN );

// Save buttons position
m_rcClose = closeRect;
m_rcMin = minRect;
m_rcMax = maxRect;

m_hIcon = LoadIcon(NULL, IDI_APPLICATION);


DrawIconEx (dc.m_hDC, 5, rc.bottom/4, m_hIcon, 16, 16, 0, NULL, DI_NORMAL);
}

dar cand se trimit prea multe mesaje nc paint imi apare un flicker....vroiam sa va intreb...cum as putea folosi metoda de double buffering pentru functia de mai sus? am gasit pe net o gramada de exemple dar niciunul nu mi-a fost de prea mare ajutor. multumesc!
Last edited by azhi_dahaka on 15 Jul 2009, 14:58, edited 1 time in total.



User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: double buffering

Post by Marius Bancila » 27 Nov 2008, 15:12

Double buffering inseamna sa-ti creezi un device context "in memorie", compatibil cu cel in care vrei de fapt sa desenezi, il folosesti pe acesta, si la sfarsit il copiezi in device contextul original.

Am scris aici un articol: http://www.codeguru.com/cpp/misc/misc/g ... hp/c15585/. Daca te uiti la bitmap-uri, o sa vezi exact aceasta tehnica.
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

azhi_dahaka
Junior
Junior
Posts: 9
Joined: 27 Nov 2008, 13:17
Judet: Sibiu

Re: double buffering

Post by azhi_dahaka » 27 Nov 2008, 23:13

foarte bun articolul...multumesc...am incercat ceva....doar ca nu mi-a iesit...imi afiseaza doar scrisul :(...

am facut urmatoarele modificari:
{
...ca mai sus....
CWindowDC dc2(this);

CDC dc;

dc.CreateCompatibleDC(&dc2);

...ca mai sus....

dc2.BitBlt(0, 0,rc.Width(), rc.Height(), &dc,0, 0,SRCCOPY);
}

ce-am gresit? :(

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: double buffering

Post by Marius Bancila » 28 Nov 2008, 00:02

Mai trebuie sa creezi un bitmap compatibil cu dc-ul din memorie, sa-l selectezi in acest dc, apoi sa faci operatiile de desenare.

Uite niste aticole care modifica bara de titlu.
http://www.codeproject.com/KB/dialog/sk ... nbars.aspx
http://www.codeproject.com/KB/dialog/gr ... lebar.aspx
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

azhi_dahaka
Junior
Junior
Posts: 9
Joined: 27 Nov 2008, 13:17
Judet: Sibiu

Re: double buffering

Post by azhi_dahaka » 28 Nov 2008, 12:52

ok...am facut si bitmap-ul....i-am dat CreateCompatibleBitmap....i-am dat select object.....dar tot la fel :( ...cred ca-mi scapa ceva ....oare folosesc bitblt-ul cum trebuie?

Viorel
Microsoft MVP
Microsoft MVP
Posts: 292
Joined: 13 Jul 2007, 12:26

Re: double buffering

Post by Viorel » 28 Nov 2008, 13:36

Poate ar trebui să comentezi linia Default();?

azhi_dahaka
Junior
Junior
Posts: 9
Joined: 27 Nov 2008, 13:17
Judet: Sibiu

Re: double buffering

Post by azhi_dahaka » 28 Nov 2008, 14:31

l-am comentat de test candva...si daca l-am comentat nu-mi mai deseneaza meniul + ca flicker-ul nu dispare





later edit: gata am rezolvat problema... am folosit o clasa de pe codeproject CMemDC si acum deseneaza fara flicker....multumesc frumos marius si viorel pentru ca v-ati implicat in problema mea.

Post Reply