|
|
|
|
How can I do to make a class serializable, a class which is not
derived from a CObject class.
Fred.
Thank for your help
|
|
|
|
|
Hi Fred,
If the type of class you are going to load is fixed, then the solution is simple, add a Serialize(CArchive &ar) method to the class. You create a blank object, a call this function, passing the CArchive reference to it, and hey-presto, you have a loaded class. If you have a class whose type is not fixed, your job is a little harder .. you will still need a 'Serialize' function though. The only reason you need a CObject derivation is because with it, MFC is able to dynamically reproduce the class from file data. But, as you don't have a CObject derivation, you will need to do this manually. In saving you must do three steps,
1. Store an identifyer that defines the name of your class, a string, or a just a token.
2. Get the class to serialize all it's member variables using the Serialize function.
To load you must
1. Read the identifyer that defines the class type.
2. Now you know what type of class to create, create it - like this
3. Ask the class to load it's member variables from the the archive, also using the Serialize function.
The code for loading might look a little like this...
ar >> iClassType;
switch(iClassType)
{
case FISH: object = new CFish(); break;
case DUCK: object = new CDuck(); break;
default: ASSERT(NULL); break;
}
object->Serialize(ar);
You could even define a constructor for the object that took a reference to the CArchive as it's only parameter, so as you construct the object, it deserializes itself!
I hope this all helps
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
I finally finished RC1 of my Movie Database ( with huge thanks to all who helped, especially Norm for getting me over the Connection Points hurdle with the code he sent me ). It a COM dll which is called from an MFC client, and when reading in files, the dll sends back messages through connection points to advise of each filename being scanned, the number of files to be processed ( for a progress bar ) and a message to say it's stopped scanning. My class that catches these messages impliments a progress dialog based on them.
Now the question. I'd like to make the dialog run in a different thread and put a 'Cancel' button on it. I want a different thread so that the GUI doesn't lock up due to the process of reading files, etc. The thing is, how do I tell my dll to stop processing files and just finish with the ones it has ? The obvious way would be another COM method that sets a bool which is checked before I process each file. I have two qualms.
1/ It's ugly. Is there a nicer way to do it ? I'm not concerned about speed, because the time it takes to check a bool pales next to the time it takes to render a video file and establish the data I am storing ( frames, length, size, etc ). I am concerned about doing this well ( the whole point is to learn more about ATL, after all ), so if there is a nicer way of doing it, I'd love to hear it.
2/ If my instance of the COM object is busy processing files, will my other call to set the bool occur right away in another thread, or sit in a message queue and execute when I don't need it anymore, i.e. the files have been read.
Any advice is, as always, appreciated.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
The obvious way would be another COM method that sets a bool which is checked before I process each file.
I once made an anti-virus scanner that ran as an ActiveX control in IE and I used precisely this method, and it worked fine. The control was free-threaded, so the StartScan() method (which was called by script in an HTML page) created a new thread to do the actual scanning. This let the main thread return to IE.
Now when the user clicked the cancel button, it called StopScan() which set a flag. The scanning code checked that flag and stopped when it was true.
So the key is to do your processing in a worker thread, that way your Stop() call will happen on another thread and your worker thread will see the change right away.
(I should note that this one project, done almost 2 years ago, was my only venture into production-level multithreaded COM stuff, so there might be a better way to do this. However, what I described above worked perfectly for me.)
--Mike--
http://home.inreach.com/mdunn/
your with and
|
|
|
|
|
Is it possible to change screen resolution or window resolution without interacting with drivers. Since gdi can provide us with only defined set of resolutions such as 800x600 or 1024x768. I need to change the resolution whatever i wish,it may be 5023x4045 or 7048x5678 or anything.
1) Is there any device driver do support this?
In vb, we can get all the controls of the form and change their width and height to make a form resolution changed.
2) Is it possible to do the same with windows?
|
|
|
|
|
MoveWindow or SetWindowPos will move a window or control. If you want to set the screen resolution, I know you can under DX, but even then you query DX for a list of resolutions the driver will support. Why do you want to change the resolution to something non-standard and ( assuming your examples are an indication ) something most monitors will not display ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
you can use API function : ChangeDisplaySettings
|
|
|
|
|
I have to replicate a window whose handle is known. A window can't be replicated using setwindowlong and getwindowlong. if replication is possible,both windows should be functional and at the same time scrolling in one window should not reflect in other window.
Is it possible to replicate a window with its data buffer?
|
|
|
|
|
|
Hi,
I have a strange problem, I have no device connected to Com1 yet whatever I send via SetOutput() is waiting for me when I issue GetInput()
I am using the MSComm ocx within my VC++ 6.0 as such:
m_mscomm1.SetCommPort( 1 );
m_mscomm1.SetSettings( "9600,N,8,1" );
m_mscomm1.SetPortOpen( TRUE );
// now I write some date
CString StringToWrite;
StringToWrite = "Test";
COleVariant var;
var.vt = VT_BSTR;
var.bstrVal = StringToWrite.AllocSysString();
m_mscomm1.SetOutput( var );
// now I read the input buffer
COleVariant oVA;
CString ctmp;
oVA.Attach( m_mscomm1.GetInput() );
ctmp.Format( "%s", oVA.bstrVal );
===========================
ctmp now = "Test";
|
|
|
|
|
There are two methods for reading...
----------------------
POLLING =======
----------------------
Assuming the Mscomm control is on the form and has the name MyCom and that there is a form property named mybuffer, the following code illustrates how to poll for waiting characters ( this is in VB but same procedure you can use in VC) :
Procedure myform.myproc
IF Thisform.MyCom.InBufferCount > 0
Thisform.mybuffer = Thisform.mybuffer + Thisform.MyCom.Input
ENDIF
ENDPROC
----------------------
EVENT DRIVEN ( YOU SHOULD USE THIS BECAUSE THIS IS BETTER ) =====
----------------------
For example, you can place the following code in the OnComm event to append received data to a property of a form called mybuffer:
Procedure MyCom.OnComm
IF This.CommEvent = 2
ThisForm.mybuffer = ThisForm.mybuffer + This.Input
ENDIF
ENDPROC
----------------------
Do this way and tell me if problem persist.
Or You can read articles in msdn...(By searching in MSDN)
one of good articles is :
******
INFO: Troubleshooting Tips for the MSComm Control
******
--------------------------------------------------
Say Whatever You Know.
Helping other people is good for health.
=========
Manish
=========
---------------------------------------------------
|
|
|
|
|
Hi,
I'm wondering why my tab-key is not working when I try to jump to the next control in my dialog. Also I would like the enter-key to have the same effect as the tab-key.
Anyone any idea how to do this? (Sorry I'm very new to VC++ )
Thanks
|
|
|
|
|
Press CTRL+D in the dialog editor to set correct TAB-order, then you should be able to use TAB key to jump to the next control. If you would like Enter key to have the same effect as the TAB key, you can overload the dialog's OnKeyDown() function.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Thanks, but I guess there's another problem:
When I start my dialog project, tab key is working fine until I press a button which calls a routine from where there is no return. All the dialog functionality is ok except for the tab-key.
How can I overcome this problem
|
|
|
|
|
What do you mean "no return"?
Could you show me the codes?
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Here you are:
void CSimulatorDlg::OnOK()
{
static launched=false;
if (!launched)
{
launched=true;
goOpenGL(); // Careful!! There is no return from this function!!
}
}
And at the end of goOpenGL() there is the following instruction from where there's no return :
glutMainLoop(); // Go into main loop and stay there
The function above comes from the GLUT-library (openGL)
|
|
|
|
|
Well, I think you'd better not call goOpenGL() in OnOK() function.
Because if OnOK() doesn't return, the dialog can't get messages so there will be some unexpected behaviors. You should start a thread to process goOpenGL() like this:
UINT ProcessingThread(LPVOID lpData)
{
goOpenGL();
return 0;
}
void CSimulatorDlg::OnOK()
{
static launched=false;
if(!launched)
{
launched=true;
AfxBeginThread(ProcessingThread,NULL);
}
}
and there should be no trouble.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Working prefectly now
Thanks a lot
|
|
|
|
|
I am working on a logger for my friend and I need to know how I could go about capturing the keyboard commands and saving them to a file.
Help is much appreciated.
"To wonder is to begin to understand"
|
|
|
|
|
Look under "Hooks" on the MSDN Index, you will have different types of Hooks, Keyboard Hooks are for you.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Ahhhh, that hurts. How can I get it to log for the entire system and not just one program (I have never used hooks)
"To wonder is to begin to understand"
|
|
|
|
|
Actually System Hooks are for the entire system, not just one program.
I don't remember the details about the use (I have used them a little bit a long time ago), but you can capture pretty much anything (you won't be able to get the keyboard entry for de logon process, and that kind of stuff).
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|