|
Hi,
Thanks for your valuable suggestion.
Actually I am not drawing World Map every time. It is drawn only once but I am drawing small towers on the MainMap in OnTimer() event. There might be atleast 300 to 400 small tower bitmaps which have to be loaded and drawn on the MainMap. I think you got confused. Let me explain you.
1) In OnPaint() I have drawn a MainMap on the Dialog Box.
2) In OnTimer() I am drawing 400 small bitmaps on the Dialog Box which appears like those small towers are on the MainMap.
I think now you got it.
Problem is I have to blit 400 bitmaps every time for 500 milliseconds to get blinking effect.
When my application is running and when ever I see my CPU usage it starts with 29% and when it was drawing 400 small bitmaps suddenly CPU usage goes to 54%.
I think CPU usage is going up because I am blitting 400 small tower bitmap at once.
I want to reduce the CPU usage.
"Make sure all drawing is done in OnPaint" I cannot do this because I have to call invalidate every time from OnTimer() this may increase CPU usage even more(This is what I am thinking but I have to test this and let you know with in few days).
I hope you understood my design. Please help me.
I think instead of blitting every time small bitmaps on the Dialog BOx. I think I will take some CStatic Controls.
and call SetBitmap(HBITMAP) to change the bitmap in those controls and Move these CStatic controls on different locations on Dialog Box. This may not also work because in OnPaint() I am Drawing MainMap this MainMap may overrite on these static controls and these static controls may not be visible.
Suggest me some thing good Idea. Plsssssssss
Thanks & Regards,
Deliver.
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
That is a lot of bitmaps!
You still need to do all the drawing in OnPaint and just invalidate in OnTimer. If you called UpdateWindow after calling InvalidateRect you would still have the same problem.
I thought of some different solutions on the way to work this mourning and it looks like one might work. This works on the assumption that the Towers are all one color or the other, and either they do not move (or rarely do).
1) Create 2 new member bitmaps (CBitmap m_b[2]), the same size as the Word Map.
2) Use BitBlt to copy the World Map to each of them.
3) Then draw all the Towers of one color onto one bitmap and the other color on the other bitmap.
4) Add a int member variable as index for bitmap array (range 0-1).
5) Then in OnTimer, just change the index then invalidate the rect containing the whole World Map.
If for some reason any of the Towers need to move or stop blinking, then you just need to update one or both of the bitmaps (at that time).
That should do the trick, unless I missed something else.
It is better to do one large blit than to do hundreds of small blits.
Good Luck!
INTP
|
|
|
|
|
I have a CList defined in my dialog apps main header file like this (not within the class definition):
static CList<SONGSTRUCT,SONGSTRUCT&> TrackList;
It works fine in the apps main dialog class, but when I try to access it from another dialog class within the same app then it shows an empty list, although it sees it.
I need access to this list from all dialogs within my app without copying it all over the place, how does one go about doing that?
tia,
Rick
|
|
|
|
|
Cpt Rick wrote:
I need access to this list from all dialogs within my app without copying it all over the place, how does one go about doing that?
One way would be to make it a member variable of the CWinApp -derived class. Then whenever it was needed, just use AfxGetApp()->TrackList .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Well, I tried that by moving it here:
class CMyApp : public CWinApp
{
public:
CMyApp();
HICON m_Icon;
static CList<SONGSTRUCT,SONGSTRUCT&> TrackList;
And I get this error:
error C2039: 'TrackList' : is not a member of 'CWinApp'
???
|
|
|
|
|
Firstly, it probably doesn't want to be static.
Secondly, AfxGetApp() returns a CWinApp*. You will need to cast it appropriately, eg
((CMyApp*)AfxGetApp())->TrackList
should do the trick.
Steve S
Developer for hire
|
|
|
|
|
Thanx Steve, that did the trick.
What I don't understand is why it wouldn't work right as a static global???
|
|
|
|
|
? Is it defined globally?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Hello!
I'm currently writing some plugin framework. The plugins are implemented as simple DLLs. The main application has some class A. It passes a pointer to this class to the DLL. The DLL knows the class (it can include the header file of A) and can now perform operations with it.
Now, what happens if the class extends (a developer adds a function or variable for example) and the main application gets recompiled? Will the DLL still be able to access the class?
Of course it cannot know the new functions or variables. But will the old functions still be accessible or are they completely incompatible now?
Thanks in advance and best regards
|
|
|
|
|
I think If your class is not having any virtual functions inside or any other mechanism like COM does...then It will work fine...otherwise it won't
|
|
|
|
|
Provided you don't move the variables around within the baseclass you should maintain ABI (Application Binary Interface), google should be a good starting point for getting information specific for your compiler.
As the previous poster pointed out, one one to do this is to use an approach like that of COM, with interfaces for versioning rather than changing implementations.
If this is for an in house product it's probably not worth worrying about. Recompile everything to be safe if you're not sure. If you're selling it to other developers look for a more robust way of doing this, COM or XCOM.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
In c++ can an abstract base class have member variables apart from virtual functions ?
or
In c++ can an Interface have member variables apart from virtual functions ?
sorry if a stupid question.
thanks for your time
|
|
|
|
|
yes and no - in fact interface is just a nickname for struct . Therefore you can easily add members and non-virtual methods to the interface.
Problem is that then it's no interface anymore.
|
|
|
|
|
Unlike Java and C# these terms tend to have less meaning in C++, where the rules are far more flexible. The language designers of C++ aim was (and still is) 'you don't pay for what you don't use'. and in doing so they discovered many of the potential programmer pitfalls which more modern languages seek to avoid.
The answers to both questions is yes, you can do what you like - although most programmers now follow some general guidelines when preparing these types of classes.
A C++ abstract base class is any class that cannot be instantiated due to having one or more pure virtual functions. Some developers make the choice to flag this in other ways as well by making constructors and/or destructors private.
Standard C++ has no concept of an interface, however java-like interfaces can be implemented in two ways. One is through the use of a class with only virtual functions, the second is an ugly mess of templates which you generally need a code generator to assist with - this was described in a recent article of the C/C++ Users Journal see Heronfront for more information. Interfaces tend to provide a single concrete function (a virtual destructor), whilst avoiding data.
The presence of member variables for classes in these situations can have an impact on a number of factors, mainly to do with language implementation details (class sizes and v-tables). These issues are largely irrelevant, provided you aren't doing weird casts on classes and/or using multiple inheritance.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Hi there
I would like some help with this plz if posible.
I need to write the following class book and it's implementation, this is what i have done.
class book<br />
{<br />
public:<br />
<br />
book(const string title,const author,const char isbn[10]);<br />
<br />
void show_book();<br />
<br />
private:<br />
<br />
const string T;<br />
const string A;<br />
const char I;<br />
<br />
};<br />
Ok,the library class must be able to add books. some other stuff aswell.
class library<br />
{<br />
public:<br />
library()<br />
<br />
void add_book();<br />
void display()const;
<br />
private:<br />
<br />
vector<book *> book_list;<br />
<br />
};
The library class implementation
<br />
void library::add_book()<br />
{<br />
book * new_book = new book("Danger","Mike","102- RT34");<br />
<br />
book_list.push_back(new_book);<br />
}<br />
<br />
void library::display() const<br />
{<br />
<br />
for(int i = 0; i < book_list.size(); i++)<br />
{<br />
cout << book_list[i]->show_book() << "\n";<br />
}<br />
<br />
}<br />
First is there any thing wrong with this code?
Secondly is there a beter way of writing this code?
Thirdly how would i go about adding books at runtime and
iterate thru the vector to find a specific book?
excuse the english, Thanks in advance
I Never said you should like me.I say be yourself, and make a difference
|
|
|
|
|
the code looks ok, except maybe for the display method; the show_book method will do what ? no, it is declared as void , and cout will do nothing for it; or might not compile.
to find a book, you need to compare somthing, when iterating the list, you can compare one it with the search criteria.
for example ( pseudo code )
<br />
CString sCriteriaTitle;<br />
for(int i = 0; i < book_list.size(); i++)<br />
{<br />
if ( sCriteriaTitle.Compare( book_list[i]->get_book_title() ) == 0)<br />
{<br />
bFound = true;<br />
}<br />
}<br />
<br />
}<br />
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
A Class is just a structure. Can youm write a structure with all these elements?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
Once upon a time there was a thread:
UINT CIrisAdqDlg::CaptureImageThread(LPVOID pParam)
{
...
}
And one day I tried to launch it:
void CIrisAdqDlg::OnStart()
{
...
AfxBeginThread(CIrisAdqDlg::CaptureImageThread, this);
...
}
But VC++ didn't want:
...
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
...
I am sure it worked in the past, so I don't know what it's really happening now.
Thanks!
|
|
|
|
|
Hi
This occurs when you use Member functions as the parameter of AfxBeginThread.
Write the Thread function outside the class.
This http://www.codeproject.com/win32/callback_adapter.asp[^] may be of help to you.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Or make the member function static.
If I write code in my sleep, does that make me brilliant, or just a lazy programmer?
My articles
www.stillwaterexpress.com
BlackDice - the programmer formerly known as bdiamond
|
|
|
|
|
Hi, I have a dll that runs as a process via dllHost.
My problem is i need to know when a Windows Shutdown event is being fired. I've never had this problem before because all my apps have a main window and receive this notification. However the dll just keeps working and terminates in an undetermined state.
I can't have the dll called from an app. I have no alternative but to use what i've got.
how can i register to receive a WM_SHUTDOWN event from my dll?
Please don't suggest i change the design of the solution. I'm confined to what i have.
thanks in advance
Carl
|
|
|
|
|
What about a creating an invisible hidden window for just receiving this message (under W2K+ you can use message only windows designed specially for these purposes - see HWND_MESSAGE for details)
|
|
|
|
|
thanks for the comment but firstly this needs to be a solution to all current windows platforms (excluding servers) and secondly i'm sure there must be a way to register for this event, even in a dll. hmmm
Regards
Carl
|
|
|
|
|
Yes instead though create a custom message
In both headers:
#define MY_MESSAGE (WM_USER+22)
Then trap it in defwinpro
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|
I only have one binary, the dll. Hence only one header. I am running the dll as an application, through another process.
|
|
|
|