|
The point of doc/view and the UpdateAllViews feature is that you're storing the data in the document. When that data is updated, calling UpdateAllViews allerts all views working with that data that it has changed.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Well, consider Visual Studio. If you have 5 source files open ( the documents ), and you go and change the text color in the options menu, ALL the views will update. The color of the text being displayed in the view is common to ALL views. It is NOT part of the data.
|
|
|
|
|
What you described was nothing like this. You described a piece of data belonging to one view whose change you wanted announced to other views. What you're comparing to in VS is a global setting used with all views.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
I said a "static" variable in the class. It does NOT belong to one view, it belongs ( is shared by ) ALL instances of that view class.
|
|
|
|
|
You were not very clear about whether or not this was a single view type or if you had other view types. At any rate, people like myself freely give our time to help others as a gesture of community spirit. Your rudeness surely won't help you garner much help around here.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Sorry if I sound rude, or "have an attitude". I thought I was perfectly clear in the original question when I said -- What I want is for "AllDocs" to "UpdateAllViews" --.
"Instead of telling us what there isn't - when you clearly don't know - you might try following the advice of those that have done this."
There is no function called "GetFirstDocument". If I "clearly don't know", then maybe someone should tell Microsoft, becuase they neglected to put it in the help files.
I would love nothing more than to follow your advice, that is why I originally posted the question.
"Then you need to use an object that is accessable across all your views/documents. The first one that comes to mind is the application object which can be obtained via AfxGetApp."
Sorry to be "rude" again, but that still doesn't answer the question. So now I have a pointer to CMyApp, ok, what do I do to get all the documents and UpdateAllViews ? My point here is that your not giving me advice, your giving me half answers that never solve the original problem.
I apologize for my attitude, I did not intend to offend anyone, I just wanted to know how other applications update every view in the app. I wanted to know how other software engineers have implemented a " UpdateAllInstantiatedViewsInTheApp() " function.
|
|
|
|
|
RoboTed wrote:
What I want is for "AllDocs" to "UpdateAllViews".
Invalidate() the MDI Client window. If that doesn't work you could:
a) iterate all docs and call UpdateAllView() for each one.
b) iterate all MDI Client window.children and Invalidate each one.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
My problem is that I don't know alot about MFC.
What is "the MDI Client window" and how do I get to it ?
How do I "iterate all docs" ? Which class owns the docs ?
If I can't find a function in the help files, then I won't
know where to find it. There is no "GetFirstDocument" function,
or a "GetFirstView", especially for an MDI app.
All I am doing (for now) is handling a menu message ( change color )
which opens a CColorDialog and let's me pick a color. I want ALL
my views to use the new color.
|
|
|
|
|
Here is some code to scan all views. If you want code to scan all docs or all MDI children let me know.
CEDTextView*
CEDTextView::ScanViews( SECMultiDocTemplate* pTemplate, int(CEDTextView::*Scan_Func)( int ), int iVar1 )
{
if ( pTemplate == NULL )
{
CEDApp* pApp = (CEDApp*)AfxGetApp();
ASSERT_VALID( pApp );
pTemplate = pApp->GetTemplate( IDR_EDTYPE );
}
ASSERT( pTemplate != NULL );
POSITION Dpos = pTemplate->GetFirstDocPosition();
while ( Dpos != NULL )
{
CEDDoc* pDoc = (CEDDoc*)pTemplate->GetNextDoc( Dpos );
if ( pDoc->DocGetVmb() != NULL )
{
POSITION Vpos = pDoc->GetFirstViewPosition();
while ( Vpos != NULL )
{
CEDTextView* pView = (CEDTextView*)pDoc->GetNextView( Vpos );
ASSERT( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) );
if ( pView->IsKindOf( RUNTIME_CLASS( CEDTextView ) ) )
if ( !(pView->*Scan_Func)( iVar1 ) )
return pView;
}
}
}
return NULL;
}
int
CEDTextView::VwDraw( int iOpts )
{
.....
}
CEDTextView::ScanViews( pTemplate, VwDraw, 0 );
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Perfect !!! GetFirstDocPosition and GetNextDoc is exactlly what I was looking for !!! Thank You so much !!!!
|
|
|
|
|
RoboTed wrote:
Thank You so much !!!!
Glad to be of help. Oh and thanks for the thankyou.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
RoboTed wrote:
There is no "GetFirstDocument" function,
or a "GetFirstView", especially for an MDI app
Instead of telling us what there isn't - when you clearly don't know - you might try following the advice of those that have done this.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
"The point of doc/view and the UpdateAllViews feature is that you're storing the data in the document. When that data is updated, calling UpdateAllViews allerts all views working with that data that it has changed."
Yes, I know that. I have used "UpdateAllViews". I get it. As I said before, I am asking how I can update ALL views in my App, not just the ones related to one document. Changing the text color has nothing to do with "the data in the document", it relates to how the view displays it. Therefore, the textcolor is a static member in my view class and has a static access function. Once I change the color variable, I need all the views in my App to redraw themselves. Simply calling UpdateAllViews will only update the views attached to that ONE document.
|
|
|
|
|
Then you need to use an object that is accessable across all your views/documents. The first one that comes to mind is the application object which can be obtained via AfxGetApp.
By the way, unless you lose the attitude I doubt you'll get much more help around here.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Is there a way to use IE to render to bitmap or file?
Todd Smith
|
|
|
|
|
IE can render gif/jpeg/png/bmp files with no prob.
Use "file:"/"res:"/"http:"/custom: moniker
Brian
|
|
|
|
|
Brian Shifrin wrote:
IE can render gif/jpeg/png/bmp files with no prob.
Use "file:"/"res:"/"http:"/custom: moniker
I don't want to load a bitmap I want to load a normal HTML page and save it to a bitmap but I want to do it programmatically and with no windows.
Todd Smith
|
|
|
|
|
I have a MSVC++ 6.0 program that creates a worker thread and then performs file I/O using CStdioFile class. It works fine in Windows 98 but when I try to run the same program on windows XP, it fails to be able to open the files. I looked at permissions and logged in as the sys admin but it still fails to open the files. Any ideas?
Chipg
|
|
|
|
|
::GetLastError == ?????
in debug
@err, hr = ?????
|
|
|
|
|
The error was 32 but nobody else has this file open as far as I know. The filename was obtained using the CFileDialog class in the User interface thread but as far as I can tell this dialog does not actually open the file. It just returns the path and filename for you to open later which I am trying to do in the worker thread.
|
|
|
|
|
Post the code that opens the file via CStdioFile.
Kuphryn
|
|
|
|
|
One Year ago one guy had this same problem like me now (his mail is not valid). I spend 6 days to analyse old threads from all mailing
lists and I could not find solution of my problem.
Question is: "How safely run thread from another thread under MFC."
Here is my sample program.
Only you have to do is put it to any MFC application and run.
When you break execution, this will appear:
DBG: Break command failed within 3 seconds.
DBG: Potential deadlock. Soft broken.
Main thread will stop on PumpMessage().
Always one thread from thread list stop in PumpMessage(). probably
main
thread.
it looks like this:
->> USER32! 77e11d6b()
CWinThread::PumpMessage() line 821 + 19 bytes
CWnd::RunModalLoop(unsigned long 0x00000004) line 3478 + 19 bytes
CDialog::DoModal() line 539 + 12 bytes
CMyApp::InitInstance() line 66 + 11 bytes
sometimes it stop after 15 loops, sometimes after 20000 loops.
When you press F10 nothing will happen.
Sometimes on thread list are 3 threads, sometimes only main thread.
This same effect I have after few hour of waiting.
Different is only m_mgCur:
After break it is: m_mgCur = 0x0f
After few hours waiting: m_mgCur = 0x219
I have no idea what it means.
My program should:
-- Run Master thread:
-- Master thread should run and stop Slave Thread every 6 seconds.
I have no idea how can I do that.
/*------------------------------------------------------------------------*/
in mfc dialog or mainfrm file:
Master Newobject;
--->> Press Start Button: NewObject.Start_Master();
--->> Press Stop Button: NewObject.Close_Master();
/*------------------------------------------------------------------------*/
file: my_problem.h
class Master{
public:
Master();
~Master();
bool Start_Master();
void Close_Master();
CWinThread* volatile p_Thread_Slave;
CWinThread* volatile p_Thread_Master;
protected:
bool Open_Slave();
void Close_Slave();
static UINT Thread_Slave(LPVOID adr);
static UINT Thread_Master(LPVOID adr);
HANDLE ReqestTerminateEvent_Master;
HANDLE ReqestTerminateEvent_Slave;
};
/*------------------------------------------------------------------------*/
file: my_problem.cpp
Master::Master(){
ReqestTerminateEvent_Master=CreateEvent(NULL,TRUE,FALSE,NULL);
ReqestTerminateEvent_Slave=CreateEvent(NULL,TRUE,FALSE,NULL);
ResetEvent(ReqestTerminateEvent_Master);
ResetEvent(ReqestTerminateEvent_Slave);
p_Thread_Master=NULL;
p_Thread_Slave=NULL;
}
Master::~Master(){
if (ReqestTerminateEvent_Master!=NULL) {
CloseHandle(ReqestTerminateEvent_Master);
ReqestTerminateEvent_Master=NULL; }
if (ReqestTerminateEvent_Slave!=NULL) {
CloseHandle(ReqestTerminateEvent_Slave);
ReqestTerminateEvent_Slave=NULL; }
}
/*------------------------------------------------------------------------*/
UINT Master::Thread_Master(LPVOID adr) {
Master *LPMaster=(Master*)adr;
if (LPMaster==NULL) return 1;
while(WAIT_OBJECT_0!=WaitForSingleObject(LPMaster->ReqestTerminateEvent_Master,200))
{
if (!LPMaster->Open_Slave()) {ASSERT(false);}
Sleep(3000);
LPMaster->Close_Slave();
Sleep(3000);
}
return 0;
}
UINT Master::Thread_Slave(LPVOID adr) {
Master *LPMaster=(Master*)adr;
if (LPMaster==NULL) { return 1;}
while(WAIT_OBJECT_0!=WaitForSingleObject(LPMaster->ReqestTerminateEvent_Slave,300)){}
return 0;
}
/*------------------------------------------------------------------------*/
bool Master::Open_Slave(){
if (p_Thread_Slave) return false;
ResetEvent(ReqestTerminateEvent_Slave);
p_Thread_Slave=AfxBeginThread(Thread_Slave,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
if (p_Thread_Slave->m_hThread){
p_Thread_Slave->m_bAutoDelete=false;
p_Thread_Slave->ResumeThread();
} else {
ASSERT(false);
Close_Slave(); return false;
}
return true;
}
void Master::Close_Slave(){
SetEvent(ReqestTerminateEvent_Slave);
if (p_Thread_Slave){
DWORD dwCode;
if ( ::GetExitCodeThread( p_Thread_Slave->m_hThread,
&dwCode )
&& dwCode == STILL_ACTIVE )
{
WaitForSingleObject(
p_Thread_Slave->m_hThread, INFINITE );
}
}
delete p_Thread_Slave; p_Thread_Slave=NULL;
}
/*------------------------------------------------------------------------*/
bool Master::Start_Master(){
if (p_Thread_Master) return false;
ResetEvent(ReqestTerminateEvent_Master);
p_Thread_Master=AfxBeginThread(Thread_Master,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
if (p_Thread_Master->m_hThread){
p_Thread_Master->m_bAutoDelete=false;
p_Thread_Master->ResumeThread();
} else {
ASSERT(false);
Close_Slave(); return false;
}
return true;
}
void Master::Close_Master(){
SetEvent(ReqestTerminateEvent_Master);
if (p_Thread_Master){
DWORD dwCode;
if ( ::GetExitCodeThread( p_Thread_Master->m_hThread,
&dwCode )
&& dwCode == STILL_ACTIVE )
{
WaitForSingleObject(
p_Thread_Master->m_hThread, INFINITE );
}
}
delete p_Thread_Master; p_Thread_Master=NULL;
}
/*------------------------------------------------------------------------*/
-----------------
Mariusz Zielinski brainiax@wp.pl
-----------------
brainiax@wp.pl
|
|
|
|
|
WOW! SORRY guys I did not know that it takes too many place ...
brainiax@wp.pl
|
|
|
|
|
Hello,
I am new to .Net and more of an old school programmer. I for the life of me can’t make srand() work in .Net. this is the line of code that has always worked for me in the past:
srand(time(NULL));
The Error I get is:
error C2365: 'srand' : redefinition; previous definition was a 'function'
And
error C2501: 'srand' : missing storage-class or type specifiers
Now that damn intellisense or however you spell it tells me that srand() will return an int when I hover my mouse over the function call. So I thought that the computer knew what was going on so I tried to catch that int in a variable only to be told:
error C2440: 'initializing' : cannot convert from 'void' to 'int'
So after searching many web sites and books the only way I can find to seed the rand() is with srand(). Have I been left in the dark? Has the call to the system clock changed? What is going on with my lousy srand() call?
P.S. I did include time.h and I have not redefined srand() or rand() at all. I am new to namespace std so maybe I have messed something up in there.
Thanks.
|
|
|
|
|
That still gives the same problem. Am I suppose to be using :: on the rand class? I tried that and it did not work, I also tried using it on noting just like you said. The little menu pops up and teases me that srand() exists but still no luck.
|
|
|
|