Click here to Skip to main content
15,899,026 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CListBox Control Pin
Gary R. Wheeler7-Aug-04 0:36
Gary R. Wheeler7-Aug-04 0:36 
Generalnext dialog Pin
doraemon16-Aug-04 22:15
doraemon16-Aug-04 22:15 
GeneralRe: next dialog Pin
Gary R. Wheeler7-Aug-04 0:41
Gary R. Wheeler7-Aug-04 0:41 
GeneralRe: next dialog Pin
DavidR_r7-Aug-04 1:22
DavidR_r7-Aug-04 1:22 
GeneralFlicker free drawing in MFC... Pin
JamRoll6-Aug-04 22:10
JamRoll6-Aug-04 22:10 
GeneralRe: Flicker free drawing in MFC... Pin
Neville Franks6-Aug-04 23:08
Neville Franks6-Aug-04 23:08 
GeneralRe: Flicker free drawing in MFC... Pin
Ryan Binns8-Aug-04 18:41
Ryan Binns8-Aug-04 18:41 
GeneralRe: Flicker free drawing in MFC... Pin
JamRoll10-Aug-04 18:06
JamRoll10-Aug-04 18:06 
I gave all the code, cuz I felt that it would be better for all to know exactly what was going on and I didn't wanna be told I didn't give enuf information! Smile | :)
Anyways, here are some snippets, then:


the main APP OnPaint() function.
void battleshit::OnPaint() {<br />
	CPaintDC dc(this);<br />
<br />
	CPen pen;<br />
	pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 150));<br />
<br />
	CBrush brush;<br />
	brush.CreateSolidBrush(RGB(0, 0, 200));<br />
<br />
	dc.SelectObject(&pen);<br />
	dc.SelectObject(&brush);<br />
<br />
	dc.Rectangle(0, 0, 400, 552);<br />
<br />
	player->draw(&dc);<br />
	computer->draw(&dc);<br />
} // OnPaint();


and a single CELL draw code:
<br />
void CELL::draw(CPaintDC *pdc) {<br />
	if (hilited) <br />
		pdc->SelectObject(&hiliter); else<br />
		pdc->SelectObject(&pen);<br />
<br />
	pdc->SelectObject(&cellBrush);<br />
	pdc->Rectangle(rect);<br />
<br />
	CRect circle = rect;<br />
	circle.left += 5;<br />
	circle.top += 5;<br />
	circle.right -= 5;<br />
	circle.bottom -= 5;<br />
<br />
	pdc->SelectObject(&pen);<br />
	pdc->SelectObject(&pegBrush);<br />
	pdc->Ellipse(circle);<br />
}<br />


a SHIP object draw code:
<br />
void SHIP::draw(CPaintDC *pdc) {<br />
	if (hilited)<br />
		pdc->SelectObject(&hiliter); else<br />
		pdc->SelectObject(&pen);<br />
<br />
	if (sunk())<br />
		pdc->SelectObject(&sunkBrush); else<br />
		pdc->SelectObject(&shipBrush);<br />
<br />
	if (size != 5) {<br />
		pdc->Rectangle(rect);<br />
	} else {<br />
		pdc->Rectangle(rect);<br />
<br />
		if (hilited)<br />
		  pdc->FloodFill(location.x + (CELLSIZE / 2), location.y + (CELLSIZE / 2), RGB(0, 255, 255)); else<br />
		  pdc->FloodFill(location.x + (CELLSIZE / 2), location.y + (CELLSIZE / 2), RGB(0, 0, 0));<br />
<br />
		if (vertical) {<br />
		} else {<br />
		}<br />
	}<br />
<br />
	pdc->SelectObject(&pegBrush);<br />
	for (int c = 0; c < size; c++) {<br />
		pdc->SelectObject(&pen);<br />
		pdc->SelectObject(&pegBrush);<br />
	}<br />
}<br />


and finally the BOARD object draw code:
<br />
void BOARD::draw(CPaintDC *pdc) {<br />
	pdc->SelectObject(&pen);<br />
	pdc->SelectObject(&boardBrush);<br />
<br />
	pdc->Rectangle(rect);<br />
<br />
	for (int y = 0; y < size; y++) {<br />
		for (int x = 0; x < size; x++) {<br />
			cells[x][y].draw(pdc);<br />
		}<br />
	}<br />
<br />
	for (int ship = 0; ship < 5; ship++) {<br />
		ships[ship].draw(pdc);<br />
	}<br />
<br />
        // paint the title of the board.<br />
	CRect tRect, sRect;<br />
	tRect.left = rect.left - (CELLSIZE + CELLSPACING);<br />
	tRect.top = rect.top - (CELLSIZE + CELLSPACING);<br />
	tRect.right = rect.left + 300;<br />
	tRect.bottom = rect.top + CELLSIZE;<br />
	sRect = tRect;<br />
	sRect.left += 2;<br />
	sRect.top += 2;<br />
<br />
	pdc->SetTextColor(RGB(0, 0, 0));<br />
	pdc->SetBkMode(TRANSPARENT);<br />
	pdc->DrawText(_T(title), -1, sRect, DT_SINGLELINE);<br />
	pdc->SetTextColor(RGB(255, 255, 0));<br />
	pdc->DrawText(_T(title), -1, tRect, DT_SINGLELINE);<br />
}<br />


Yyou will notice some lines of code that read if (hilited) { /*do hilite stuff*/ } else { /*do NON-hilite stuff*/ }. It seems that if I change the hilite value from true to false (or vice-versa) I have to invalidate the area for the change to take affect....this is what is causing the flicker!

One fella sed ..."You need to use a memory DC" - a what???
Perhaps I am just daft...but I did take a course (a 20,000 dollar course at that, altho the course wasn't JUST MFC)...so I should hope i know at least a little of what i am doing...hehe; the teacher was useless at helping me correct the flicker - told us (the whole class) to figger it out ourselves!!! Blush | :O

anyways, thanx for yer help guys! It really is appreciated, and please please forgive my previous LONG post... Frown | :(

ciao for now! JamRoll...

JamRoll@telus.net
http://jamroll.dyndns.org/
GeneralRe: Flicker free drawing in MFC... Pin
Ryan Binns10-Aug-04 18:39
Ryan Binns10-Aug-04 18:39 
GeneralRe: Flicker free drawing in MFC... Pin
JamRoll12-Aug-04 10:48
JamRoll12-Aug-04 10:48 
GeneralRe: Flicker free drawing in MFC... Pin
Ryan Binns12-Aug-04 13:56
Ryan Binns12-Aug-04 13:56 
QuestionPlease Help me about Digital Map Help ?Help ?Help ?Help ? Please ? Pin
A_Fa6-Aug-04 21:06
A_Fa6-Aug-04 21:06 
Generalproblem with STL Vector Pin
Sivaji6-Aug-04 20:41
Sivaji6-Aug-04 20:41 
GeneralRe: problem with STL Vector Pin
DavidR_r7-Aug-04 1:26
DavidR_r7-Aug-04 1:26 
GeneralHey problem with STL Vector Pin
Sivaji6-Aug-04 20:39
Sivaji6-Aug-04 20:39 
Questionhow to change the shape of the SDI window Pin
n.srinukumar6-Aug-04 19:49
n.srinukumar6-Aug-04 19:49 
QuestionWhat is the difference between LPWSTR and WCHAR * Pin
ting6686-Aug-04 19:40
ting6686-Aug-04 19:40 
AnswerRe: What is the difference between LPWSTR and WCHAR * Pin
Gary R. Wheeler7-Aug-04 1:13
Gary R. Wheeler7-Aug-04 1:13 
GeneralRe: What is the difference between LPWSTR and WCHAR * Pin
ting6687-Aug-04 2:45
ting6687-Aug-04 2:45 
GeneralRe: What is the difference between LPWSTR and WCHAR * Pin
Tim Smith7-Aug-04 19:22
Tim Smith7-Aug-04 19:22 
GeneralVC6 IDE Bookmarks question Pin
Gammill6-Aug-04 19:02
Gammill6-Aug-04 19:02 
GeneralShell extension...help Pin
Member 12827896-Aug-04 18:34
Member 12827896-Aug-04 18:34 
GeneralRe: Shell extension...help Pin
Michael Dunn7-Aug-04 3:46
sitebuilderMichael Dunn7-Aug-04 3:46 
QuestionHow to set the entry point of an application. Pin
Jijo.Raj6-Aug-04 17:22
Jijo.Raj6-Aug-04 17:22 
AnswerRe: How to set the entry point of an application. Pin
bikram singh6-Aug-04 23:15
bikram singh6-Aug-04 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.