|
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:-
|
|
|
|
|
I'm trying to add a task to the context menu of the Results Pane but can not seem to do this atall!!
I have added a task to the node in the scope pane but when using the same code to add to the results pane it compiles but doesn't do anything. The results pane displays entries that are read into a vector from reading files from a particular directory.
Code I have used is same as below - help!!!
//This is taken from an platform sdk sample and works on the node but not the results
//add item adds the item to the context menu and the menu command deals with the
//resulting command.
HRESULT CRocket::OnAddMenuItems(IContextMenuCallback *pContextMenuCallback, long *pInsertionsAllowed)
{
HRESULT hr = S_OK;
CONTEXTMENUITEM menuItemsTask[] =
{
{
L"Start vehicle", L"Start the space vehicle",
IDM_START_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, CCM_SPECIAL_DEFAULT_ITEM
},
{
L"Pause vehicle", L"Pause the space vehicle",
IDM_PAUSE_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
},
{
L"Stop vehicle", L"Stop the space vehicle",
IDM_STOP_SPACE, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
},
{ NULL, NULL, 0, 0, 0 }
};
// Loop through and add each of the menu items
if (*pInsertionsAllowed & CCM_INSERTIONALLOWED_TASK)
{
for (LPCONTEXTMENUITEM m = menuItemsTask; m->strName; m++)
{
hr = pContextMenuCallback->AddItem(m);
if (FAILED(hr))
break;
}
}
return hr;
}
HRESULT CRocket::OnMenuCommand(IConsole *pConsole, long lCommandID)
{
const size_t cchBuffer = 128;
_TCHAR szVehicle[cchBuffer];
// StringCchPrintf and StringCchCopy always null-terminate the destination string.
// However the string may be a truncation of the ideal result (indicated by return value other than S_OK).
switch (lCommandID) {
case IDM_START_SPACE:
iStatus = RUNNING;
break;
case IDM_PAUSE_SPACE:
iStatus = PAUSED;
break;
case IDM_STOP_SPACE:
iStatus = STOPPED;
break;
}
StringCchPrintf(szVehicle, cchBuffer, _T("%s has been %s"), szName,
(long)iStatus == RUNNING ? _T("started") :
(long)iStatus == PAUSED ? _T("paused") :
(long)iStatus == STOPPED ? _T("stopped") : _T("!!!unknown command!!!"));
MAKE_WIDEPTR_FROMTSTR(ptrname, szVehicle);
int ret = 0;
pConsole->MessageBox(ptrname,
L"Vehicle command", MB_OK | MB_ICONINFORMATION, &ret);
return S_OK;
}
Steve
|
|
|
|
|
Hi everybody,
I have a small problem with a CRecordset. I open a dialog-box, where I set some values. When I close the dialog-box with OnOK(), I put all the values in an access-mdb using ODBC.
Right after closing my dialog-box, I need the values in the calling function. So I open my recordset again and read all the values. But the last value is missing.
When I debug my application, all values appear. When I add a button, to get the values from my database, all values appear. When the values are to be read immediately after closing my dialog-box, the last value is missing.
So I think, it is some kind of timing problem. That I read from the database, before all records are written. I tried to reopen the database in my dialogbox right after closing it and I close it again. Now all my records are there (at least mostly). But this is not really elegant.
So, is there any possibility, to wait, until the data is really written in the database after closing it, before reopening it again?
Or am I completely wrong and the problem is something else?
Juergen
|
|
|
|
|
Hi everybody,
I have a big problem when using a CRecordset, that contains a CTime-object.
I use an Access-mdb via ODBC and have a table containing a date/time-row.
I can open this table using CRecordset.
I then do an Edit(), set my values and perform an Update(). Everythings works as expected.
But when I do an AddNew(), set my values and perform an Update(), a access-violation occurs. Debugging shows, that the CTime-object is called with a GetYear(). And here the GPF happens. Since this is somewhere deep inside the MFC, I can not tell, what's going wrong.
Something strange:
I have another table, containing CTime-objects and AddNew() works fine here. I have not found any special differences in my algorithms.
So, can anybody tell me the right questions to help me here?
Juergen
|
|
|
|
|