|
I am trying to update my CViews related to my CDocument. In order for the program to remain resposive as data is read from a file, I need to start a seperate thread to do the reading and updates. The problem I am running into, as I understand it, is that I cannot use C++ objects in this thread. The code I have is:
<br />
while (m_bRunThread)<br />
{<br />
<br />
this->UpdateAllViews(NULL); <br />
}
Is there a way to accomplish what I want to do?
Thanks.
|
|
|
|
|
masnu wrote:
this->UpdateAllViews(NULL); //ERROR HERE
What error?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
typically, you'd have a UI thread and a worker thread. the UI thread would (obviously) handle the UI updates, and would communicate anything to the UI anything the worker thread had to say. in other words, you wouldn't have two separate threads talking to the UI.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
MFC uses thread local storage to maintain it's map of CWnd objects to HWND. So only the UI thread will have this data structure. There are Knowledge base articles on MSDN about this.
Look at using PostThreadMessage to communicate events from the worker thread to the UI thread. Be sure to apply synchronization where necassary to avoid corrupting data.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Doing anything extensive in your UI thread is asking for trouble. Often causes your UI to become unresponive.
Put your big file operation (and other I/O -- i.e. networking) into a worker thread.
Once your big operation is complete, you can post a message to the UI thread.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
hello,
i have a cstring like this:
item1,item2,item3,item4,etc is their a way to get each item seperated by a comma into an array (or a for loop)? i want to add each item to a listbox.
(something like php's explode() function: http://us2.php.net/explode)
thanks in advance
|
|
|
|
|
Are you looking for AfxExtractSubString() ?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Used that. Thanks for the tip.
|
|
|
|
|
use Tokenize()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
Sam Kline wrote: is their a way to get each item seperated by a comma into an array (or a for loop)? i want to add each item to a listbox.
see example quoted in Help of CStringT::Tokenize in MSDN!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I have a dropdown combo box that needs to be able to accept new entries not listed in the combo box via the edit control. If I create the member variable as a value instead of control, I'm able to save the selection or text input, but how do I display it in the edit control when I reopen the window. I tried the following:
private:
CString test_value;
test_value = m_test; //Saves the selection
//m_test = test_value; //tried this first
GetDlgItem(IDC_TEST)->SetWindowText(m_test); //this didn't work either
UpdateData(FALSE);
Please help! Thanks.
|
|
|
|
|
elephantstar wrote: GetDlgItem(IDC_TEST)->SetWindowText(m_test); //this didn't work either
UpdateData(FALSE);
does SetWindowText still not work if you get rid of the UpdateData call ?
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
Hi,
I don't have more knowlegde about VC++, but try following if it can satisfy your requirement.
CComboBox *combo = new CComboBox();
combo->m_hWnd = GetDlgItem(IDC_TEST)->m_hWnd;
combo->AddString("AS");
combo->AddString("ZX");
m_combo = "ZX";
UpdateData(FALSE);
Try it.
Best Regards,
Aniket
-- modified at 9:07 Friday 19th May, 2006
|
|
|
|
|
|
My app reports memory leaks. The problem is, I can't track them down because the allocation numbers (the ones in curly brackets) change every time I run the app, even though I do so in exactly the same way each time. I have tried using Visual Leak detector, but it doesn't find any leaks. Any suggestions would be most appreciated!
Here's what pops up in the Debug Window. I am using Visual C++ 6.0, under Windows XP Home edition.
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {1398} normal block at 0x00EF4300, 16 bytes long.
Data: < F:\ > 01 00 00 00 03 00 00 00 03 00 00 00 46 3A 5C 00
strcore.cpp(118) : {1397} normal block at 0x00EF4448, 16 bytes long.
Data: < C:\ > 01 00 00 00 03 00 00 00 03 00 00 00 43 3A 5C 00
thrdcore.cpp(166) : {1388} client block at 0x00EF47D8, subtype 0, 112 bytes long.
a CWinThread object at $00EF47D8, 112 bytes long
thrdcore.cpp(166) : {1367} client block at 0x00EF44A0, subtype 0, 112 bytes long.
a CWinThread object at $00EF44A0, 112 bytes long
Object dump complete.
Thanks for any help!
|
|
|
|
|
This is purely a guess, but you are 'new'ing two CWinThread based objects and they are not being 'delete'd. I'd also suspect that these CWinThread based objects are where the CString leaks are coming from. But without any kind of code listed, it's all guesswork.
Chris Meech
I am Canadian. [heard in a local bar]
The America I believe in has always understood that natural harmony is only one meal away from monkey burgers. [Stan Shannon]
GOOD DAY FOR: Bean counters, as the Australian Taxation Office said that prostitutes and strippers could claim tax deductions for adult toys and sexy lingerie. [Associated Press]
|
|
|
|
|
Thanks, Chris.
I found the problem, deleting monitoring threads in OnDestroy() which wasn't being called.
|
|
|
|
|
Hi !!!
If you want to detect your Memory Leaks, I wouldn't use the Visual Leaks Detector. It makes some things they are not good in the Runtime. If you want to use VLD, use it only for debugging, belive me. If you don't want to use VLD, I don't know any other Leak Detectors for the Visual Studio 6.0. In Visual Studio .NET 2005 you can do it by using the _CrtMapAlloc in your watches and than you can trigger a breakpoint.
By!!!
-:KNOX:-
|
|
|
|
|
I have three document types in my software. However, when I run the app, it prompts me to decide what type of document to start with; furthermore when I try to use the same resource ID for more than one of my document templates...it also seems to do the same thing. Any ideas? The offending code is listed below.
Thanks in advance.
<br />
pDocTemplate = new CMultiDocTemplate(IDR_PhotonOneTYPE,<br />
RUNTIME_CLASS(CPhotonOneDoc),<br />
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CPhotonOneView));<br />
if (!pDocTemplate)<br />
return FALSE;<br />
AddDocTemplate(pDocTemplate);<br />
pLWDocTemplate = new CMultiDocTemplate(IDR_MAINFRAME,<br />
RUNTIME_CLASS(CLyghtWayveDoc),<br />
RUNTIME_CLASS(CLyghtWayveFrm),<br />
RUNTIME_CLASS(CLyghtWayveView));<br />
if(!pLWDocTemplate)<br />
return FALSE;<br />
AddDocTemplate(pLWDocTemplate);<br />
pNuDocTemplate = new CMultiDocTemplate(IDR_PhotonOneTYPE,<br />
RUNTIME_CLASS(CNuonDoc),<br />
RUNTIME_CLASS(CNuonFrm),<br />
RUNTIME_CLASS(CNuonFormView));<br />
if(!pNuDocTemplate)<br />
return FALSE;<br />
AddDocTemplate(pNuDocTemplate);<br />
<br />
<br />
CMainFrame* pMainFrame = new CMainFrame;<br />
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))<br />
return FALSE;<br />
m_pMainWnd = pMainFrame;<br />
m_pMainWnd->DragAcceptFiles();<br />
EnableShellOpen();<br />
RegisterShellFileTypes(TRUE);<br />
CCommandLineInfo cmdInfo;<br />
ParseCommandLine(cmdInfo);<br />
if (!ProcessShellCommand(cmdInfo))<br />
return FALSE;<br />
pMainFrame->ShowWindow(m_nCmdShow);<br />
pMainFrame->UpdateWindow();<br />
-- modified at 13:46 Thursday 18th May, 2006
|
|
|
|
|
BlitzPackage wrote: when I run the app, it prompts me to decide what type of document to start with
I'm assuming this is undesireable. If so, see here.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
David,
Thank you so much; because of you I found that answer. I really appreciate it.
What I did was implement the method you provided the link for in an overrided version of the CWinApp::OnFileNew() method.
Thanks again,
BP
|
|
|
|
|
hello again
Can anybody explain me :
1) What we need stdafx.h and stdafx.cpp files for ?
2) Why are they useful ?
thank you.
|
|
|
|
|
|
Hi !!!
The stdafx file is Precompiled Header file. You can call it Monkey, too. It is only some name from the ActiveX libs.
By !!!
-:KNOX:-
|
|
|
|