Sounds like an excellent candidate for using a DATABASE. Like SQL Server. That's what these programs do for a living....
If you really need to do this yourself, you should probably create a series of memory structures to house the data and create indexes on the various fields. The MFC/OO approach would be to create objects similar to the following:
class CommandObj
{
public:
CString m_cCommandTime;
CString m_cCommandName;
WORD m_wParam1;
WORD m_wParam2;
WORD m_wParam3;
};
class CommandDB
{
BOOL CheckMatch(CommandObj *pCmdObj, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3);
public:
CObList m_oCommands; // list of Command objects
CMapStringToOb m_oCmdNameIndex; // index of cmd name to a CObList of Command objects that have this cmd name
CMapWordToOb m_oParam1Index; // index of param1 values to a CObList of Command objects that have this valuevirtual ~CommandDB(); // clean up our listsvoid AddCommandObj(CommandObj *pCmdObj);
BOOL SearchCommands(CObList *pOutputResults, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3);
};
void CommandDB::AddCommandObj(CommandObj *pCmdObj)
{
CObList *pIdxList = NULL;
// update our indexes...if (!m_oCmdNameIndex.Lookup(pCmdObj->m_cCommandName,pIdxList))
{
pIdxList = new CObList;
m_oCmdNameIndex.SetAt(pCmdObj->m_cCommandName,pIdxList);
}
pIdxList->AddTail(pCmdObj);
if (!m_oParam1Index.Lookup(pCmdObj->m_wParam1,pIdxList))
{
pIdxList = new CObList;
m_oParam1Index.SetAt(pCmdObj->m_wParam1,pIdxList);
}
pIdxList->AddTail(pCmdObj);
// and add to "table"
m_oCommands.AddTail(pCmdObj);
}
BOOL CommandDB::SearchCommands(CObList *pOutputResults, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3)
{
BOOL bFound = TRUE;
CommandObj *pCmdObj;
CObList *pKeyList = NULL;
if (cpCommand != NULL && *cpCommand)
m_oCmdNameIndex.Lookup(cpCommand,pKeyList);
elseif (wpParam1 != NULL)
m_oParam1Index.Lookup(*wpParam1,pKeyList);
else
pKeyList = &m_oCommands; // table scan time...// scan keyset for matches
POSITION pPos = pKeyList->GetHeadPosition();
while (pPos)
{
pCmdObj = (CommandObj *)pKeyList->GetNext(pPos);
if (CheckMatch(pCmdObj,cpCommand,wpParam1,wpParam2,wpParam3))
{
bFound = TRUE;
pOutputResults->AddTail(pCmdObj);
}
}
return bFound;
}
BOOL CommandDB::CheckMatch(CommandObj *pCmdObj, LPCSTR cpCommand, WORD *wpParam1, WORD *wpParam2, WORD *wpParam3)
{
// you can extend this to do "like" clauses/pattern matching, etc...if (cpCommand && *cpCommand)
{
if (pCmdObj->Compare(cpCommand))
return FALSE;
}
if (wpParam1)
{
if (*wpParam1 != pCmdObj->m_wParam1)
return FALSE;
}
if (wpParam2)
{
if (*wpParam2 != pCmdObj->m_wParam2)
return FALSE;
}
if (wpParam3)
{
if (*wpParam3 != pCmdObj->m_wParam3)
return FALSE;
}
return TRUE;
}
This is like a little "hardcoded" isam file...only in memory.
Is it possible to draw several shapes directly on a window during a loop without having any flicker? I have tried to use the ValidateRect and InvalidateRect function, but I can’t seem to make them prevent flicker, maybe I am missing something. How do you prevent flicker when drawing directly on a window?
One way is to use a memory device context (search codeproject for CMemDC), which is essentially a bitmap in memory. Instead of drawing directly to the screen, you draw everything to the memory DC, and then as the last step in the drawing process, you BitBlt the memory DC onto the real DC. This means that if the same part of the DC is drawn multiple times during the drawing process, you won't see any flicker.
But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen? So that you can draw stuff on that area and update it when your done, sort of like when you use BeginPaint and EndPaint?
Aidman wrote: But shouldn't it be possible to use ValidateRect or some other function to prevent an graphic area from updating to the screen?
Yes, but the part you don't validate will still flicker if you draw over the same part multiple times or if you don't handle WM_ERASEBKGND to prevent the background being erased.
It's almost always better to use a memory DC, combined with selective invalidating like you suggested.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
John M. Drescher wrote: YES! This is very important to avoid filcker even if you use a memory dc.
Absolutely! I probably didn't make that clear enough did I
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
I need to play a video file in .avi file format I am writing a DirectX win32 program so I do not want to use the control that ships with VC++ as I need full control.
also the AVI file is compressed using a custom codec.how can I extract the frames although it is compressed.
Hi. Recently due to my newbie design, I got stuck with all my windows as dialogs. Now I want to create a modal help dialog that has CHTMLView in it. I successfully did this with WebBrowser ActiveX object, but it requires external file (which I dont like), since it doesnt have LoadFromResource interface. Now most of the examples shown have Doc/View architecture which makes it simple to replace CChildView with CHTMLView. But almost none is inside a CDialog. The hints like creating CFrameWnd inside a CDialog sounds good but I couldn't make it work. Can anyone help / post an article on this? Any solutions will do. Thanks!!!
I'm looking for what I should use for a collection class which holds small objects of my own creation (all of the one class type.) Trouble is that the collection is expected to have up to 500000 objects in it.
What would be recommended for a collection class that minimizes the searching and retrieval time for so many objects in the collection?
It depends on how you want to access them. If you need to do lookups based on some key value, and the values do not need to be sorted, then you can use a hashmap, as it has constant time insertion, deletion, and retrieval.
If you need them sorted, then you could use a balanced tree, as that will have logN insertion/deletion/retrieval, and allows traversing the tree in order (keeping them sorted).
If you don't care how they are sorted, and don't need to do lookups, then you could use a simple linked list, or even an array if you know at the start how many items there will be.
If you can provide some more details with how you plan to use it, then it will be easier to recommend a specific collection to use.
I wrote a program that does a statistical analysis, allocating large quantities of memories (3-400 MB) dynamically, and then performs cycles of calculations on the data.
At the end of each cycle, the program opens 2 files in sequence and writes the results to the disk.
With the first file there is no problem, with the second everything goes well for 20-30 cycles (on average, but the figure varies), when the fopen() that should open the file fails, returning a null pointer. If I try to make it open the same file (which is always the same file that it opened without problems for the first 20-30 cycles) passing to the fopen the name in “” instead of passing a variable, it still doesn’t open it.
If I give it a wayout letting it open another file somewhere else, it succeeds and goes on.
At the next cycle, it reopens the old file without problems.
It is as the write permission on that file were temporarily altered in a cycle, to be brought back to their original values in the next cycle.
The problem occurs with 3 different compilers (borland, Visual C++, mingw) and on 2 operating systems (windows NT e windows ME) , running on 2 different machines (both pentium)
I tried to launch the program from the Visual C++ debugger with all the cheks activated, putting also checks on the heap (functions _CrtMemCheckpoint, _ASSERTE( _CrtCheckMemory( ) )), but apparently there is no memory corruption problem.
Here is the function savememory where the error occurs.
Hi Alex,
You aren't testing whether the second fclose() succeeds. It may be that the value of fp has been trashed by your for loops. You could printf fp after the close or better still inspect it in the debugger.
Your code hasn't displayed correctly because < and/or > signs are missing. You need to use the Formatting bar to add these.
I'd try remove the code between the fopen/fclose and repeat the test and see what happens. Also inspect why the fopen is failing more closely. perror() might be of use here and the CRT global errno.
Hope that helps.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
That's what I did: I placed a GetLastError right after the test on the pointer of the fopen() and the result is error code = 32, which on my system means: "impossible to access the file, file is used by another process."
In additon, I noticed that, if I wait for a while (in the deubugger), the file (the same file, with the name unchanged) becomes available again and the fopen succeeds. So this would be an easy wayout I only coud be sure that no major problem (like dangling pointers or the like) is threatening the correctenss of the application results.
Anyway, I am trying to figure out some possibilities:
1. Is it possible that some system processes or not-system processes (I am thinking at the Kazaa stuff which I once downloaded - now I deleted it but I notice that, when I connect to the internet, an icon "connected" in the Kazza style appears at the bottom of the screen).
2. The file was not closed properly at the last cycle and so it is still marked as "used". In this case should be seen as used bu the same process, not by another one.
Now I am going to check out the result of the second fclose() as you already suggested.
What do you think?
Alex
Last Visit: 31-Dec-99 18:00 Last Update: 28-Sep-24 5:39