|
Hello everyone !
I want to find some files in the whole disk drive , the code like this :
void C***Dlg::EmuFiles(CString strPath, CString strType)
{
WIN32_FIND_DATA data;
CString csPath(strPath);
csPath = csPath + "\\*." +strType;
HANDLE handle = FindFirstFile((LPCSTR)csPath,&data);
BOOL ret = (BOOL)handle;
while(ret)
{
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(data.cFileName[0] != '.')
{
csPath = strPath;
csPath +="\\";
csPath += data.cFileName;
EmuFiles(csPath,strType);
}
}
else
{
csPath = strPath;
csPath +="\\";
csPath += data.cFileName;
m_ListBox.InsertString(nCount,csPath);
m_ListBox.SetCurSel(nCount);
m_nTotal = nCount;
UpdateData(FALSE);
nCount ++;
}
ret = FindNextFile(handle,&data);
}
FindClose(handle);
}
when I use EmuFiles("C:\WINDOWS","exe"), it can be found.
but if I use EmuFiles("C:","exe"),it can't be found as more.
how to set the WIN32_FIND_DATA's parameters to find whole disk?
|
|
|
|
|
You should ideally be calling it as
EmuFiles(_T("C:\\Windows"), _T("exe"));
and
EmuFiles(_T("C:"), _T("exe"));
|
|
|
|
|
wangningyu wrote:
HANDLE handle = FindFirstFile((LPCSTR)csPath,&data);
BOOL ret = (BOOL)handle;
What in the world is this? If FindFirstFile() fails, it will return -1 , thus assigning TRUE to ret .
wangningyu wrote: UpdateData(FALSE);
While I would not use this at all, I especially would not use it in a loop.
wangningyu wrote: when I use EmuFiles("C:\WINDOWS","exe"), it can be found.
This should not even compile.
wangningyu wrote: ...it can't be found as more.
Which means what exactly? Do you have any .exe files/folders in your root folder?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
Don't use the extension as the parameter for FindFirstFile/FindNextFile, use "*.*" and then filter out the files with the extension you're looking for. This is probably also the reason why it doesn't recurse into directories.
|
|
|
|
|
but MS only give us this function to find files .
any else ?
|
|
|
|
|
You lost me.
Anyway, try something like this:
BOOL EnumFilesRecursive(CString csStartDir)
{
CString csCurFile;
CString csDir = csStartDir;
if (csDir.Right(1) != "\\")
csDir += "\\";
csDir += "*.*";
CFileFind ff;
BOOL bWorking = ff.FindFile(csDir);
while (bWorking == TRUE)
{
bWorking = ff.FindNextFile();
if (ff.IsDirectory())
{
if (ff.IsDots())
continue;
EnumFilesRecursive(ff.GetFilePath());
}
else
{
csCurFile = ff.GetFilePath();
}
}
return TRUE;
}
Edit: code corrected.
modified on Wednesday, December 16, 2009 11:12 AM
|
|
|
|
|
A directory is just a special kind of file.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
i've a question(hypothetical situation):
There are two class
class1 with a void funct_cl1()and other methods;
(class1 use observer paradigm, funct_cl1 will be called with high frequency)
class2 is a thread with some functions;
In class2 i initialized class1 pointer like this: class1* cls1 = new class1() and i use some method of its but never funct_cl1.
if i put in pause (p.e with a long sleep) the thread of class2, the funct_cl1 belong to cls1 can be anyway executed with observer paradigm or is it block?
Regards
Marco
|
|
|
|
|
Hi Marco, I try an answer.
Yes you can call a method from another thread, any object can be accessed from other threads. The real question is if the called functionality will be multithreading safe. Maybe this isn't even an issue in your case and you just wondered about ownership: Sleep() will only stop execution of one thread, but not prevent memory access from other threads. For example if class 2 creates an object of class1, which then is only used/called from another thread context, you don't even have to worry about multithreading (as long as lifetime of "class2 object thread" is longer than "class1 object thread").
Hope it helps
/M
|
|
|
|
|
|
My program contains a ListControl(common control ).
I use LVS_EX_DOUBLEBUFFER style in window XP, it works well,
but it has flicker problem in window Vista and window 7.
Anyone know why this happen?
Thanks for your help.
|
|
|
|
|
HI all,
i am struggling to create CIPAddressCtrl . i cannot use drag and driop as i am not using Cdialog, i have craeted a window using CFrameWindow.
have any one done this successfully.
here i could just see a edit control kind of thing when i create
CIPAddressCtrl IpAddr;
IpAddr.Create(.....);
dont know whats wrong.
any help will be gret for me..
Thanks
|
|
|
|
|
Try this.
1)Please check the return value from IpAddr.Create(.....); function.
2)Make sure that CIPAddressCtrl IpAdd is not a local variable to a function. This will destroy object after function call.
HTH
Abhi
|
|
|
|
|
The VS2008 toolbar stuff is driving me nuts. The SetButtonInfo() call now seems to take an image index as 4th parameter rather than a width. I can create an embedded combobox if the button is set to TBBS_SEPARATOR but the combo overpaints the drop-arrow used to customise the toolbar. Anyone got an example that works?
Thx++
Jerry
|
|
|
|
|
Hi,
I've got an application with 3 dialogs: Monitor, UnitView, GroupStart. Each dialog has it's class named accordingly. Monitor is a main dialog which opens at the start of application. By clicking button on Monitor dialog you can open UnitView dialog. It is done like that:
<br />
unitviewdialog[selection] = new CUnitView();<br />
unitviewdialog[selection]->SetParent(this);<br />
<br />
unis[selection] = new CDlgModalToModeless();<br />
unis[selection]->DoDialog(unitviewdialog[selection]);<br />
Then on UnitView dialog you can click on next button to open GroupStart dialog:
<br />
CGroupStart* dlg = new CGroupStart(this);<br />
<br />
dlg->DoModal();<br />
delete dlg;<br />
There is a function SendMsg() which is public member of CMonitorDlg class, and which I need to use. I mean I have to call it from function which is public member of CGroupStart class.
Here is first few lines of this function:
<br />
BOOL CMonitorDlg::SendMsg(int destination, char *typec, char *content)<br />
{<br />
<br />
int sum = 0; <br />
<br />
coutbuff[0] = STX; <br />
coutbuff[1] = '0';<br />
coutbuff[2] = '0';<br />
coutbuff is declared as char[410] and is public member of CMonitorDlg class.
Now - I'm calling this function from CGroupStart like that:
<br />
void CGroupStart::OnGstart() <br />
{<br />
char grpcmd[5];<br />
<br />
if (groupid<0 || groupid>20)<br />
return;<br />
<br />
sprintf (grpcmd,"%d;1",groupid);<br />
<br />
((CMonitorDlg*)m_pWnd)->SendMsg(unit, "MO", grpcmd);<br />
<br />
The application crashes at this moment with Access Violation error.
I tried to run it under debugger, step by step and it took me to second line of SendMsg() function where it tries to assign STX to coutbuff[0]. So it looks like it cannot access coutbuff.
What am I doing wrong?
I'm using VC++ 6.0.
|
|
|
|
|
blackbolek wrote: ((CMonitorDlg*)m_pWnd)->SendMsg(unit, "MO", grpcmd);
The application crashes at this moment with Access Violation error.
Are you sure that m_pWnd is a CMonitorDlg ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Here is my declaration of m_pWnd for GroupStart class:
<br />
private:<br />
CDialog* m_pWnd;<br />
When I change it for:
<br />
private:<br />
CMonitorDlg* m_pWnd;<br />
it's still the same error in the same place. So it doesn't change anything.
m_pWnd is not 'initialized' anywhere. How should I initialize it?
modified on Tuesday, December 15, 2009 10:37 AM
|
|
|
|
|
blackbolek wrote: It's not 'initialized' anywhere. How should I initialize it?
I think you should really learn a bit more about the concept of classes in C++. This is really basic C++ stuff.
You have to pass an instance of your dialog to the GroupStart class (but instead of the generic CDialog, use a pointer to a CMonitorDlg instead, this way you won't need to cast). This is typically done in the constructor: you add an additional parameter in the constructor of GroupStart (and when you conctruct it from CMonitorDlg, you simply pass the this pointer).
|
|
|
|
|
Yes - that sorted the problem.
Thank you very much for your help.
|
|
|
|
|
In addition to Devaid's answer, how did you initialize m_pWnd ? Are you sure it is not null ?
|
|
|
|
|
I am Having a Virtual List Control,with 5 columns.if i double clock on the first column i want to sort the list by that column,& if i clicked on second column i want to sort it by that column & till the last column. how i can accomplish this.Can i get a simple example of this
|
|
|
|
|
As far as i know virtual list controls do not provide you with any means of sorting, you have to do it yourself. If the user clicks a column header you get a LVN_COLUMNCLICK[^] notification from your list control (i don't know about doubleclick, look around List View[^] in MSDN), upon this message you should/need to sort your data yourself (using some nice sorting algorithm like Quick-sort[^]) and then redraw the list items. Good luck.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
hi all,
Actaully my Question seems to be silly but i just wanted to know can i set the same key accelerators to two ID's i.e if i have popup menu lock and unlock a object than if my accelerator is Ctrl+L then on first press of Ctrl+L it should lock object and agian on second time keypress it should unlock it... for lock and unlock the id's are different
Thanks
Samir
|
|
|
|
|
Hi Samir! Assign Ctrl+L to ID_APP_OBJECT_TOGGLE , and write a command handler that toggles the object (lock/unlock object depending on current state). Does that work for you?
Hope it helps.
/M
|
|
|
|