|
Yep, I'm convinced ModifyStyle() doesn't work after the control has been created. I just found this article talking about Listboxes,
http://www.codeproject.com/combobox/listbox_tut.asp[^]
...
Changing List box Styles at Runtime
It is not possible to change these styles at runtime even though ModifyStyle() may give the impression it does. If you want turn the Sort style on and off for example it is best to construct the List box by calling new and Create then deleting it and creating a new one when the style is to be changed. Alternatively you can have 2 List box superimposed and hide the one with the incorrect style.
I already thought about overlapping two controls, but I have about 10 in my dialog and at the time it seemed messy in the dialog template. Looks like that's what I'll do.
thanks for your help!
|
|
|
|
|
Can someone supply me the code required to iterate through a list of files in folders and sub-folders???
Using SDK calls, not MFC CFileFind class...
Thanks
I'm drinking triples, seeing double and acting single
|
|
|
|
|
This is what I use, but I'm looking into moving to the Boost::filesystem library to do platform independant directory iteration.
#include "io.h"
class CFileSpec : public _finddata_t {
long m_hfile;
public:
CFileSpec() {
m_hfile = -1;
}
~CFileSpec() {
if (m_hfile>=0)
_findclose(m_hfile);
}
bool First(const char* filespec) {
if (m_hfile>=0)
_findclose(m_hfile);
return (m_hfile=_findfirst((char*)filespec, this)) != -1;
}
bool Next() {
return m_hfile>=0 && _findnext(m_hfile, this)==0;
}
};
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I'm not sure if thats really what I needed. What i'm looking for is how would you iterate a folder and it's sub-folders returning all the files until no more folders or files are left?
I"m confused about how to determine that when a directory has been found, what do you do then? Do files always preceed folders when searching?
Like if the directory i'm searching has has say 10 files and 3 folders each folder has 3 more sub folders. If on the third iteration I determine the file is actually a folder, do I open that folder then, and begin to add files that are in the folder, complete that and go back to where I left off???
Do I need a fancy stack to keep track of things?
Unless folders always come after or before files the code to traverse the file structure(required to fill a tree control with folders and files) must be very confusing????
I can't figure it out anyways...
Thanks
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Sorry, that was the code for a single directory, but it's not hard to extend it for multiple directories.
FileSearch.h
#include <string>
#include "FileSpec.h"
class IFileParser
{
public:
virtual void onFile(std::string str, std::string type) = 0;
virtual void onFilesDone() = 0;
virtual void onEnterDir(std::string str) = 0;
virtual void onExitDir(std::string str) = 0;
virtual ~IFileParser() {}
};
class FileParserAdapter : public IFileParser
{
public:
virtual void onFile(std::string str, std::string type) {}
virtual void onFilesDone() {}
virtual void onEnterDir(std::string str) {}
virtual void onExitDir(std::string str) {}
virtual ~FileParserAdapter() {}
};
class FileSearch
{
public:
FileSearch();
~FileSearch();
void findFiles(const std::string& path, const std::string& type, IFileParser& parser);
private:
void addFiles(const std::string& path, const std::string& type, IFileParser& parser);
};
FileSearch.cpp
#include "FileSearch.h"
using namespace std;
FileSearch::FileSearch()
{
}
FileSearch::~FileSearch()
{
}
void FileSearch::addFiles(const string& path, const string& type, IFileParser& parser)
{
CFileSpec spec;
string search = path + "\\" + type;
for (bool more=spec.First(search.c_str()); more; more=spec.Next())
{
if( !(spec.attrib & _A_SUBDIR) )
{
parser.onFile( spec.name, type );
}
}
}
void FileSearch::findFiles(const string& path, const string& type, IFileParser& parser )
{
parser.onEnterDir( path );
addFiles(path, type, parser);
parser.onFilesDone();
CFileSpec spec;
string search = path + "\\*.*";
string result;
for (bool more=spec.First(search.c_str()); more; more=spec.Next())
{
if( (spec.attrib & _A_SUBDIR) )
{
result = spec.name;
if( (result != ".") && (result != "..") )
{
result = path + "\\" + spec.name;
findFiles(result, type, parser );
}
}
}
parser.onExitDir( path );
}
Here's a sample usage to help with the renumbering of files 1.jpg - 01.jpg.
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <sstream>
#include "FileSearch.h"
using namespace std;
bool smart_comp(const string& a, const string& b)
{
if(a.length() != b.length())
{
return a.length() < b.length();
}
else
{
return a < b;
}
}
class WFileParserAdapter : public FileParserAdapter
{
public:
virtual void onFile(std::string str, std::string type)
{
files_.push_back(str);
}
virtual void onFilesDone()
{
cout << dirs_.top() << endl;
sort(files_.begin(),files_.end(),smart_comp);
for(int i = 0; i < files_.size(); i++)
{
string from = dirs_.top() + "\\" + files_[i];
ostringstream oss;
oss << dirs_.top() << "\\" ;
if(i+1 < 10)
{
oss << 0;
}
oss << i+1 << ".jpg";
string to = oss.str();
cout << from << " -> " << to << endl;
rename(from.c_str(),to.c_str());
}
files_.clear();
}
virtual void onEnterDir(std::string str)
{
dirs_.push(str);
}
virtual void onExitDir(std::string str)
{
dirs_.pop();
}
virtual ~WFileParserAdapter() {}
private:
vector<string> files_;
stack<std::string> dirs_;
};
int main()
{
FileSearch g;
vector<string> v;
v.push_back("*.jpg");
v.push_back("*.html");
v.push_back("*.txt");
string path = "C:\\";
g.findFiles(path, "*.jpg", WFileParserAdapter());
return 0;
}
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
thanks
I'm drinking triples, seeing double and acting single
|
|
|
|
|
I am having problem creating a simple C++ MFC Application using Visual C++ .NET with database support. For database, I use ODBC and selected an Oracle table. Here is the error message:
Microsoft Development Environment
Error occurred while converting the wizard's text to the code page of the existing text in the file: C:\Excercise\db4\db4Set.h
However, if I select a desktop database, for example, a DBF file, the problem does not occur.
Eilzabeth
|
|
|
|
|
I need to catch file system updates for my directory tree
control - that is to say, if anything modifies the directory
tree while my user is browsing, I need to know so he gets
to see the updated view.
So, is there some kind of callback to say "let me know if
the filesystem changes and how" or is there a windows message
that I should be catching?
I know some apps you seem to have to hit Refresh (F5) to get
the system to pickup changes, but I've seen others that seem
to change on the fly and I assume a windows message or a callback was involved. I'm just a little lost on what to look in MSDN for...
|
|
|
|
|
|
*heh!*
Well, it's a nice solution. But it won't work for me. Target platform support is insufficient (I have to support good old
win98 in addition to 2K/XP). But this looks like the way one
would *prefer* to go if one had his druthers, I admit.
Thanks, another good post.
|
|
|
|
|
In that case use the good old fashioned timer and poll the directory structure checking the last time modified date of all the files if "my" solution is unavailbale by checking the OS version. You may be able to get away by just checking the sub directory date/time instead of all the files.
Or for 95/98 add a F5 refresh key!
Hopefully there won't be too many 95/98 systems around
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
start a thread the block it waiting for the hNotify handle to be valid
HANDLE hNotify = FindFirstChangeNotification(_T("C:\\Monitor_this_folder"), TRUE,
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE);
while(g_bContinue)
{
WaitForSingleObject(hNotify, INFINITE);
PostMessage(ptr_lparam.hWnd, WM_EX_CHANGENOTIFICATION, 0, 0);
FindNextChangeNotification(hNotify);
}
FindCloseChangeNotification(hNotify);
I got this example from chapter 7 of Windows Shell programming, D. Espisito
you can download on amazon in PDF format
http://images.amazon.com/images/P/B000063UL1.01.LZZZZZZZ.jpg[^]
There's no more in print, yet I have a hard copy!!!
|
|
|
|
|
Beer said:
start a thread the block it waiting for the hNotify handle to be valid
HANDLE hNotify = FindFirstChangeNotification(_T("C:\\Monitor_this_folder"), TRUE,
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME |
FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE);
Tomb replies:
I'd seen that function.... so it seems my suspicion is confirmed. Will this notify you of changes in subdirs? (ie if I set it for c:\\* (root folder), will it notify of changes in any child dir? or do I have to somehow monitor every folder concurrently (and if so, is there a good way to do this as a whacking pile of threads might not be an ideal choice.... maybe some sort of multiple object wait?)
This looks like what I'm wanting thought.
Thanks muchly.
|
|
|
|
|
kaladorn wrote:
Will this notify you of changes in subdirs? (ie if I set it for c:\\* (root folder), will it notify of changes in any child dir?
Yes, it will, you really should just buy Dino's book, it's full of good stuff.
I'll even let you in on how I got a hard copy of it even though it's out of print!
I bought it used from one of those amazon.com used book dealers. It only cost me thirty bucks too!
If you do any type of shell programming targeted at win98->XP, this book is a must have, you will end up using it for countless numbers of things.
|
|
|
|
|
I'll hunt for the book. I always like buying books that have lasting value and a solid testimonial from someone in the field helps convince me (where I haven't personally seen or leafed the book). I just hate shelling out money for books that quickly obsolesce.
Thanks again!
Tomb
|
|
|
|
|
|
PS: in that example of his you have to type the path of a folder in the edit box, or it the empty field will cause it to crash.
|
|
|
|
|
can anyone help with this function parameters, i cant get them at all
"AdjustTokenPrivileges"
|
|
|
|
|
Security structures in the Windows API tend to be of the 'extensible array' type, where the last field is declared as an array of 1 element, but Windows will actually accept bigger arrays. You can consider the structure you declare as being a header for the full structure.
Let's say, for the sake of argument, that you want to disable the SE_TAKE_OWNERSHIP_NAME privilege (which permits the principal to change the owner of a resource, even if they don't have Write Owner access) and the SE_DEBUG_NAME privilege, which permits the principal to debug processes they don't own.
You would write something like the following:
DWORD dwPrivsSize =
sizeof( DWORD ) + 2 * sizeof( LUID_AND_ATTRIBUTES );
TOKEN_PRIVILEGES* pPrivsIn =
(TOKEN_PRIVILEGES*) malloc( dwPrivsSize );
pPrivsIn->PrivilegeCount = 2;
LookupPrivilegeValue(
NULL,
SE_TAKE_OWNERSHIP_NAME,
&( pPrivsIn->Privileges[0].Luid )
);
LookupPrivilegeValue(
NULL,
SE_DEBUG_NAME,
&( pPrivsIn->Privileges[1].Luid )
);
pPrivsIn->Privileges[0].Attributes = 0;
pPrivsIn->Privileges[1].Attributes = 0;
HANDLE hToken = NULL;
OpenThreadToken(
GetCurrentThread(),
TOKEN_ADJUST_PRIVILEGES,
FALSE,
&hToken
);
AdjustTokenPrivileges(
hToken,
FALSE,
pPrivsIn,
dwPrivsSize,
NULL,
NULL
);
CloseHandle( hToken );
free( (void*) pPrivsIn ); You should save the previous state of the privileges somewhere if you want to re-enable them later. You should also check the return values of all the functions called - this is especially critical in security code.
No warranties for the above code; I just typed it straight into CP's editor
On Server 2003, you can specify SE_PRIVILEGE_REMOVED for the attributes to cause AdjustTokenPrivileges to remove the privileges from the token permanently - they cannot be re-enabled except by creating a new token.
|
|
|
|
|
Hi im writing a dialog based program in mfc ive made a large icon for it and it displays fine for the exe however if i add the program to my quick launch or go to it in a file dialog it shows the default mfc small icon how do i set the small icon for the exe? the regular icon works fine within the program on the system menu so whats the deal why isnt the exe's small icon being set?
Thanks
|
|
|
|
|
In the VC++6 ide, bring up your icon in the resource editor then click on the combo box next to where it says "Device:" above the icon you have open.
Now select Small (16X16) and edit it to your liking.
|
|
|
|
|
Hi
Anyone knows a fn that shut down the pc?!
thanks in advance
|
|
|
|
|
ExitWindowsEx() is the way to go
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks but i tried it, but it only causes the pc to log off, i'm trying it with win XP...
|
|
|
|
|
ExitWindowsEx(EWX_POWEROFF,0)
Here are some notes about using it:
Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
Windows NT/2000/XP: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege.
John
|
|
|
|