|
|
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
Michael Dunn wrote:
Try this programming help site
John would be so proud
Ryan "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"
|
|
|
|
|
lol, you own
Don't try it, just do it!
|
|
|
|
|
|
DaveE9th wrote:
I'm trying to open a file from a console program. How do I do this?
Are you using the C libraries, STL, MFC or Win32? You need to be more specific in the question.
Ryan "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 have a couple of bmp images. each image is 24*32 unit and all the images make up a stripe. The stripe image's ID is "IDB_ADDRESS". Now i want to use a
CImagelist to manage these images. i codes like this:
m_ImagList.Create(IDB_ADDRESS,24,1,RGB(0,0,0));
IMAGEINFO m_sImageInfo;
m_ImagList.GetImageInfo(2,&m_sImageInfo); // i want to get the no.3 image
m_BtImage1.SetBitmap(m_sImageInfo.hbmImage); // i want to set the no.3 on the
//button
the m_BtImage1 is a CButton control object which has been set the "BS_BITMAP"
But there is nothing on the button,why?
|
|
|
|
|
I'm trying to use VC++ to connect to MySQL. To do this, I have use MFC to do it. Initially it was easy when i was using the form that they have created for me. But when I insert my own form/dialog, I can't seems to see the database field for me to map it. Any idea why is it so?
Also is it better for me to use ATL MyOLEDB??
Noelle
|
|
|
|
|
More info please... Are you using ODBC, ADO, DAO???
John
|
|
|
|
|
At the moment i'm using MyODBC to connect to my database in MySQL.
|
|
|
|
|
|
My MFC app is using comboboxes with the CBS_DROPDOWN style (i.e. edit control + drop list). The combos are defined in a dialog template. I want to be able to switch these to CBS_DROPDOWNLIST style (i.e. static control + drop list).
My difficulty is that I need to change the style AFTER the comboboxes have been created.
(How) can this be done?
Andrew
|
|
|
|
|
m_pComboBox.ModifyStyle(...)
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Hi Eugene,
I just tried your suggestion, but it doesn't work.
My combobox is derived from CComboBox, I have a member function to do the switch
void CMyComboBox::MakeStatic()<br />
{<br />
VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST));<br />
}
I call MakeStatic() after the combo has been created, but immediately before I load the combo. The ModifyStyle() call returns TRUE - the VERIFY doesn't generate an error. I also tried ModifyStyleEx(), just in case, but it doesn't work either
|
|
|
|
|
Andrew Allen wrote:
I just tried your suggestion, but it doesn't work.
My combobox is derived from CComboBox, I have a member function to do the switch
void CMyComboBox::MakeStatic()
{
VERIFY(ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST));
}
I've had this problem myself. What I did was create TWO combobox controls, one a dropdown and the other a dropdown list, and placed them right on top of each other. I used some other control to determine the state I wanted the "combo" in, and showed/hid the appropriate one.
Actually, I had this problem with CListBox. You can't change its selection style at runtime, either.
|
|
|
|
|
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.
|
|
|
|