|
Can someone please clear my confusion about the major function calls related to WM_PAINT and the sequence in which they are called. I want to know when these functions:
OnUpdate
OnInitialUpdate
UpdateAllViews
OnDraw
InvalidateRect
are called - whether before or after WM_PAINT, and in what sequence.
I've read that InvalidatRect just adds the rectangle to the update region, but it seems to me that a call to it also causes the window to be repainted immediately, or in ther words, a WM_PAINT is passed. Is that true?
It would be great if someone can explain me the MFC drawing sequence and procedure in detail. U see, i have just begun with VC and my project is entirely graphics based (OpenGL). So its imperative that i get a good grasp on the drawing mechanism.
Despo for your replys.
Thanks.
|
|
|
|
|
The only virtual methods which are called by the MFC framework are those with OnXXX.
OnInitialUpdate is called after the view is attached to a document but before the view is initially displayed.
OnUpdate is called if you change the document data and call UpdateAllViews. So OnUpdate is called by UpdateAllViews. The default implemenation is also called by OnInitialUpdate and it invalidates the entire client area and so it will be repainted if the next WM_PAINT messages is received.
UpdateAllViews should be called if you changed the documents data and so the view of the document must be marked invalid so that it is repainted in the next WM_PAINT message! So it forces the views of the document to display the changed data.
As I said above UpdateAllViews calls OnUpdate of all views which are attached to this document (except the sender view).
Note: you can prevent that OnUpdate invalidates the whole client area, if you overwrite UpdateAllViews/OnUpdate and pass a hint object with the information which part of the view must be updated in order to refelect the document changes!
InvalidateRect adds the given rectangle to the windows update region. The update region will be repainted if the next WM_PAINT message is received. It is used by OnUpdate to invalidate the given region of the view.
OnDraw will be called by the MFC framework in order to display the document. So OnDraw is called if a WM_PAINT message has been received.
|
|
|
|
|
OnUpdate and OnInitialUpdate are called by the framework. OnInitialUpdate is called when the view is first created, and can be used to perform some initial setup before it then calls OnUpdate.
OnUpdate is called by the framework in response to a call to CDocument::UpdateAllViews. You normally call UpdateAllViews if you've modified something in the document. This allows multiple views of the same document to be updated (maybe you have a CAD drawing, with different view windows showing different viewpoints of the design). UpdateAllViews calls OnUpdate for all views attached to the document, apart from the one passed in the pSender parameter.
CWnd::InvalidateRect is a simple Windows wrapper function (wrapping ::InvalidateRect) which tells Windows that a certain area of the window needs to be redrawn. When your thread's message queue is empty (apart from timer messages, which are the lowest priority), Windows posts a WM_PAINT message for each window that has an invalid region. MFC handles this in CView::OnPaint by retrieving the window's DC, calling OnPrepareDC to allow it to be set up correctly, then calling OnDraw().
OnPrepareDC doesn't do anything in CView's implementation; CScrollView overrides it to set up the scroll extents correctly. This allows you to use a single co-ordinate system whatever the current position of the scroll bars.
OnDraw() is also called when you use MFC's built-in printing support. This enables you to support both drawing to the screen and to a printer using the same code.
Most of the functions you're discussing are implemented in VIEWCORE.CPP. If you haven't installed the MFC source code, you may find it helpful to do so. The book MFC Internals by George Shepherd and Scot Wingo is still a good reference, despite being 8 years old; the core of MFC has barely changed since version 4.0.
|
|
|
|
|
Hi,
Iam Using VC++, Iam planning to capture the screen, saving into .BMP format and iam able to do this.
My question is
I want to capture the screen whenever the changes happen on my desktop.
Can any one tell me how do i know whether the screen changed or not. i mean through which event we can find it out.
Thanks in Advance.
Regards
Santosh.K
|
|
|
|
|
If you wish to capture the screen when even a single pixel has changed you'll have an impossible time finding an event which triggers that. Suppose you have a movie running on the screen. The screen changed but probably not a single message is called. In this case your best bet would be to keep capturing the screen on a certain interval and comparing the bitmaps in memory. This would be really slowing down your system though. If you don't mind much about movies and the like and wish to recapture only when a window for instance resizes or gets created you could make a global windows hook. A CBT hook would be quite good for this purpose I guess.
From the MSDN:
The system calls this function before activating, creating, destroying, minimizing, maximizing, moving, or sizing a window; before completing a system command; before removing a mouse or keyboard event from the system message queue; before setting the keyboard focus; or before synchronizing with the system message queue.
|
|
|
|
|
The best thing you can do in this case I guess is to capture the screen at a static interval. You can do three things (which I can think of atleast ):
1) Just capture the screen at a static interval and write it to the disk as bitmap
2) Capture the screen at a static interval and write it to the disk as a compressed image
3) Capture the screen and compare it to the last to see if it changed and write it to the disk if it didn't (this means that you'll also have to keep a log on how long the same image should be shown)
Depending on the desired framerate and quality of the final movie (and ofcourse speed of the machine) I can't do nothing but suggest you to find the best and fastest way for yourself. They all have disadvantages, the first two being a high I/O and the second a lot of CPU required. The third, well I don't know about performance in the third. It seems like it could be pretty fast compared to the other two, but it's just a hunch
I think though that if you want the best performance this should be done in assembly, especially with method 2 and 3.
And I was just thinking. Suppose you have a resolution of 1024x768, 16 bits and you wish to have a framerate of 24. This means that with method 1 you'll have to write about 40MB/s to the harddisk. It's going to have a very hard time doing that and the harddisk will need quite some space too If I were you I'd try my last suggestion, it sure seems like the most fun suggestion as well
|
|
|
|
|
Hi Mr.GopalaKrishna,
Iam Using VC++, Iam planning to capture the screen, saving into .BMP format and iam able to do this.
My question is
I want to capture the screen whenever the changes happen on my desktop.
Can any one tell me how do i know whether the screen changed or not. i mean through which event we can find it out.
Thanks in Advance.
Regards
Santosh.K
|
|
|
|
|
This must be easy i dont know how to do it.
I have a dialog box and a button on the screen,
i want to move th button from one place to another under certain conditon.
Moveing the window is fine no prob.
but i want to do it this way.
first get the current position of the button.
then move the button relative to this position.
I tried GetClientRect and GetWindowRect, but i am not able to use it properly.(may be i am doing it allwrong)
basiaclly i am not able to get the current posion of the button on the dialot.
how do i do that.
thanx.
Toughest Steel Comes From Hottest Furnance
|
|
|
|
|
MoveWindow should help you. You will need to pass the x/y pos or rect details in so getting the rect before you start would help.
BD
|
|
|
|
|
GetWindowRect(hButton,...) will give the position of the button relative to the top left of the screen.
GetWindowRect(hDlg,...) will give the position of the dialog relative to the top of the screen.
Simple maths gives you the position of the button relative to the dialog, or you can use ScreenToClient(hDlg, buttonrect) to convert the button position.
Steve S
|
|
|
|
|
Anyone know if or how I can format cells and skip rows writing out to a spreadsheet (MS EXCEL).
Ger
|
|
|
|
|
|
Check out the MSDN article Q178749.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Any examples of how I could add filtering to a ListCtrl Column? The only example I can find on the site draws from a 'dead' link.
Ger
|
|
|
|
|
You would filter at the time of calling InsertItem() and/or SetItemText() .
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hi,
my program making request to the server on loop first time the request works correctly. rest of the loop the data is read from cache. how to avoid this problem. i need to load each and every time from server. any one help to me.
thanks in advance.
Have A Nice Day!
Murali.M
|
|
|
|
|
Does anyone know how to overwrite / delete a particular line of data from a file?
eg.
First, First <--- Line 1
Second, Second <--- Line 2
Third, Third <--- Line 3
If I would like to overwrite / delete Line 2 how should I go about retriving the particular line and overwrite or delete it ?
Thanks in advance
|
|
|
|
|
Well, file manipulation is buffer manipulation.
You will have to rewrite the file. Any editor does it that way: load the file, manipulate it, write it to disk again. Some editors (saving physical memory) write to a temporary file first, delete the old and rename the new file.
As I am not that familiar with (V)C++, I would suggest
fgets to retrieve the lines. Then store them in a linked list and manipulate that list until it meets your requirements. Then write it back to disk.
Open file (read-only)
begin loop
Read line from file
store line (linked list, dynamic array... whatever you can do)
loop until eof
close file
manipulate list
open file (same file, do not append data but overwrite instead)
begin loop
write line to file from list
delete line from list
loop until last element
close file
Thats what I would do
Cheers
Sebastian
|
|
|
|
|
If you want to delete a line(or anything else) from a file
you must rewrite the hole file.
I would write in another file(temporary), then delete the initial file, and then rename the temporary file with the
name of initial file.
But, If you want to overwrite data in a binary file, you
must open the file with write acces, then go to the begining of data you want to overwrite and then write
the new data (the size of the new data must be the same
as the size of the old data).
If you want an easy C++ class that uses Win32 API file access functions for creating,reading and writing binary
files send me an e-mail.;)
iCounter
|
|
|
|
|
Is Visual C++.Net ANSI C compliant?
|
|
|
|
|
The short answer is no, but 7.1 is very close.
What they are missing out on is relatively minor at the moment - specifically separate compilation of templates using export. Probably a better question to ask is 'is there another compiler out there better?', and there are some. Intel's compiler is an optimizing compiler, and comeau seems to travel ahead of the pack feature wise. Some of the major compilers are compared in the boost regression tests , although this isn't an entirely fair comparison because of compiler based configuration files and developer mistakes it gives a rough indication of how compilers perform in real world situations.
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 you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Yes, but it allows a lot of extensions. Compile with the /TC (Compile as C) and /Za (Disable Language Extensions) options to ensure that you're compiling as C rather than C++, and only using ANSI features.
(The other poster is talking about C++ conformance, which is a different thing.)
|
|
|
|
|
Hi all,
I've written a small program and I want to be able to run it on many machines by carrying the executable around on a floppy. However, when I try to run it on another machine I get an error saying that MSVCP60D.dll can't be found. Is there a way to link that dll so that the entire program is in the exe so I only need to copy 1 file?
Thanks in advance.
|
|
|
|
|
|
I am porting a XML based project from VC6.0 to VC7.0. But, 7.0 compiler shows 'ambigous symbol' error. How can I solve it.
|
|
|
|