|
i still get the error what file are you looking on to see it on line 152?
|
|
|
|
|
Shlwapi.h line 152.
Steve
|
|
|
|
|
ok i got it working but like i said this is over my head im trying to get it to show the folder i want but i havent figured out what part to change yet to get it right
|
|
|
|
|
Ok, here a crude implementation of the "Dir" DOS command which uses the shell instead of the file APIs:
--------------------------------------------------
// VDir.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <shlobj.h>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
void Go(LPCTSTR pFolder)
{
using namespace std;
USES_CONVERSION;
HRESULT hr;
CComPtr<IMalloc> spAlloc;
hr = SHGetMalloc(&spAlloc);
if (FAILED(hr))
{
cerr << "SHGetMalloc failed!" << endl;
return;
}
CComPtr<IShellFolder> spDesktop;
hr = SHGetDesktopFolder(&spDesktop);
if (FAILED(hr))
{
cerr << "SHGetDesktopFolder failed!" << endl;
return;
}
LPITEMIDLIST pFolderPIDL;
hr = spDesktop->ParseDisplayName(
NULL,
NULL,
T2OLE(pFolder),
NULL,
&pFolderPIDL,
NULL
);
if (FAILED(hr))
{
cerr << "IShellFolder::ParseDisplayName failed!" << endl;
return;
}
CComPtr<IShellFolder> spFolder;
hr = spDesktop->BindToObject(
pFolderPIDL,
NULL,
IID_IShellFolder,
reinterpret_cast<void**>(&spFolder)
);
spAlloc->Free(pFolderPIDL);
if (FAILED(hr))
{
cerr << "IShellFolder::BindToObject failed!" << endl;
return;
}
CComPtr<IEnumIDList> spEnum;
hr = spFolder->EnumObjects(
NULL,
SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN,
&spEnum
);
if (FAILED(hr))
{
cerr << "IShellFolder::EnumObjects failed!" << endl;
return;
}
LPITEMIDLIST pPIDL;
while ( (hr=spEnum->Next(1, &pPIDL, NULL))==S_OK )
{
STRRET Name;
hr = spFolder->GetDisplayNameOf(pPIDL, SHGDN_NORMAL, &Name);
if (SUCCEEDED(hr))
{
LPWSTR pDisplayName;
hr = StrRetToStrW(&Name, pPIDL, &pDisplayName);
if (SUCCEEDED(hr))
{
cout << W2CA(pDisplayName) << endl;
spAlloc->Free(pDisplayName);
}
}
spAlloc->Free(pPIDL);
}
}
int main(int argc, char* argv[])
{
using namespace std;
if (argc<2)
{
cerr << "No directory specified!" << endl;
return 1;
}
OleInitialize(NULL);
Go(argv[1]);
OleUninitialize();
return 0;
}
Steve
|
|
|
|
|
do you have msn or yahoo if so add me or this thread will be a mile long msn: fruitloop45@hotmail.com
yahoo: fruitloop455
|
|
|
|
|
Doesn't matter if the thread gets long. If MSN or some other messaging service is used then other people can't get any benefit from the thread.
Steve
|
|
|
|
|
ok. i took the first one you posted and stuck it in a dialog only changed the cout lines to be MessageBox changed
CComPtr<IShellFolder> spDesktop;<br />
hr = SHGetSpecialFolderPath(m_hWnd , buff, CSIDL_INTERNET_CACHE, 0);
that line to be the folder i want and changed
if (SUCCEEDED(hr))<br />
{<br />
USES_CONVERSION;<br />
file.Format("%s", W2CA(pDisplayName));<br />
m_list.InsertItem(index, file);<br />
spAlloc->Free(pDisplayName);<br />
index++;<br />
}
get a debug assertion in altbase.h line 474 Expression: p!=0
hr = spDesktop->EnumObjects(<br />
NULL,<br />
SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN,<br />
&spEnum<br />
);
has to be in there i have a MessageBox befor and after it first one works
|
|
|
|
|
That's because spDesktop is NULL but you're trying to call a method through it. You commented out the line which sets spDesktop .
Steve
|
|
|
|
|
Try this. The only changes are in 'main':
Also, you should look into 'FindFirstUrlCacheEntry' for an alternative (and perhaps easier) solution.
-----------------------------------------
// VDir.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <shlobj.h>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
void Go(LPCTSTR pFolder)
{
using namespace std;
USES_CONVERSION;
HRESULT hr;
CComPtr<IMalloc> spAlloc;
hr = SHGetMalloc(&spAlloc);
if (FAILED(hr))
{
cerr << "SHGetMalloc failed!" << endl;
return;
}
CComPtr<IShellFolder> spDesktop;
hr = SHGetDesktopFolder(&spDesktop);
if (FAILED(hr))
{
cerr << "SHGetDesktopFolder failed!" << endl;
return;
}
LPITEMIDLIST pFolderPIDL;
hr = spDesktop->ParseDisplayName(
NULL,
NULL,
T2OLE(pFolder),
NULL,
&pFolderPIDL,
NULL
);
if (FAILED(hr))
{
cerr << "IShellFolder::ParseDisplayName failed!" << endl;
return;
}
CComPtr<IShellFolder> spFolder;
hr = spDesktop->BindToObject(
pFolderPIDL,
NULL,
IID_IShellFolder,
reinterpret_cast<void**>(&spFolder)
);
spAlloc->Free(pFolderPIDL);
if (FAILED(hr))
{
cerr << "IShellFolder::BindToObject failed!" << endl;
return;
}
CComPtr<IEnumIDList> spEnum;
hr = spFolder->EnumObjects(
NULL,
SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN,
&spEnum
);
if (FAILED(hr))
{
cerr << "IShellFolder::EnumObjects failed!" << endl;
return;
}
LPITEMIDLIST pPIDL;
while ( (hr=spEnum->Next(1, &pPIDL, NULL))==S_OK )
{
STRRET Name;
hr = spFolder->GetDisplayNameOf(pPIDL, SHGDN_NORMAL, &Name);
if (SUCCEEDED(hr))
{
LPWSTR pDisplayName;
hr = StrRetToStrW(&Name, pPIDL, &pDisplayName);
if (SUCCEEDED(hr))
{
cout << W2CA(pDisplayName) << endl;
spAlloc->Free(pDisplayName);
}
}
spAlloc->Free(pPIDL);
}
}
int main(int argc, char* argv[])
{
using namespace std;
OleInitialize(NULL);
char cache[MAX_PATH];
HRESULT hr = SHGetSpecialFolderPath(NULL, cache, CSIDL_INTERNET_CACHE, 0);
if (FAILED(hr))
{
cerr << "SHGetSpecialFolderPath failed!" << endl;
return 1;
}
Go(cache);
OleUninitialize();
return 0;
}
Steve
|
|
|
|
|
Who can tell me how to get the total pages of excel when using Office Automation in VC++?
_Application excel;
Workbooks books;
_Workbook book;
Sheets sheets;
_Worksheet worksheet;
How can I get page for each sheet?
Thank for your reply.
|
|
|
|
|
_Worksheet worksheet;
Worksheets wssMysheets;
.
.
.
.
LONG mTotal = wssMysheets.GetCount();
LONG mPage =wsMysheet.GetIndex();
freeman
|
|
|
|
|
Sorry, I have made a mistake!
_Worksheet worksheet;
Worksheets wssMysheets;
.
.
.
.
LONG mTotal = wssMysheets.GetCount();
LONG mPage = worksheet.GetIndex();
-- modified at 23:14 Wednesday 25th October, 2006
freeman
|
|
|
|
|
Thank freeman for your replay.
Sorry I do not state very clear about my excel page.
I need to know how many pages if one excel printed.
So the pages should be printed pages.
I know how to calculate the word pages now. But it is not the same as Excel.
If I use VBA, I can use the following word to get it.
pages=(sheet.hpagebreaks.count+1)*(sheet.vpagebreaks.count+1)
or
pages=Workbook.Excel4MacroSheets(50)
|
|
|
|
|
Here I share the function of Word pages to everybody.
//This function shows how to get the pages of word
int Wordpage(char* wordfile)
{
int page;
CoInitialize(NULL);
_Application app;
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(FALSE);
Documents docs=app.GetDocuments();
CComVariant FileName(wordfile);
CComVariant ConfirmConversions(false);
CComVariant ReadOnly(false),AddToRecentFiles(false);
CComVariant PasswordDocument(_T("")),PasswordTemplate(_T(""));
CComVariant Revert(false),WritePasswordDocument(_T(""));
CComVariant WritePasswordTemplate(_T("")), Format(0);
CComVariant Encoding(false),Visible(TRUE);
CComVariant OpenAndRepair(false),DocumentDirection(false);
CComVariant NoEncodingDialog(false);
CComVariant XMLTransform(_T(""));
docs.Open(&FileName,&ConfirmConversions,&ReadOnly, &AddToRecentFiles,&PasswordDocument, &PasswordTemplate, &Revert, &WritePasswordDocument,&WritePasswordTemplate, &Format, &Encoding, &Visible, &OpenAndRepair,&DocumentDirection, &NoEncodingDialog, &XMLTransform);
_Document doc=app.GetActiveDocument();
Range rang=doc.GetContent();
page=rang.GetInformation (4).lVal;//get pages
rang.ReleaseDispatch();
doc.ReleaseDispatch();
docs.ReleaseDispatch();
CComVariant SaveChanges(false),OriginalFormat,RouteDocument;
app.Quit(&SaveChanges,&OriginalFormat,&RouteDocument);
app.ReleaseDispatch();
return page;
}
|
|
|
|
|
Hello. I'm new to C++ so go easy. I'm trying to read from a txt file, but need to do it in a specific way. The txt file will basically be formatted like this:
1111 90 85 50 78 85
2222 100 90 99 89 88
3333 52 85 44 66 87
4444 87 88 95 85 100
where the first number of each line will be a student ID number and the next five numbers are grades they got on 5 different tests. I need to read this file as such and then do stuff with that data. What I don't know is how to read the file and store those numbers in a usable way. The thing is I don't know how many lines the file will have, so I need go all the way to the end of the file. Given this, do I have to create an array for the different inputs from the file, and how do I then differentiate between the student ID numbers and the test grades?
What I have so far is laughable because I simply don't know how to go about this, but here it is:
int id, score1, score2, score3, score4, score5;<br />
ifstream inFile;<br />
inFile.open ("grade.txt", ios::in);<br />
while (!inFile.eof())<br />
{<br />
inFile >> id >> score1 >> score2 >> score3 >> score4 >> score5;<br />
}<br />
inFile.close();
Obviously the while loop isn't done yet because I don't know what to do after I have a line of input from the file. Any help would be awesome.
-- modified at 17:27 Wednesday 25th October, 2006
|
|
|
|
|
q_p wrote: I'm new to C++
Most students are eh?
q_p wrote: Any help would be awesome.
You create a struct or class that encapsulates the data. Then you use a STL (Standard Template Library) vector to dynamically store each one after it is loaded from the file. Or perhaps a "map" rather than "vector" is called for, depends on requirements.
led mike
|
|
|
|
|
Thanks Mike. The problem is, I dunno what any of that even is. We haven't learned this stuff at all. I've basically learned if/else, switch, functions, and arrays... the basic stuff. I figured there's gotta be a simple way to do it with these basic tools that I'm just not seeing, because why would my professor give me a project about things she hasn't taught?
|
|
|
|
|
Generally, I wouldn't actually give you as much as I did below, but I'd rather see someone start off on the right foot than to learn bad habits from the start. What is posted below should get you started.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
q_p wrote: if/else, switch, functions, and arrays
Well then I guess it will be using arrays since "if/else, switch and functions" can't store any information for you.
Good luck!
led mike
|
|
|
|
|
Here is the most flexible way:
#include <vector>
#include <algorothm>
#include <iterator>
#include <fstream>
class Student
{
Student() : _StudentID(0) {}
~Student() {}
void setStudentID(long id) {_StudentID = id; }
long getStudentID() const { return _StudentID; }
std::vector<long>::iterator grades_begin() { return _Grades.begin(); }
std::vector<long>::iterator grades_end() { return _Grades.end(); }
void addGrade(long grade) {_Grades.push_back(grade); }
void addGrades(const std::vector<long>& grades) { _Grades.insert(back_inserter(_Grades), grades.begin(), grades.end()); }
unsigned long grade_count() const { return _Grades.size(); }
private:
long _StudentID;
std::vector<long> _Grades;
};
ostream& operator<<(ostream& os, const Student& s)
{
os << s.getStudentID() << " ";
copy(s.begin(), s.end(), ostream_iterator<long>(os, " "));
os << endl;
return os;
}
istream& operator>>(istream& is, Student& s)
{
long id;
std::vector<long> grades;
is >> id;
copy(istream_iterator<long>(is), istream_iterator<long>(), back_inserter(grades));
s.setStudentID(id);
s.addGrades(grades);
return is;
}
int main()
{
ifstream fin;
fin.open("mydata.txt");
std::vector<Student> students;
copy(istream_iterator<Student>(fin), istream_iterator<Student>(), back_inserter(students));
fin.close();
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
So Zac... back in school again are you?
led mike
|
|
|
|
|
Yeah, I was bored ... and it was the end of the day. Even I can be generous sometimes ...
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks a lot Zac I really appreciate that and can appreciate you not wanting to give me the solution straight up. Normally I can think these things through myself and figure it out, but I was having a serious mental block. After Mike's post though something clicked and I figured it out - I can simply do everything I need to do within the while loop after reading each separate line, so I don't need to store each number separately, I can just store them one line at a time. Basically I was making things a whole lot more complicated than they had to be... Thanks a lot for the replies! It's good to know there are fast replying helpful people here.
|
|
|
|
|
While it is useful to know how to write your own loops, most of the time if you are writing your own loops you should rethink your implementation. The STL algorithms do a lot for you and can help simplify your code (once you get use to the template syntax). Depending on what your professor is expecting, you may or may not want to go that route.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
HI g_p,
i still prefer that you write your own code.. actually Zac code's looks like to be highly proffessional and you as you have said know only basic.. your teacher will caught you very easily.. i my opinion you should read file line by line and use strtok function and atoi function to fetch data from that files!.....
hope you will give the try!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|