|
any one help me how to load TIFF image into my
MFC application?
how get information of pixel in that TIFF image?
if any one find solution please share with me.
|
|
|
|
|
Try the graphics library CxImage, available on CP. http://www.codeproject.com/bitmap/cximage.asp
or www.libtiff.org and get the tifflib library, CxImage uses this library as well
"Home computers are being called upon to perform many new functions, including the consumption of homework formerly eaten by the dog." - Doug Larson
|
|
|
|
|
I would like to ask you what is the best best way to store information like, for instance, user preferences, on a CFormView project.
Serializing would make it but i do not know how to make avoiding the Open/Save dialog.
It woul be nice if you could help me.
Thanks in advance
|
|
|
|
|
Hi guys,
I have a small problem.
Actually I am able to open a perticular page by using HtmlHelp() function. Problem is with If I want to go to the perticular topic with in the page like On my single page I have file, New Open and Save and I want to see only the Save As. That is seeing only the bookmarks.
Thanks & Regards,
Md Azghar Hussain.
Salman
Live and Let live
|
|
|
|
|
Hi,
Is it possible to search for a text written on a bitmap.
If possible tell me If we can search text even if the bitmap can be stretched.
bbye
Salman
Live and Let live
|
|
|
|
|
|
Thanks for suggestion. Can u kindly give me a small sample
Salman
Live and Let live
|
|
|
|
|
Who wrote the text on the bitmap?
If your program did the writing, then you need to record the text and where you wrote it. From there it is smiple.
Search any bitmap?
You need an OCR library ($$$) to search the bitmap, and there is no garantee it will beable to find the string. An OCR library should not care if the bitmap is strected.
INTP
|
|
|
|
|
Hi,
Thanks for your reply.
Unfortunately I am not writing a Text in Bitmap.
Where can I find this OCR Library.
Do we have any support in Windows for such type of operations.
Thanks & Regards
Salman
Live and Let live
|
|
|
|
|
Hello,
I have been given a program consisting of several C written modules (neither C++ nor C#),
I want to edit/debug/execute so as to understand what it does and how it works, in the easiest and quickest possible way.
Which product/package would you advise me to use ?
Regards?
aprx
|
|
|
|
|
Your best choice would be an IDE (integrated development environment). IDE's typically include a syntax-highlighting editor, compiler, and debugger. The most prominent IDE in the Windows world is Microsoft Visual Studio. Most C++ tools will work just as well with C.
You can check out a list of IDE's at Programmer's Paradise here[^]. They also sell tools here[^] and here[^] that help with analyzing code.
Software Zen: delete this;
|
|
|
|
|
Any IDE that recognises a 'C' module and has edit/debug capabilities; preferably the one that is going to be used to compile the final code.
To fully understand how the code is supposed to work, I reccomend testing it using the origanal IDE (if any, and available).
INTP
|
|
|
|
|
What to use and how to display postscript file in my win32(gui) application ?!
|
|
|
|
|
You could look at hosting the GhostScript DLL, which will do all the rendering for you.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hello Friends,
I am doing an accounting package for my friend.i am facing a problem for displaying reports in the CListCtrl. I want to display in the CListCtrl in four columns and in the following format but i Cann't able to do so. so please help
Account_Name Debit Credit Transaction_Type
Computer 1000 --- Computer Purchased
Cash --- 1000 Computer Purchased
Thank you,
Neelesh K J Jain.
|
|
|
|
|
Rather than using a CListBox control, you would be better off using a list control. An example of a list control is the right hand pane in Windows Explorer. When it's set for the details view, the list control is in report mode, which supports multiple columns. Try Matt Weagle's article[^] here on Code Project. It gives a basic introduction to using the list control.
Software Zen: delete this;
|
|
|
|
|
I just wish to have 2 dialogs in my MFC prrogram:
when I click "next" in dialog1, then dialog1 disappear and replaced with dialog2. that's it.
how can i do this?
I am new to MFC... would any one pls help??
Many Thanks!
|
|
|
|
|
CMyDialog1 dlg1;
CMyDialog2 dlg2;
int result = dlg1.DoModal();
if (result == NEXTCLICKED) {
dlg2.DoModal();
} CMyDialog1 and CMyDialog2 are the dialog classes for your two dialogs. NEXTCLICKED is a constant value. In your 'next' button handler in the CMyDialog1 class, call EndDialog(NEXTCLICKED); .
Software Zen: delete this;
|
|
|
|
|
Consider use of tab control, for example this is the way for building wizards
DavidR
|
|
|
|
|
Hi! My name is Jarett - a budding MFC programmer!!! yay.
Anyways, I am having some difficulties getting rid of some flicker. Now, before ignoring the rest of this, and telling me to look up info on the net; I have! And I am at my wits end. Nothing seems to refer to my specific issue. Here's my program (I know, it's long and boring).
Before reading any code, let me explain my idea (if the code isn't clear enough). The idea is this: It's battleship. Battleship has a board for both players (computer, and human in this case). Each board has cells (or places for pegs and ships). each board also gets five ships (duh). Now, I want to have the program display a cute little yellow line around a cell or ship (easily accomplished using a CPen (which I call 'hiliter')), but I get harsh flickering. So, I created CELL, SHIP and BOARD objects. A ship has cells, and so does the board. A ship will have 5 cells, and the board will have 10 by 10 cells (100). Easy enuf to figger out, right?
One last thing: I hope I don't have incomplete lines of code here. If so, just ignore them.
//////////////////////////////////////////////////////////////////////////////////
// battleshit.h
//////////////////////////////////////////////////////////////////////////////////
#define IDR_MENU1 100
#define CELLSIZE 20
#define CELLSPACING 0
// the cell class. the basics of battleship.
class CELL {
protected:
CPoint location;
CRect rect;
CPen pen, hiliter;
CBrush cellBrush, pegBrush;
bool hilited, occupied, shot, displayed, selected;
public:
CELL();
// this shall do the actual drawing on screen...acourse
void draw(CPaintDC *pdc);
// "get" functions
bool isHilited() { return hilited; }
bool isOccupied() { return occupied; }
bool isShot() { return shot; }
bool isDisplayed() { return displayed; }
bool isSelected() { return selected; }
// returns true if CPoint specified is within this CELL
bool pointInside(CPoint point) { if (rect.PtInRect(point) == 0) return false; else return true; }
// this will return the upper-left coordinate of the cell
CPoint getLocaton() { return location; }
// this will return (left, right, top, bottom) of the CELL in stored in a CRect
CRect getRect() { return rect; }
// "set" functions.
// sets the upper-left location of the CELL only.
// pass in either (int x, int y) or (CPoint point).
void setLocation(int x, int y);
void setLocation(CPoint point);
// sets the upper-left location of the cell, AND its lower-right as well.
// pass in either (int x, int y, int w, int h) or (CRect rect).
void setRect(int x, int y, int w, int h);
void setRect(CRect r);
// hilights the cell!
void hilite() { hilited = true; }
// tells the cell that a ship is currently occupying this square.
void occupy() { occupied = true; }
// 'shoots' the cell, placing a WHITE peg in it.
void shoot() { shot = true; }
// to toggle-on the display of the cell
void display() { displayed = true; }
// to toggle-off the display of the cell
void hide() { displayed = false; }
// used to reset ALL cell data to defaults.
void reset();
void select() { selected = true; }
void deselect() { selected = false; }
void unHilite() { hilited = false; }
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// the SHIP class HAS A grouping of cells (for informational/data purposes only)
class SHIP {
protected:
CPoint location;
CRect rect;
CPen pen, hiliter;
CBrush shipBrush, sunkBrush, pegBrush;
bool hilited, displayed, vertical, selected;
int size;
CELL cells[5]; // yes, five. some ships may be smaller, and the 'extra' cells will just be ignored.
public:
SHIP();
// this shall do the actual drawing on screen...acourse
void draw(CPaintDC *pdc);
// "get" functions
bool sunk();
bool isHilited() { return hilited; }
bool isDisplayed() { return displayed; }
bool isVertical() { return vertical; }
bool isSelected() { return selected; }
// returns true if CPoint specified is within this SHIP
bool pointInside(CPoint point) { if (rect.PtInRect(point) == 0) return false; else return true; }
// this will return the upper-left coordinate of the SHIP
CPoint getLocation() { return location; }
// this will return (left, right, top, bottom) of the SHIP in stored in a CRect
CRect getRect() { return rect; }
// "set" functions
void setShip(int x, int y, int sz, bool vert);
void setPen(CPen p);
void setHiliter(CPen h);
void setShipBrush(CBrush b);
void setPegBrush(COLORREF color) { pegBrush.CreateSolidBrush(color); }
void select() { selected = true; }
void deselect() { selected = false; }
void rotate() { vertical = !vertical; }
void unHilite() { hilited = false; }
void hilite() { hilited = true; }
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// the board class HAS A grouping of cells and ships.
class BOARD {
protected:
CPoint location;
CRect rect;
CPen pen, hiliter;
CBrush boardBrush;
bool displayed;
int size;
char *title;
public:
CELL cells[10][10];
SHIP ships[5];
BOARD(char *title, CPoint point, int sz); // sz isn't really used yet...so, ignore it for the most part.
void draw(CPaintDC *pdc);
void leftClick();
void rightClick();
CPoint getLocation() { return location; }
CRect getRect() { return rect; }
int getSize() { return size; }
void reset(); // this will remove ships, and shots from the board.
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// main application
class BSApp : public CWinApp {
public:
virtual BOOL InitInstance();
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// the game!
class battleshit : public CFrameWnd {
public:
battleshit();
protected:
BOARD *player, *computer;
CMenu menu;
virtual void PostNcDestroy();
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnFileExit();
afx_msg void OnGameReset();
afx_msg void OnHelpContents();
afx_msg void OnHelpAbout();
DECLARE_MESSAGE_MAP();
};
//////////////////////////////////////////////////////////////////////////////////
// battleshit.cpp
//////////////////////////////////////////////////////////////////////////////////
#include <afxwin.h>
#include "battleshit.h"
BSApp battleshitApp;
//////////////////////////////////////////////////////////////////////////////////////////////////
// battleshitApp member functions //
//////////////////////////////////////////////////////////////////////////////////////////////////
BOOL BSApp::InitInstance() {
m_pMainWnd = new battleshit;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
} // InitInstance();
//////////////////////////////////////////////////////////////////////////////////////////////////
// battleshit member functions //
//////////////////////////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(battleshit, CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_COMMAND(100, OnFileExit)
ON_COMMAND(200, OnGameReset)
ON_COMMAND(500, OnHelpContents)
ON_COMMAND(501, OnHelpAbout)
END_MESSAGE_MAP()
////////////////////
// Initialization //
////////////////////
battleshit::battleshit() {
CString strWndClass = AfxRegisterWndClass(
CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_ARROW),
(HBRUSH) ::GetStockObject(WHITE_BRUSH),
AfxGetApp()->LoadStandardIcon(IDI_WINLOGO)
);
CreateEx(0, strWndClass, _T("Battleshit"),
WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, NULL);
CRect rect(0, 0, 400, 552);
CalcWindowRect(&rect);
SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
CPoint boardLoc(40, 50);
player = new BOARD("You sail here...", boardLoc, 10);
boardLoc.y += 250;
computer = new BOARD("You shoot here...", boardLoc, 10);
menu.CreateMenu();
CMenu popup;
popup.CreatePopupMenu();
popup.AppendMenu(MF_STRING, 100, "E&xit");
menu.AppendMenu(MF_POPUP, (UINT)popup.Detach(), "&File");
popup.CreatePopupMenu();
popup.AppendMenu(MF_STRING, 200, "&Reset");
menu.AppendMenu(MF_POPUP, (UINT)popup.Detach(), "&Game");
popup.CreatePopupMenu();
popup.AppendMenu(MF_STRING, 500, "&Contents\tF1");
popup.AppendMenu(MF_STRING, 501, "&About");
menu.AppendMenu(MF_POPUP, (UINT)popup.Detach(), "&Help");
SetMenu(&menu);
menu.Detach();
} // battleshit();
void battleshit::PostNcDestroy() {
DestroyMenu(menu);
delete this;
} // PostNcDestroy();
//////////////////
// Painting //
//////////////////
void battleshit::OnPaint() {
CPaintDC dc(this);
CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 150));
CBrush brush;
brush.CreateSolidBrush(RGB(0, 0, 200));
dc.SelectObject(&pen);
dc.SelectObject(&brush);
dc.Rectangle(0, 0, 400, 552);
player->draw(&dc);
computer->draw(&dc);
} // OnPaint();
//////////////////
// Mouse clicks //
//////////////////
void battleshit::OnLButtonDown(UINT nFlags, CPoint point) {
} // OnLButtonDown();
void battleshit::OnRButtonDown(UINT nFlags, CPoint point) {
// check if a ship is selected, if so, rotate it.
for (int i = 0; i < 5; i++) {
if (player->ships[i].isSelected()) {
player->ships[i].rotate();
}
}
} // OnRButtonDown();
////////////////////
// Mouse movement // LOOK HERE - THIS IS WHERE MY PROBLEM IS!!!
////////////////////
void battleshit::OnMouseMove(UINT nFlags, CPoint point) {
// check if mouse is 'over' a cell in the PLAYER and COMPUTER board.
// if so, hilite the cell.
// before hiliting, tho, make sure all other cells are not hilited.
for (int y = 0; y < player->getSize(); y++) {
for (int x = 0; x < player->getSize(); x++) {
if (player->cells[x][y].isHilited()) {
player->cells[x][y].unHilite();
InvalidateRect(player->cells[x][y].getRect(), false);
}
if (player->cells[x][y].pointInside(point)) {
player->cells[x][y].hilite();
InvalidateRect(player->cells[x][y].getRect(), false);
}
}
}
for (y = 0; y < computer->getSize(); y++) {
for (int x = 0; x < computer->getSize(); x++) {
if (computer->cells[x][y].isHilited()) {
computer->cells[x][y].unHilite();
InvalidateRect(computer->cells[x][y].getRect(), false);
}
if (computer->cells[x][y].pointInside(point)) {
computer->cells[x][y].hilite();
InvalidateRect(computer->cells[x][y].getRect(), false);
}
}
}
// then, check if mouse is 'over' a ship. if so, hilite the ship.
for (int i = 0; i < 5; i++) {
if (player->ships[i].isHilited()) {
player->ships[i].unHilite();
InvalidateRect(player->ships[i].getRect(), false);
}
if (player->ships[i].pointInside(point)) {
player->ships[i].hilite();
InvalidateRect(player->ships[i].getRect(), false);
}
}
for (i = 0; i < 5; i++) {
if (computer->ships[i].isHilited()) {
computer->ships[i].unHilite();
InvalidateRect(computer->ships[i].getRect(), false);
}
if (computer->ships[i].pointInside(point)) {
computer->ships[i].hilite();
InvalidateRect(computer->ships[i].getRect(), false);
}
}
} // OnMouseMove();
////////////////////
// Menu events //
////////////////////
afx_msg void battleshit::OnFileExit() {
SendMessage(WM_CLOSE);
}
afx_msg void battleshit::OnGameReset() {
MessageBox(_T("Coming soon..."));
}
afx_msg void battleshit::OnHelpContents() {
MessageBox(_T("More help coming soon..."));
}
afx_msg void battleshit::OnHelpAbout() {
MessageBox(_T("Completed: <no eta,="" as="" yet="">\nWritten by: Jarett Lloyd\nLanguage: VS v6.0, C++, MFC\n\nHomePage: http://jamroll.dyndns.org/"), _T("About Battleshit"));
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
CELL::CELL() {
location.x = 0;
location.y = 0;
rect.SetRect(0, 0, 0, 0);
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
hiliter.CreatePen(PS_SOLID, 1, RGB(255, 255, 0));
cellBrush.CreateSolidBrush(RGB(0, 200, 200));
pegBrush.CreateSolidBrush(RGB(0, 160, 160));
hilited = false;
occupied = false;
shot = false;
}
void CELL::setLocation(CPoint point) {
location = point;
}
void CELL::setLocation(int x, int y) {
location.x = x;
location.y = y;
}
void CELL::setRect(CRect r) {
rect = r;
}
void CELL::setRect(int x, int y, int w, int h) {
rect.left = x;
rect.top = y;
rect.right = w;
rect.bottom = h;
}
void CELL::draw(CPaintDC *pdc) {
if (hilited)
pdc->SelectObject(&hiliter); else
pdc->SelectObject(&pen);
pdc->SelectObject(&cellBrush);
pdc->Rectangle(rect);
CRect circle = rect;
circle.left += 5;
circle.top += 5;
circle.right -= 5;
circle.bottom -= 5;
pdc->SelectObject(&pen);
pdc->SelectObject(&pegBrush);
pdc->Ellipse(circle);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
SHIP::SHIP() {
location.x = 0;
location.y = 0;
rect.SetRect(0, 0, 0, 0);
displayed = true;
hilited = false;
size = 2;
vertical = false;
for (int i = 0; i < 5; i++) {
cells[i].hide();
}
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
hiliter.CreatePen(PS_SOLID, 1, RGB(255, 255, 0));
shipBrush.CreateSolidBrush(RGB(200, 200, 200));
pegBrush.CreateSolidBrush(RGB(160, 160, 160));
sunkBrush.CreateSolidBrush(RGB(160, 0, 0));
}
void SHIP::draw(CPaintDC *pdc) {
if (hilited)
pdc->SelectObject(&hiliter); else
pdc->SelectObject(&pen);
if (sunk())
pdc->SelectObject(&sunkBrush); else
pdc->SelectObject(&shipBrush);
if (size != 5) {
pdc->Rectangle(rect);
} else {
pdc->Rectangle(rect);
if (hilited)
pdc->FloodFill(location.x + (CELLSIZE / 2), location.y + (CELLSIZE / 2), RGB(0, 255, 255)); else
pdc->FloodFill(location.x + (CELLSIZE / 2), location.y + (CELLSIZE / 2), RGB(0, 0, 0));
if (vertical) {
} else {
}
}
pdc->SelectObject(&pegBrush);
for (int c = 0; c < size; c++) {
pdc->SelectObject(&pen);
pdc->SelectObject(&pegBrush);
}
}
void SHIP::setShip(int x, int y, int sz, bool vert) {
if (sz < 2) sz = 2;
if (sz > 5) sz = 5;
size = sz;
vertical = vert;
location.x = x;
location.y = y;
rect.left = x;
rect.top = y;
if (vertical) {
rect.right = x + 20;
rect.bottom = y + (size * (CELLSIZE + CELLSPACING));
} else {
rect.right = x + (size * (CELLSIZE + CELLSPACING));
rect.bottom = y + 20;
}
for (int i = 0; i < size; i++) {
cells[i].display();
int px, py, pw, ph;
if (vertical) {
px = x;
py = y + (i * (CELLSIZE + CELLSPACING));
pw = px + 20;
ph = py + 20;
} else {
px = x + (i * (CELLSIZE + CELLSPACING));
py = y;
pw = px + 20;
ph = py + 20;
}
cells[i].setRect(px, py, pw, ph);
}
}
bool SHIP::sunk() {
for (int i = 0; i < size; i++) {
if (cells[i].isShot() == false) return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
BOARD::BOARD(char *title, CPoint point, int sz = 10) {
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
boardBrush.CreateSolidBrush(RGB(0, 0, 240));
location = point;
sz = 10;
size = sz;
rect.left = point.x - 5;
rect.top = point.y - 5;
rect.right = (point.x + ((CELLSIZE + CELLSPACING) * sz)) + 5;
rect.bottom = (point.y + ((CELLSIZE + CELLSPACING) * sz)) + 5;
int cx = point.x,
cy = point.y,
cw = cx + CELLSIZE,
ch = cy + CELLSIZE;
for (int y = 0; y < sz; y++) {
for (int x = 0; x < sz; x++) {
cells[x][y].setRect(cx, cy, cw, ch);
cx += CELLSIZE + CELLSPACING;
cw = cx + CELLSIZE;
}
cx = point.x;
cy += CELLSIZE + CELLSPACING;
cw = cx + CELLSIZE;
ch = cy + CELLSIZE;
}
bool v = false;
for (int ship = 0; ship < 5; ship++) {
int sz = 2;
switch (ship) {
case 0: sz = 2; break;
case 1:
case 2: sz = 3; break;
case 3: sz = 4; break;
case 4: sz = 5; break;
default: sz = 2; break;
}
if (v)
ships[ship].setShip(rect.right + CELLSIZE, point.y, sz, true); else
ships[ship].setShip(rect.right + CELLSIZE, point.y + (ship * (CELLSIZE + CELLSPACING)), sz, false);
}
this->title = title;
}
void BOARD::draw(CPaintDC *pdc) {
pdc->SelectObject(&pen);
pdc->SelectObject(&boardBrush);
pdc->Rectangle(rect);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
cells[x][y].draw(pdc);
}
}
for (int ship = 0; ship < 5; ship++) {
ships[ship].draw(pdc);
}
CRect tRect, sRect;
tRect.left = rect.left - (CELLSIZE + CELLSPACING);
tRect.top = rect.top - (CELLSIZE + CELLSPACING);
tRect.right = rect.left + 300;
tRect.bottom = rect.top + CELLSIZE;
sRect = tRect;
sRect.left += 2;
sRect.top += 2;
pdc->SetTextColor(RGB(0, 0, 0));
pdc->SetBkMode(TRANSPARENT);
pdc->DrawText(_T(title), -1, sRect, DT_SINGLELINE);
pdc->SetTextColor(RGB(255, 255, 0));
pdc->DrawText(_T(title), -1, tRect, DT_SINGLELINE);
}
/////////////////////////////////////////////////////////////////////////////
I don't want the flicker!!!
At first, I thot just changing the data in the CELL and SHIP objects would do the trick. But no, that doesn't work! Of course it doesn't - it's Microsoft - he can't make anything easy!!!! Now, I know for a fact the flicker is caused by InvalidateRect(...) - is there a way around this problem, or do I just put up with it?
Anyways, if yer confused, take a look at the DRAW member functions of the CELL and SHIP objects and the OnPaint and OnMouseMove member functions of the 'battleshit' object. Maybe I should just bury my head up my backside and forget this whole endeavor, but I don't relish that idea - I want to be successful; so I beg for your kind assistance.
TY in advance, JamRoll
PS: I don't care what you do to my code. use it, delete it, or serve it for dinner. If it isn't real good, let me know how I can improve it - I'm always trying to create code that is readable, and friendly!
---
jamroll@telus.net
http://jamroll.dyndns.org/
|
|
|
|
|
You need to use a memory DC. Keith Rule set the lead with this. There are a few articles here on CP re. memory dc's including: "Further discussions on flicker free drawing" http://www.codeproject.com/vcpp/gdiplus/what_is_a_basename_.asp[^]
Some tips. When you post code use the code and pre buttons in the Formatting bar below the message area. Also the < and > buttons. Show just the code that is of interest, not a huge slab which no body will read.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Ummm... that's an awful lot of code to look through.
You might want to consider only posting the relevant pieces of code in the future. I'd doubt if anyone would read through that much.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
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!
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 />
}
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 />
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!!!
anyways, thanx for yer help guys! It really is appreciated, and please please forgive my previous LONG post...
ciao for now! JamRoll...
JamRoll@telus.net
http://jamroll.dyndns.org/
|
|
|
|
|
JamRoll wrote:
One fella sed ..."You need to use a memory DC" - a what???
Using a memory device context basically means that you do all your drawing to a bitmap held in memory, then at the end draw it to the screen with a BitBlt() call. Then whenever you redraw the window, don't erase anything (override OnEraseBkgnd() and do nothing) and just draw the new image over the top. That will give no flicker.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I see...can ya point me in the direction of a simple example of how to use a memDC? I found a thingy called CMemDC.h, but that's pretty intense stuff...i'm still mainly a beginner here...
ty again.
JamRoll
jamroll@telus.net
http://jamroll.dyndns.org/
|
|
|
|
|