|
m_imageList is a local variable (not a member, which is what the m_ normally indicates). It gets destroyed at the end of the function, and destroys the underlying image list too.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.10414 AcidHelm
|
|
|
|
|
Michael Dunn:
Thank you very much,You are so kind and smart.
Thank you!
|
|
|
|
|
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();
}
}
}
Thanks all!
-Rune Svendsen
|
|
|
|
|
I have a set of code in VC++ where I feel it takes time to populate the data. How to find out what code is taking lot of time. How to tune it? I don't have profile options in VC++.
|
|
|
|
|
Check out
http://www.codeproject.com/datetime/perftimer.asp#xx21598xx
I have a class which I use in one of my libraries to obtain performance data. All you do is istantiate the class at the beginning of every function call and it measures how long the function takes. My class, though, uses GetTickCount which does not have very good resolution. You might try combining my class with this performance timer.
If you want the class, I'll email it to you. Just drop me an email and I'll forward it to you.
|
|
|
|
|
How can I pass a struct to my thread with AfxBeginThread(..)???
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
take the address of your struct and cast it to a void* when you place it in the pParam parameter.
Then inside of your thread object cast it back to your struct type.
struct POINT
{
long x;
long y;
};
...
POINT pt;
...
afxBeginThread (..., (void*)&pt, ...);
POINT *ptInput = (POINT*)pParam;
The only gotcha, as with all pointers, is that you will want to make sure that the pointer pParam is not NULL before you try to dereference it.
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!
|
|
|
|
|
Then I see why it didn't worked for me!
Thank you kilowatt!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
A piece of advice: don't pass the address of local variables, unless you are sure that they will live beyond the thread's life.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Michel Prévost wrote:
don't pass the address of local variables, unless you are sure that they will live beyond the thread's life.
Your right about that, I was simply trying to demonstrate how to pass the object.
Also if I allocated memory for a pointer to send I really wouldn't have felt good about showing how the pointer could be properly deleted as well and that was just more than I wanted to do
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 just wanted to point that out. You know, that's me
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
What do you mean?
I pass a local struct varible that will assign its two member varibles to two local thread varibles. What is bad with this, or what COULD be bad?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
Your local struct can go out of scope before the thread starts using it.
Hence the pointer you send will point to garbage.
/Magnus
|
|
|
|
|
ummmm well i looked at ishelllink for quite some time and didnt see the start menu bit anywheres
if i'm stupid please forgive me ... am not being lazy
i need to create a start menu short cut from the app if there isnt one there ... didnt seem so hard an idea to implement until i started looking
*sigh*
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
Try doing a search for CreateLink.
About 2/3 through this article is a sample function to Create a shell link, it should give you the answer you want. Of course you still have to find the StartMenu but that is just a call to SHGetSpecialFolderLocation with CSIDL_COMMON_STARTMENU or CSIDL_STARTMENU.
|
|
|
|
|
|
Lauren
You have to locate the start menu folder for the current user and create a short cut in that folder. It will not automatically put it in the right folder for you.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Hi.
I would like to know what function or message I need to implement to determine what item a user selects (if any) from a CListBox in a dialog box. I am referring to single and/or double click. I have implemented a solution for a problem similar to this one, but never in a dialog box.
Thanks,
Kuphryn
|
|
|
|
|
go to classwizard, select the list box you want to watch, and add a handler for the SELCHANGE event.
-c
Cheap oil. It's worth it!
|
|
|
|
|
|
Hi everyone,
I need some advice on a project that I am working on, here's my situation:
I have a Flat File(.txt) serves a my database, it has 3 colums Fld1,Fld2,Fld3, this Flat File contains about 10,000 Records(SORTED Ascending) My program receives a String as a parameter, I need to locate this string in the Flat File if it exist. Ex:
String1 = "MR. & MRS BUTCH"
//Extract each word in this string and search it in the Flat File
What is the fastest way to search each word of String1 in the Flat File? if I use line per line search I imagine how long it will take to move "M" to "B" right?
Please help I really need some advice on what to use and how to use it.
Thanks/Regards
Sidney
|
|
|
|
|
For such small numbers (unless you have extremely large fields) I'd almost suggest just loading the file and then strstr it. But you wanted the fastest way...
I think the fastest solution you can find would be to use gperf to create three separate indices for your "db" loaded into memory. I think that would give you O(1) lookup, and so far no one has beaten that.
|
|
|
|
|
Maybe try this (if your fields are a fixed length):
1) Find the first name in the list
2) Seek to the end of the file and find the last name in the list
3) Guess-timate roughly where your string might be in the list
// psuedo code
StringUpper = String1.Upper();
AvgItemPerLetter = NumItems/26;
NumOfFirstLetter = (int)String1[0] - (int)'A';
StartPosition = NumOfFirstLetter * AvgItemPerLetter;
4) check the string at that position and go forward or backward from there
Like it or not, I'm right.
|
|
|
|
|
Best way I can think of (assuming the list is sorted) is a subdivision technique in which you check the middle item in the list. If the items name is further down the list than the search string we check the term one quater of the way through the file. Then if the quater marker has a "value" less than the string we check the 3/8 mark and so on. Its a trial and improvment technique. Here's some pseudocode
int Find(Array strarray, String searchstring)
{
int count = strarray.GetCount(), pos = 0;
float shiftsize = count;
while(1)
{
shiftsize /= 2;
pos += ((unsigned long)shiftsize)+1
switch(strcmp(strarray[pos], searchstring)
{
case 0: return pos;
case 1:
shiftsize = min(shiftsize, -shiftsize);
break;
case -1:
shiftsize = max(shiftsize, -shiftsize);
break;
}
}
}
So here's a demonstration of how I hope it works: (hope this comes out ok on your browser...)
18 Items
X X X X X X Y X X X X X X X X X X X
Step 1: 10
Step 2: 5
Step 3: 8
Step 4: 6
Step 5: 7 The iterator is looking for the Y among an array of Xs. Here we just keep subdividing the area in which the correct entry potentially lies, until we have the correct answer "cornered". I', not sure how well my pseudocode will work - its only a demo, but this teqnique is FAST it will be able to locate your string in a 4000 entry index in around 12 or 13 steps! A big improvment on systematic search! The efficiency of the routine all depends on how you code it however!
With time we live, with money we spend!
Joel Holdsworth
|
|
|
|
|
Thanks everyone!! I'll try each of your suggestions, I really appreciate it =) if there's somebody else who can contribute any Ideas pls feel free to post.
And yes the fields are fixed length. and yes the data are stored in a Flat File(.txt) so i'm using file manipulations like open and testing for EOF.
Thanks/Regards
Sidney
|
|
|
|