|
lucy wrote:
I overwrite BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
You also have a view though, right? How about implementing OnEraseBkgnd() for the view?
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
Ah I got it. At first I thought the WM_ERASEBKGND can only be handled by the frameWnd since I couldn't find it in classWizard for the view. After reading your advice, I overwrite the view's WindowProc and check for this message, then overwrite it based on my program requirement. now the bitmap is shown perfectly.
Thank both of you a lot!
|
|
|
|
|
sorry, one more question:
I am updating the display using a bitmap file at a rate of 10 frames per second in a worker thread, when I need to overwrite the process of WM_ERASEBKGND. At the same time, I want to respond to user event, like file open.
The problem is: if my worker thread is running and the background is not erased, there would be funny things left on the display, like the file open dialog even after the dialog is closed. How do I know the WM_ERASEBKGND is posted by the worker thread and when it is posted by other UI thread so that I can treat it differentely in my view?
Thanks a lot!
|
|
|
|
|
Sorry if i missunderstand your question, but:
You should not be posting WM_ERASEBKGND directly. Use Invalidate() , do nothing in OnEraseBkgnd() , and draw the bitmap in OnPaint(). That way, whenever the frame changes, you'll invalidate and the window will repaint. And, when the window is invalidated for some other reason (window is uncovered, menu disappears, etc.) the window will also repaint correctly.
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
yeah, I think I am doing this. the pseudo code is :
CMainFrame::OnImage()
{
AfxBeginThread(BitmapUpdate, pMyView);
}
UINT BitmapUpdate(LPVOID pParam)
{
m_bImage = true;
while(m_bImage)
{
pMyView->Invalidate();
}
}
CMyView:: OnDraw()
{
}
CMyView::WindowProc(....)
{
if ( message == WM_ERASEBKGND && m_bImage )
return TRUE;
}
but when m_bImage is true, when my bitmap cannot cover the whole client area, background outside my bitmap area will not be updated until I clear m_bImage. What should I do?
|
|
|
|
|
If you know what area the bitmap takes up, just erase the borders around that area before returning on WM_ERASEBKGND . BTW, you should be able to use CMyView::OnEraseBkgnd() instead of CMyView::WindowProc() .
As a side note:
kilowatt has written several very nice articles on these subjects you may want to read; i would especially recommend you read Guide to WIN32 Paint for Intermediates and A Guide to WIN32 Clipping Regions as they are both very relevant to what you are trying to accomplish.
Developers that like shiny objects also dig case mods and scratch-and-sniff stickers. Klaus Probst, The Lounge
|
|
|
|
|
Thank you. I am reading those articles.
|
|
|
|
|
Hello,
I'm a games programmer and I'm writing a level editor using MFC for putting game objects in our levels. I've got an SDI document/view MFC project and I'm using a splitter window to split the framework into a treeview (for the game data) and an OpenGL view (to view the level geometry and visual representation of the game data).
The question I need answering is: at what point after loading data can I fill the Treeview? I need to remove all treeviews items when I load a new set of game data so I was originally doing this in CTreeView::OnInitialUpdate() using TreeCtrl::DeletAllItems(). But when I load my data from CDocument::OnOpenDocument() I want to fill in the data in the view using UpdateAllViews(). OnInitalUpdate() gets called after OnOpenDocument and hence deletes all the data I've added so at what point do I fill in the data in my treeview?
Can anyone explain a good way (or the correct way!) to do this please?
Thanks,
Marc
|
|
|
|
|
Marc Littlemore wrote:
I want to fill in the data in the view using UpdateAllViews().
That seems the right thing to do. In which case, I think you want to update the contents of the tree in your view's OnUpdate() method.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Ravi - yes, that's what I'm currently doing _but_ it calls OnInitalUpdate _after_ I call OnUpdate (via UpdateAllViews() in the document). So what's happening is that I'm filling in my treeview after loading (from OnOpenDocument() in CDocument) and then at some point afterwards it calls OnInitialUpdate() which is where I was removing all previous data.
Is there a specific place which I should initialise my treeview from other than OnInitialUpdate(). If not, how do I get around my problem?
Thanks,
Marc
|
|
|
|
|
Hmmm, a couple of thoughts:
OnInitialUpdate() should not be called automatically when you call UpdateAllViews() . Are you manually calling OnInitialUpdate() ? (If so, you shouldn't.)
- How about removing old data from the tree control in
OnUpdate() (instead of OnInitialUpdate() ) just before you load new data? /ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
OnInitialUpdate is called (according to MSDN) after the view is first attached to the document. This is done via OnUpdate() (with a default hints of 0 for both parameters). I'm not calling it.
I'll try removing the data via OnUpdate(). Sounds like a great idea!
Thanks,
Marc
|
|
|
|
|
Marc Littlemore wrote:
This is done via OnUpdate()...
Not quite! OnInitialUpdate() ends up calling OnUpdate() , not the other way around. OnInitialUpdate() should only contain one-time initialization code. I think things should work properly when you empty the tree control in OnUpdate() .
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Sorry Ravi, my mistake! I read MSDN too quickly and just scanned!
Yes, UpdateAllViews() before loading to remove the items works a treat. Thanks for your help!
Marc
|
|
|
|
|
Hi,
Can nebody tell me how to prevent my application to
run again.. That is. if my application is running
preven another instance
My Application is a Dialog Based Application.
Help..
Sameer
|
|
|
|
|
Search for your application using FindWindow(class, title).
rechi
|
|
|
|
|
Add the following to your application's InitInstance
CreateMutex(NULL,TRUE,_T("SomeMutexName"));
BOOL bAlreadyRunning = (GetLastError() == ERROR_ALREADY_EXISTS);
if (bAlreadyRunning)
return FALSE;
|
|
|
|
|
|
CMemFile Datafile(1024);
CArchive ar(&Datafile,CArchive::store,4096,NULL);
pDoc->Serialize (ar);
I want use these code store the data of a RichEditDoc into a memory file,but I find that these code can't work as I want it to.The DataFile return the right length of the data of RichEditDoc,but all the file data is '0'.
Don't look at me in that way!
|
|
|
|
|
Dont you have to call open on the file before attaching it to the archive?
Roger Allen
Sonork 100.10016
yet to be identified being from the planet Paltinmoriumbanfrettybooter
|
|
|
|
|
the DataFile is a memory file,how can I use Open Function?
Don't look at me in that way!
|
|
|
|
|
OK, I had no experience with CMemFile before. I was comparing your code to what I have seen in the past for serialization. After having read the notes on CMemFile in MSDN it looks like what you are doing is correct. The only thing I can think of is that you may not be accessing the allocated buffer correctly, or you need to flush the archive to commit the changes to the buffer.
Just a couple of possible reasons.
You may also need to close the archive
ar.Close()
before accessing the buffer.
Roger Allen
Sonork 100.10016
yet to be identified being from the planet Paltinmoriumbanfrettybooter
|
|
|
|
|
Have you confirmed that your document's Serialize() method is serializing data?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
hey guys
how does one detect if a computer has an active internet connection? i got the ras modem stuff sorted but what about a network connection through a corporate network and such?
is there a simple way to check on the internet or not via whatever method?
help appreciated
---
"all's fair in love and war but in love there is no geneva convention"
|
|
|
|
|
BOOL CheckInternetConnection(char *strError) {
CString g_strURL = "http://www.indiatimes.com";
LPVOID pParam=NULL;
CInternetSession session;
BOOL bConnectFlag = FALSE;
CStdioFile* pFile1 = NULL;
try {
pFile1 = session.OpenURL(g_strURL, 0, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD); // needed for Windows NT c/r authentication
if(pFile1 != NULL) {
bConnectFlag = TRUE;
delete pFile1;
} else
bConnectFlag = FALSE;
} catch(CInternetException* e) {
LogInternetException1(strError,e);
e->Delete();
bConnectFlag = FALSE;
}
return bConnectFlag;
|
|
|
|