|
I am at work right now, and I do not have much time to look for a good link for you. I will try to get some information for you tonight (about 7-8) hours.
In the mean while, try a search on google for something like:
array implementation "binary tree"
This should get you started, in the short time that I looked, I could not find a good source sample.
Also try learning a little bit about red-black trees, this is the implementation that you will want to settle on if you go this route. Heapsort is another item to look at.
Good Luck
Sorry I can't give you more information right now.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
If you only want to search the file and your strings are as you say fixed, then this is also a possibility:
Map your file using CreateFileMapping() and MapViewOfFile() from the Win32 API.
The filemapping lets you access your file as if it was a chunk of memory, and the OS takes care of all the IO stuff in the background.
MapViewOfFile() returns a pointer that you can pass as the basepointer to bsearch() from the C-runtime (stdlib.h).
This function does a binary search using a base pointer to an array of items, the size of each item (that's why the strings have to be fixed) and a function pointer to a function that can compare two strings (you could easily wrap strcmp() or lstrcmp() for this purpose).
This technique should be the fastest way of searching, but if insertion is an issue, then of course you should use trees.
"It could have been worse, it could have been ME!"
|
|
|
|
|
Someone once told me that using STL Map, which internally is an implementation of a binary tree, is an efficient way to solve this sort of problem.
|
|
|
|
|
The STL map does use a red-black tree (specialized version of a binary-tree).
This may be a little tricky to use though if he needs to parse through different strings in a key entry in order to perform his lookup.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I want to display an icon in a dialog. I add a static control, set it to type Icon and select the Icon from my resources.
The problem is that, even though the icon I'm using is larger than the default size, the dialog insists on scaling it down to the default size.
How do I tell VC that I want to display the icon at it's actual size? I'd use a bitmap instead but I want it to have a non-rectangular shape and using an icon seemed simpler.
|
|
|
|
|
Overriding the paint handler in your dialog and using DrawIconEx will do the trick.
Dov Sherman wrote:
How do I tell VC that I want to display the icon at it's actual size?
Shout at it really loud. Use harsh language. Tell it that Microsoft Sucks™. Then try DrawIconEx .
|
|
|
|
|
Set the style to "real size image" in the resource editor or programmatically.
|
|
|
|
|
In a dialog-based MFC, i've created a mutex as a result of pressing of a button, this way:
m_hMutex=CreateMutex(NULL, FALSE, "unique name");
Later, i call:
WaitForSingleObject(m_hMutex, INFINITE);
waiting for a worker to release the mutex.
The behaviour of the stuff is very strange: the worker doesn't release the mutex, but the main-one passes the WaitForSingleObject call and returns WAIT_OBJECT_0 immediately.
If you know how could it be fixed, please kick a click to some reply.
rechi
|
|
|
|
|
Has the worker really acquired the mutex before you try to wait?
Also, if this is the only way you are using it perhaps an event is a better choice than a mutex?
|
|
|
|
|
I pass the mutex' handle by the PVOID of the worker, while the mutex is constructed with FALSE on bInitialOwner.
It has to behave like a theoretical binary semaphore.
rechi
|
|
|
|
|
Then, how do you know that the started thread has indeed started and acquired the mutex?
Perhaps an event is a better choice in this case. If you create an event in the non-signalled state, hand it over to the thread you're creating and then WaitFor... until the other thread signals the event object (SetEvent).
|
|
|
|
|
If you name the Mutex or Event the same in both threads there is no need to pass a handle to the other thread. Remember make the name unique in the system use a GUID for example. Then Create the mutex in the main thread and open it in worker threads.
John
|
|
|
|
|
Are you calling WaitForSingleObject(m_hMutex, INFINITE); in the worker. Your call to CreateMutex does not acquire the mutex.
John
|
|
|
|
|
I was told that you can perform this conversion using the transforms and widen and narrow functions. But having played with the transform function, I keep getting an error regarding not beign able to find the widen() function. Where is widen() defined?
this is what i do:
wstring wstr;
string str;
transform(str, wstr, widen());
|
|
|
|
|
Where is widen() defined?
basic_ios
If you for some reason can't read the documentation, you might try the following:
Open an explorer window and navigate down to your MSVC include directory. Press F3. Type "widen(" (without the quotes) in the "Containing text" edit box.
Once you get a sample compiled you can get there even faster by pressing F12 from within the IDE.
|
|
|
|
|
I have an XML document that includes a DTD . I need to parse this file using VC++ using the DOM .Where can I find resources for doing this . Please help
Actx
|
|
|
|
|
http://www.codeproject.com/soap/#XML
I vote pro drink
|
|
|
|
|
I have a function which takes the IShellFolder object for a folder as a parameter, and loops through all the items in the folder. If it is a file, it adds it to a ListView control, and if it is a folder it calls itself. But the first time the function encounters a folder and calls itself, the pIShell->EnumObjects returns the error code -2147023673 which, according to the Error Lookup, is "The operation was canceled by the user.".
Can anyone figure out what's wrong? Here's the code:
void AddFilesFromFolder(IShellFolder *pIShell)
{
if (pIShell)
{
IShellFolder *pBrowse = NULL;
LPENUMIDLIST pFolder = NULL;
LPMALLOC pMalloc = NULL;
ITEMIDLIST *pNewId = NULL;
STRRET strDispName;
LVITEM lvItem;
DWORD pActual = 0;
DWORD dwAttrib;
IShellFolder *CurrentFolder;
HRESULT err;
err = SHGetDesktopFolder (&CurrentFolder);
if (err == NOERROR)
{
SHGetMalloc(&pMalloc);
err = pIShell->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pFolder);
if (err == NOERROR)
{
lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
while (pFolder->Next(1, &pNewId, &pActual) != S_FALSE)
{
dwAttrib = SFGAO_FOLDER;
pIShell->GetAttributesOf(1, (LPCITEMIDLIST*)&pNewId, &dwAttrib);
if (!(dwAttrib & SFGAO_FOLDER))
{
pIShell->GetDisplayNameOf(pNewId, SHGDN_INFOLDER, &strDispName);
GetID3();
FillInfo();
ListAddItem();
}
if (dwAttrib & SFGAO_FOLDER)
{
CurrentFolder->BindToObject(pNewId, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
Add2(pBrowse);
}
}
pMalloc->Free(pNewId);
pMalloc->Release();
gbFileOpen = true;
pFolder->Release();
}
CurrentFolder->Release();
}
}
}
Thankyou.
-Rune Svendsen
|
|
|
|
|
Try setting hwndOwner and maybe it will show you a message.
MSDN says "If hwndOwner is set to NULL, the enumerator should not post any messages, and if user input is required, it should silently fail."
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Hi I've read the article in Code project about the mschart and how to set data. Now I would like to know how to set the labels.
Can anyone help?
Thanks
|
|
|
|
|
G'Day Anon
I may have the answer for you though I'm not 100% sure because I'm yet to get it working myself - but I have run out of time for the moment.
using the example on code project I have added the following code when the GO button is pressed. I have placed it just before the chart is refreshed.
The first bit sets the legend (only did 1 to see if it worked)
CVcPlot Plot = m_Chart.GetPlot();
CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection();
CVcSeries Series = SeriesCollection.GetItem(1);
Series.SetLegendText(_T("New Text"));
The next bit was to do the labels for each point on the axis. It is incomplete and not quite working but hopefully it will give you an idea and you can let me know how to fix it I am getting a bad function argument error when calling SetColumnLabel or SetRowLabel - something to do with my indexes I think.
CVcDataGrid DataGrid = m_Chart.GetDataGrid();
short i;
CString strLabel;
short nRows = DataGrid.GetRowLabelCount();
short nColumns = DataGrid.GetColumnLabelCount();
/* for (i=0; i
|
|
|
|
|
Hi Richard,
Sorry that I'm only answering now, it's just that I've been busy and only had the time to do this now.
I tried what you suggested and also get the same "bad function argument" error.
So I tried the following:
short index;
for ( i = 1; i < 11; i++ )
{
//strLabel.Format("row %d", i);
// strLabel = "Row Text";
index = i * 2;
// DataGrid.SetColumnLabel(index, 1, "");
strLabel = DataGrid.GetColumnLabel(index, 1);
}
And I get all the correct column names, i.e. R1, R2, R3, ... R10.
It almost seems to be the actual string variable that seems to give the problem???
Still trying. Have you had any success?
Rui
Rui
|
|
|
|
|
Hi Richard,
I tried the following:
DataGrid.SetColumnLabel(1, 1, "Column 1");
strLabel = DataGrid.GetColumnLabel(1, 1);
AfxMessageBox(strLabel);
This enables the C1 text in the datagrid to be changed. This seems to be the name of the first set of data.
But I'm still not able to change the Column labels.
Does anyone have a clue how to do it?
Regards
Rui
|
|
|
|
|
hi Richard,
The following works:
COleSafeArray saRet;
CString strLabel = "";
DWORD numElements[] = {10, 1}; // 10x10
//DWORD numElements[] = {10};
// Create the safe-array...
saRet.Create(VT_R8, 2, numElements);
// Initialize it with values...
long index[2];
for(index[0] = 0; index[0] < 10; index[0]++)
{
for(index[1] = 0; index[1] < 1; index[1]++)
{
double val = index[0]*10;
saRet.PutElement(index, &val);
}
}
// Return the safe-array encapsulated in a VARIANT...
m_Chart.SetChartData(saRet.Detach());
m_Chart.SetChartType(3);
CVcPlot Plot = m_Chart.GetPlot();
CVcSeriesCollection SeriesCollection = Plot.GetSeriesCollection();
CVcSeries Series = SeriesCollection.GetItem(1);
Series.SetLegendText(_T("New Text"));
CVcDataGrid DataGrid = m_Chart.GetDataGrid();
short i;
short nRows = DataGrid.GetRowLabelCount();
short nColumns = DataGrid.GetColumnLabelCount();
/* for (i=0; i {
strLabel.Format("col %d", i);
DataGrid.SetColumnLabel(i, 1, strLabel);
}
*/
short j;
// DataGrid.SetColumnLabelCount(10);
// count = DataGrid.GetColumnLabelCount();
for ( i = 1; i < 6; i++ )
{
//strLabel.Format("row %d", i);
strLabel = "Row Text";
j = i * 2;
// DataGrid.SetColumnLabel(j, 1, strLabel);
strLabel = DataGrid.GetColumnLabel(j, 1);
//AfxMessageBox(strLabel);
DataGrid.SetRowLabel(i, 1, "Row");
strLabel = DataGrid.GetRowLabel(i, 1);
}
m_Chart.SetShowLegend(TRUE);
m_Chart.Refresh();
Try it.
Thanks for your help
Rui
|
|
|
|
|
G'Day Rui,
I'd forgotten all about this! I'll dig out the code I was playing with at the time and try it out.
Thanks for your help!
Richard.
|
|
|
|