|
I've a MDI application on which each doc/view can expect a lot of input.
What kind of input it is?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Tomasz,
Sorry I'wasn't complete
I've already updated the initial story.
The input is not from user, but Trace Events from a TCP-socket. A separate thread (launched by the doc) forms a complete protocol handler and connects to a device. When a trace-event is received, a string passed to the doc which updates the view.
It's also possible for the user to select a line in the view, and than press a button to add some comments. But this is rarely used, so: no user input to view.
Hopes this completes the story,
EiSl
|
|
|
|
|
I've never done MDI multi-threaded app, so can't really comment on this. There's a topic in Platform SDK titled "Using a Multithreaded Multiple Document Interface Application" (under Base Services/DLLs, Processes and Threads/Using Processes and threads). How this applies to MFC app is another story. Have fun!
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I've also found MTMDI sample in MSDN. It's a MFC program that uses multiple user-interface threads. However, it's 'old-style' MFC, without the doc/view.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I would probably create a thread that handles the TCP/IP connection itself, and when it has data for displaying in a view, would send a message to the approriate view.
Each view would have to register itself with the TCP/IP thread so that the thread would know who to send the data to, and the thread would have to maintain a list of views' pointers that are registered with it.
I think this might give you back your interface response because the views are now only displaying data that the TCP/IP thread tells them they have.
|
|
|
|
|
Hello John,
Thanks for reply!!
This is already how it's working now.
When a new document is created (OnNewDocument), a communication thread (WinThread) is started, which is using CAsyncSockets for communications. When data has to be printed, it is passed to the document.
But...
When I've have more than 3 documents active, and they generating quite a lot data, the main app starts become less responsive since all the documents/view updates are done under the hood of the main application thread. That was the reason for asking a thread handling doc/view archtecture.
EiSl
|
|
|
|
|
What kind of view are we talking about? CEditView? CListView? CFormView?
|
|
|
|
|
Hello John,
Does this really matters?!?
Ok in case of a CFormView yes it matters.
In my case we're talking about a read-only CEditView, but maybe this is changed to a CListView.
Sincerly,
EiSl
|
|
|
|
|
You'd probably be better off with a CFormview with a CListBox in it.
I'd be willing to bet that (with the CEditView) you are simply adding the newest message to the existing contents of the edit control. At first, performance is pretty good, but the longer the program runs, the worse less responsive the program gets.
If you change to a list box, you have better control over how much data is contained in the control (you could limit it to say 1000 lines). With an edit control, you have to call SetWindowText with a string that is larger each time. This takes a lot of processing time (a lot more time than adding a single string to a list box).
I would advise against using a list control unless you need multiple columns for some reason. A list box would be a better choice.
|
|
|
|
|
Thanks for your answer!
Most the time you read answer like: "better do this way" without a clear explaination why to do so.
I've never thougth about the combination of CFormView with ListBox, because I was only looking to derivation of the View. Since it only accepts xxxView I was thinking about the ClistView or CEditView and have chosen for the editview.
When everything is working fine I will take a look for changing that part, since it's quite easy to change.
Happy programming!
Eize
|
|
|
|
|
I had the same problem in a previous project that I inherited. We were storing messages coming across a network in an edit control. These messages could be anywhere from 2-64k in length, and that we got approximately 150 messages per minute, and we were simply adding them to the edit control with no thought of the size of the string *in* the edit control. Performance slowed to such a point that the CPU utilization was pegged at 100% and we got so far behind in the message queue that the only recourse was to do a hardware reset. The really embarassing part was that our app was the only one running. LOL
Anyway, we needed to have the edit control, so we changed the code buy only storing only the previous message in the edit control. Performance improved dramatically, and we regained keyboard control of the system.
Good luck on your project.
|
|
|
|
|
I don't think that a thread per doc/view is a good approach: there are a lot of complications, and it doesn't change the fact that only one thread can update the GUI at a time (the GDI calls are serialized).
A much better approach, which I have used successfully in a couple of commercial applications, is to have one worker thread per doc, with the original GUI thread handling all the views. The worker threads can update each documents contents to reflect the input recieved via TCP/IP independently.
You can run into some problems invoking window related functions from a worker thread because of the need to link C++ objects like CWnds with the associated Windows HWND (look up handle maps in the VC++ docs if you want the messy details). As long as the worker threads stick to updating the data in the CDocument derived class, you won't have problems. You may have to use critical sections or some other form of synchronization to stop the GUI thread from reading partially updated document contents though.
I get around the handle map problem by defining a user message UM_UPDATE_VIEWS. The worker threads POST (not send) this message to the main window after changing the document contents. The main GUI thread processes this message, by calling CDocument::UpdateAllViews() for the CDocument derived object passed as a pointer in the LPARAM. This way UpdateAllViews() gets invoked by the main GUI thread, so there is no problem with handle maps.
Stephen C. Steel
Kerr Vayne Systems Ltd.
|
|
|
|
|
I try to create an application which composed by a dialog box. The first aim of this application is to connect an access database, so i put a button to do that. After the connection done, i want to compare a Date which is kept in an edit box in my dlg box to dates in my database. So, I declare m_dlgDate as a COleDateTime variable. When I run the application, even if the dlg date and one of the data date are the same, my application return an AfxMessageBoxwith the message "Not Good Dates".
So, I would like to know if my declarations that's wrong or not??
gerald
|
|
|
|
|
Perhaps you should use a DateTimePicker control instead of a text box? Is the messagebox a complaint from the MFC framework or a result of your own code? The COleDateTime and SQL timestamp both contain clock time in addition to date, you need to take care that it's masked out if you want to compare only the dates.
|
|
|
|
|
Hi
I need two files, psapi.h and psapi.dll. But according to the platform sdk setup,I must download over 80 meg for that. Since I am on a modem connection, the idea isn't appealing to me. Is there any other way of getting individual files? ftp.microsoft.com is down....
|
|
|
|
|
Hello,
I've got those file locally. (psapi.h,*.lib and .dll, total 27kB). It's way smaller than 80MB
If you provide me an e-mail address for sending it to you, I will sent it.
EiSl
|
|
|
|
|
Hello all,
Please take a look to one of the submitted code snippets, where the layout is recalculated:
Link to sample in CodeProject: http://www.codeproject.com/docking/sizing_tabctl.asp
Part of the code:
void CMainFrame::RecalcLayout(BOOL bNotify)
{
CMDIFrameWnd::RecalcLayout(bNotify);
CMDIFrameWnd::RecalcLayout(bNotify);
}
Question:
Why does the author calls the same RecalcLayout twice ?!?!
Thanks,
EiSl
|
|
|
|
|
Hi,
In an application we've written we have a dialog based MFC application
based on the CPropertySheet class. We are dynamically adding and
removing pages while the the dialog is displayed.
If the property pages we're adding and removing contain controls (i've
tried it with buttons and treecontrols), then we have a memory leak:
when I constantly add and remove pages, thus always returning to a
same initial state, the application consumes more and more memory.
It has nothing to do with the CPropertyPage derived objects
themselves. I added several integer members to them, to make the
memoryfootprint of the object bigger, but this doesn't cause the
memory leak to be bigger. However, when I fill the dialog (by using
the dialog editor of visual studio 6.0) with a lot of buttons, then
the memory leak is getting bigger. I've added no functionality to the
buttons, and not to the CPropertyPage derived class, except for one
button with which I can add and remove pages to the CPropertySheet
derived dailogbox. Thus it looks like MFC doesn't destroy the dialog
template, or the controls on it. The page we're removing is NOT the
active page. I've tried explicitly callling destroywindow on the
propertypage that gets removed but this does not work neither.
The only functionality the application has, is adding and removing
CPropertyPage derived objects, so the memoryleak can not be caused by
anything else.
Does anyone have an idea what can be wrong and how to solve it
Thanks,
Serge Desmedt
|
|
|
|
|
Platform SDK documentation says that you shouldn't use PSM_REMOVEPAGE message (which is wrapped by CPropertySheet::RemovePage) during processing of some notifications:
"A number of messages and one function call occur while the property sheet is manipulating the list of pages. While this action is taking place, attempting to modify the list of pages will have unpredictable results. Accordingly, you should not use the PSM_REMOVEPAGE message in your implementation of PropSheetPageProc or while handling the following notifications and Microsoft Windows messages:
PSN_APPLY, PSN_KILLACTIVE, PSN_RESET, PSN_SETACTIVE, WM_DESTROY, WM_INITDIALOG"
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I'm not doing anything of the above.
On the propertypage derived classes there is a button, which sends a message to the propertysheet derived class, who then deletes a page which is not the current active page, and without changing the active page (so PSN_KILLACTIVE and PSN_RESET don't get send). Neither is the dialog startinh or closing, so none of the other meddages get send to the propertysheet.
Serge Desmedt
|
|
|
|
|
Hello, I'm experiencing problems saving a HICON to an icon file. Can you give me an example of doing that?
|
|
|
|
|
I build a SDI project.when the application had exited ,I found memoy leaks detected.The CSingleDocTemplate hadn't been deleted.Someone can tell me what will cause this.Thanx.
|
|
|
|
|
Hi ,
I try to query a value from a remote registry using RegQueryValueEx.But I get an error code which says RPC_S_INVALID_BOUNDS.I tried changins my buffersize from small to large values but to no use.Can anyone please tell me the solution?
Thank You,
Yamuna.E.
Yamuna.E.
|
|
|
|
|
Hi all,
I have a class to print individual pixels on a labelprinter. My barcodes are great but I would also like to print images and/or text. For this purpose I had the idea to create a CDC, place all my bitmaps and text in that cdc and then to convert it to a byte-buffer which I could send to the printer. Why bytes? Because the labelprinter only takes bytes and each byte represents 8 black/white pixels. I (think) cannot send the bytes from a cdc directly because I also need to send control codes to the printer to indicate newlines/formfeeds/margins...
Any ideas on how to convert the CDC to a BYTE-buffer that suits my needs? Other ways to solve this are also greatly appreciated.
|
|
|
|
|
Seems that you need to create a DIB section, select it into DC, perform drawing, then convert the DIB bits to format accepted by your device. CodeProject has an article describing the wrapper class for dib sections - search for 'DIBSection wrapper'
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|