|
Hello,
Well, I have created a custom MFC control that derives from CWnd. I have done some work to add double buffering, but now i have a problem. My application sucks up 100% of the CPU.
I have it narrowed down to one line.
void CGameArea::OnPaint()<br />
{<br />
mPlayer->Draw();<br />
<br />
CRect r;<br />
GetClientRect(&r);<br />
<br />
CDC *dc = GetDC();<br />
dc->BitBlt(r.left,r.top,r.right-r.left,r.bottom-r.top,&mBackgroundDC,0,0,SRCCOPY);<br />
ReleaseDC(dc);<br />
}
I am currently not calling the base CWnd OnPaint function because I am doing all the painting myself. Somehow, this is causing the problem.
If I uncomment the base class OnPaint call, my CPU usage goes back to normal, but I get a lot of flicker.
Any idea why NOT calling the CWnd OnPaint would cause 100% CPU usage??
Thanks ahead of time for any help.
-Kevin
-- modified at 8:53 Wednesday 18th July, 2007
|
|
|
|
|
If you don't validate the invalid region of the window then you will continue to receive WM_PAINT
messages until you do so Not good!
This should do it:
::ValidateRect(*this, NULL);
or use a CPaintDC instead of a CDC
//CDC *dc = GetDC();
CPaintDC dc(this);
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
Holy crap, you're the man. You know, I almost tried switching to CPaintDC, but kept telling myself it wouldn't matter.
It all works now. Thanks.
|
|
|
|
|
kalden wrote: mPlayer->Draw();
In addition to what Mark said, I also doubt how you took the DC in the mPlayer->Draw() function;( I am not sure what exactly that draw function does). I suggest you to pass the CPaintDC object to that function and do all the drawing in that DC.
|
|
|
|
|
I am passing a memory DC to a game DLL at initialization. That DLL has the mPlayer->Draw() code and uses GDI+ to draw to the memory DC. The memory DC is then copied to the control DC using Bitblt.
I know there are potential problems with this if the window resizes, but I am not worrying about that at the moment.
|
|
|
|
|
So you stil have problem even after changing the CPaintDC? (Comment out the statement ReleaseDC(dc); also )
|
|
|
|
|
No, it resolved the issue. See my response to Mark's post.
Thanks for your input!
|
|
|
|
|
ho I didn't noticed.
|
|
|
|
|
I am a novice programmer and have been trying to implement a virtual grid control for a tool I am building. The source files I am dealing with are very large binary files and I was told that I need to turn on the virtual mode of the CGridCtrl due to the size of the source files. I was also told that I probably need to use what is called a callback function or OnNotify.
I do have a non-virtual grid control up and running and I am already parsing and displaying data via a worker thread up to a finite number of columns and rows. The moment I turn on virtual mode, the box where my grid should be immediately pops up shows absolutely no cells. It's as if the source file was never even parsed.
I do understand that a virtual grid does not have actual cells defined or something to this effect. This is what I am observing now. I am completely clueless as to how things are done differently when it comes to actually adding data to a virtual cell.
If I must use OnNotify or a callback function, I have been struggling on trying to find useful information on either of these. I do not know exactly what they do or how to use them.
If this helps, I am using VS.NET 2003. Any help would be greatly appreciated.
|
|
|
|
|
Stuck At Zero wrote: If I must use OnNotify or a callback function, I have been struggling on trying to find useful information on either of these. I do not know exactly what they do or how to use them.
Usually they hide that information in the documentation[^]
CWnd::OnNotify The framework calls this member function to inform the parent window of a control that an event has occurred in the control or that the control requires some kind of information.
more[^]
Those little blue underlined parts are called "links". You place your mouse cursor over them and click the "left button"... unless you have a left-handed mouse then you click the "right button".
|
|
|
|
|
Thanks Led. I have an OnNotify function in my code, but I don't know what to do with it. Part of that problem is my confusion over what I need to inside of it as well as feed it. My root problem is the virtual grid. I can turn it on, but after that, I do not know how to add data.
Once I can get that going, I guess I can tackle the OnNotify to try and get the cells to actually display in Virtual mode. For now, I don't even know what to feed an OnNotify at least from glossing over what you referred me to, nor do I know what to do inside of an OnNotify function to get the desired effect.
I also noted that some of the info you pointed me too is VB. I forgot to mention I'm using Visual C++. Sorry for that oversight on my part.
Thanks for the tip on how a hyperlink works.
|
|
|
|
|
Stuck At Zero wrote: For now, I don't even know what to feed an OnNotify
That is specific to each control/message combination. You have to refer to the documentation for the specific control to discover that. In your case it is the CGridControl yes? I haven't worked with it for a few years but you should find lot's of information here on CodeProject about it. Did you look through the CodeProject Articles?
|
|
|
|
|
I have tried looking at the GridControl v2.26 (if I recall correctly), but it's very general information. It's great if I've had experience on CGridControl. It assumes I know what to do on the Callback function.
The other problem I have ran into is that it seems CGridCtrl has been ditched in favor of CListCtrl or something like that in other searches I have done via Google / MSDN.
If there is a CGridCtrl tutorial that would be appropriate for my situation, I'm more than happy to check it out. I have not been successful in finding what I need in the articles. I'm hoping that someone in the forums knows of a great site that I cannot find via simply googling. If I can find a "Stumble Upon" nudge in the direction of an good site, it would be appreciated.
|
|
|
|
|
I went back and queried for CGridCtrl and the closest thing I get that would be of any help is Chris Maunder's MFC Grid Control 2.26. Because I'm such a newb, I do not totally understand all of the details. I do google those, but nothing that cements everything together... I've got a warm fuzzy.
So what I did just now is simply copied and pasted Chris' GridCallback and OnNotify functions one at a time and rebuilt my solution. There is no change. While my worker thread is parsing through the source file, I have it periodically GetCallback after it has been registered (which was after I made the grid into a virtual grid).
The other concept I am struggling with is the idea of adding data to a cell that does not exist. With a regular grid control, it was really straightforward. Here, I do not know what I am not doing right.
Is there an actual article on CodeProject that goes into more detail into how to implement a Virtual Grid? Maybe Chris has spelled it out, but if it's "obvious", it's not clicking due to my lack of knowledge of all things MFC.
|
|
|
|
|
Chris Maunders MFC Grid Control is the only CGridCtrl I am aware of. If that is NOT what you are using I don't know where you can find information. If it is Chris's control then the Virtual mode operation is spelled out in the Articl[^]e for the control here on CodeProject.
Stuck At Zero wrote: Because I'm such a newb, I do not totally understand all of the details.
Any documentation for a control or an API or samples are not going to be trying to help you understand fundamental concepts. They are going to assume you already understand those fundamental concepts because you shouldn't even be trying to do "whatever" unless you already have programming fundamentals required to do it. Which leads to the obvious question, if you are a novice as you state, a newb, why are working on a project that is above your knowledge level?
|
|
|
|
|
I am struggling to see where virtual mode implementation is spelled out. The link you sent me is the same I've been looking at. I see descriptions of what each function does and I see code examples of OnNotify and CallBack. There's no explanation I see that explains exactly how data is added to a virtual cell other than saying OnNotify and CallBack are needed for this operation.
What I have at the moment is a working non-virtual grid. I need to make it virtual for the reasons Chris explained as to why one is needed. I can populate this non-virtual grid with data. But when I flip the switch for Virtual, poof! Nothing.
As for why I'm trying to implement a virtual grid, it's because I was told that this would be needed in order to accomplish listing lots of data on a grid control. No one around me has tried this feature so I'm left on my own to figure it out.
If I am a novice as I state? You sound like you don't believe me.
I get the idea of what Chris is trying to convey, but I don't understand the implementation.
|
|
|
|
|
Stuck At Zero wrote: There's no explanation I see that explains exactly how data is added to a virtual cell
Are you blind? From the article sample code in the "Virtual Mode" section:
pDispInfo->item.strText.Format(_T("Message %d,%d") Stuck At Zero wrote:No one around me has tried this feature
No one in your shop knows how callbacks or OnNotify work or knows how to read and understand the sample code in the article? Is this a school project?
|
|
|
|
|
I suppose I am blind but I still don't totally understand that line. Chris says "If no callback function is specified then the grid will send a GVN_GETDISPINFO message to it's parent" This led me to believe this works under the hood, or so I thought.
I have come to CodeProject because there seems to be little information out there that can explain things more for the novice. I'm not asking to be spoon fed, but I think this is your impression. I am truly sorry if the obvious for you is not obvious for me. I did say I am a novice and I am trying to do what I was told to implement.
I did not say people at my place of work did not know how OnNotify or Callbacks work. I said no one has ever done a Virtual Grid before so they do not know. I really wished this was a school project. At least I could go straight to the teacher and ask the dumb questions.
From what you're telling me, this one line will magically populate all my cells with ease. As I explained before, I have copied this into my code and I get no change in behavior. I assumed from the quote I provided above that this all worked "under the hood". Prior to trying to add this feature, I have never heard of OnNotify or Callback functions. What I still do not know is how a particular virtual cell gets the specific bit of data it needs.
Also, I do not know if this could be a problem, but my solution is based on CFormView.
|
|
|
|
|
Stuck At Zero wrote: What I still do not know is how a particular virtual cell gets the specific bit of data it needs.
The GV_DISPINFO.item member "is" the cell the OnNotify or Callback, which ever one you are using, is called for "each cell". You have the responsibility of figuring out what data needs to go into that cell.
Stuck At Zero wrote:
I suppose I am blind but I still don't totally understand that line.
It just sets the text value of the cell . I don't know how more clear that can be.
Stuck At Zero wrote: Chris says "If no callback function is specified then the grid will send a GVN_GETDISPINFO message to it's parent" This led me to believe this works under the hood, or so I thought.
Yes that behavior is "internal" to the CGridCtrl. When you "turn on" Virtual Mode, the control will send OnNotify messages if no Callback has been registered.
Stuck At Zero wrote: I'm not asking to be spoon fed, but I think this is your impression. I am truly sorry if the obvious for you is not obvious for me.
No that is not my point at all. My point is, and we see it here at CodeProject all the time, is that beginners should NOT be developing production code. They are just not capable and this instance with you is yet another example. People should actually learn how to develop software before working on production projects. No one is born knowing what is required to develop software, it is not someones fault that they don't know, however it is someone's fault, I don't know who, that a person that is not qualified to work on production projects is.
|
|
|
|
|
Okay, I will try and figure out how get what I need into the GV_DISPINFO.item member to absorb what I already pass to cells in the non-virtual mode. How do I set item.row and item.col for pDispInfo?
Out of frustration I tried using Callback and OnNotify at the same time. It seems I never have to call OnNotify because MSDN says "The framework calls this member function to inform the parent window of a control that an event has occurred in the control or that the control requires some kind of information." Did I understand this correctly or must I actually call on OnNotify?
Understood on the beginners comment and I don't disagree. They pay my bills so I'm willing to learn. It's probably not the most efficient way of doing things but it's the OJT or self-discovery mentality. It works sometimes. Other times not. This is one of those other times for me.
For now my work is restricted to MFC stuff and unmanaged code which I'm not so sure the importance of that is, but learn I must.
Thanks for the help. This may be the nudge in the right direction I needed. Is there a really good MFC book out there you'd recommend for a newb like me?
|
|
|
|
|
Stuck At Zero wrote: How do I set item.row and item.col for pDispInfo?
No, you "get" the column and row, that's what you use to know what information goes into that specific cell. Also note the ODCACHEHINT message which will give you the entire range of cells that are going to be asked for in the subsequent GVN_GETDISPINFO messages. The idea there is that you would query a database or read a file for all the cell data required and cache it for use in the subsequent GETDISPINFO messages rather than doing all that work for each cells message.
Stuck At Zero wrote: Is there a really good MFC book out there you'd recommend for a newb like me?
Oh i wouldn't know any longer, I started back in the 90's and there where decent books then. There are tutorials on MSDN and such but issues like callbacks are before MFC, they are basic C concepts and OnNotify is also something you have to understand conceptually. You need, as with all beginners, some basic programming concepts studying.
I started out in school learning how processors and systems worked like how they accesses memory, disks, IO ports, video memory, the stack, jumps, registers etc. Everything else is built on top of that so when you got to a high level language like C, everything just mapped back to those fundamental things so it was relatively easy to understand. It's whole new world now where people start right out with IDEs, drag and drop, and high level languages and then try to learn things going backwards towards the fundamentals after they are already developing production code and run into the issues. You can see how I have no experience with that so it is difficult to advise how to do it that way.
|
|
|
|
|
Stuck At Zero wrote: Did I understand this correctly...
Yes.
Stuck At Zero wrote: ...must I actually call on OnNotify?
No. It's a virtual function that the framework calls. When you respond to the notification from within the OnNotify() method, you are telling the grid control what to display.
Think of it this way. With a non-virtual control, you tell the control what to display and where, and it goes off and does so. With a virtual control, it will tell you that it needs something to display at such-and-such row/column, and it's up to you to provide that. Any clearer?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am inputing from a text file.
Example of text file:
Total 100252 252562 11021
Trial 250 32 8
Attributed to 2526 2500 210
Daily trial 25 13 1
Here is a snippet of the code I am using.
while(input1>>word>>num1>>num2>>num3)
{
if(word == "Total")
{
total1+=num1;
total2+=num2;
total3+=num3;
}
else
{
wordCount[word] += num1; //map of string,int
single[word] += num2; //map of string, int
compound[word] += num3; //map of string int
}
}
I use this but I am trying to figure out how to attack words with spaces...(attributed to & daily to from e.g above) Currently it will only pick up single words such as Trial and the numbers following it. I am trying to read in the entire word 'attributed to' into string word;
Definately a noob to programming so any and all help/suggestions appreciated.
|
|
|
|
|
Hi,
if I have understood what you want... it is just to take every single word limited by spaces and concatenate it to a string for the entire line, as you already make. If every line may have a different number of words... then make it in other way, per letters.
for (int i = 0; char != "\n"; i++) //While not an End of a line
{
if (char == " ") //If it's an empty space
continue;
else
myWord[i] = char;
}
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Not sure if I'm suppose to reply or not but oh well...
Thanks for the help. I looked at it and it gave me another idea. Since I was controlling the format of the input file, I just decided to have a word then '\t' delimiter then num1 tab num2 tab num3 endl
Here's what it looked like codewise:
while(getline(input1, word, '\t')) //reads the first line of input until the first tab delimiter is found
{
input1>>num1>>num2>>num3; //inputs the numbers associated with the word respectively
if (word == "Total") //Total is a separate data set that needs to be kept away from rest of data
{
total1+=num1;
total2+=num2;
total3+=num3;
}
else
{
wordCount[word] += num1; //take the word and if new add it to the maps
single[word] += num2; //otherwise if word already exists just update the count
compound[word] += num3;
}
getline(input1, word, '\n'); //formatting trick so that the endline delimiter wouldn't become new word
}
--------------------------
I'm new to programming and still learning so I am open to any suggestions or comments you or anyone else may have.
Once again thanks.
|
|
|
|