|
Maybe I can not express myself.I mean that I want to develop a ActiveX control container.
Firstly, my document CxxDoc is derived from COleDocument,and the constructor as following:
CxxDoc::CxxDoc()
{
// EnableCompoundFile();
// ^^^^^^^^^^^^^^^^^^^^^^^^^^I need a flat (uncompound) file.
...
}
Is it OK????
Secondly,my client item is CxxClientItem
class CxxClientItem : public COleClientItem
The WriteItem and ReadItem function (copied from the sample program of ActiceX control test container in Visual C++) as follows. They can work correctly in compound document. Please tell me how to change them from compound document to flat(uncompound) document.
void CxxClientItem::WriteItem( CArchive& ar )
{
USES_CONVERSION;
IStoragePtr pStorage;
IStreamPtr pStream;
IPersistStreamInitPtr pPSI;
TCHAR szItemName[64];
HRESULT hResult;
IPersistStoragePtr pPersistStorage;
CxxDoc* pDoc;
CLSID clsid;
(void)ar;
pDoc = GetDocument();
ASSERT_VALID( pDoc );
ASSERT( pDoc->m_lpRootStg != NULL );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document
ASSERT( pDoc->m_bCompoundFile );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document
ASSERT( m_lpStorage != NULL );
ASSERT( !ar.m_bForceFlat );
GetItemName( szItemName );
if( !pDoc->m_bSameAsLoad )
{
hResult = pDoc->m_lpRootStg->CreateStorage( T2COLE( szItemName ),STGM_CREATE|STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_EXCLUSIVE, 0, 0, &pStorage );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
m_lpNewStorage = pStorage;
m_lpNewStorage->AddRef();
m_bNeedCommit = TRUE;
}
else
{
pStorage = m_lpStorage;
}
pPersistStorage = m_lpObject;
if( pPersistStorage != NULL )
{
pPersistStorage->GetClassID( &clsid );
hResult = WriteClassStg( pStorage, clsid );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
hResult = pPersistStorage->Save( pStorage, pDoc->m_bSameAsLoad );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
}
else
{
pPSI = m_lpObject;
if( pPSI == NULL )
{
AfxThrowOleException( E_NOINTERFACE );
}
// Set the storage's CLSID to CLSID_NULL, so we know that we actually
// used a stream
hResult = WriteClassStg( pStorage, CLSID_NULL );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
hResult = pStorage->CreateStream( L"Contents", STGM_CREATE|
STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
pPSI->GetClassID( &clsid );
hResult = WriteClassStm( pStream, clsid );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
hResult = pPSI->Save( pStream, TRUE );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
pStream.Release();
}
m_bNeedCommit = TRUE;
pStorage->Commit( STGC_ONLYIFCURRENT );
}
void CxxClientItem::ReadItem( CArchive& ar )
{
USES_CONVERSION;
BOOL tUsedStream;
IStoragePtr pStorage;
IPersistStreamInitPtr pPSI;
IStreamPtr pStream;
TCHAR szItemName[64];
HRESULT hResult;
BOOL tQuickActivated;
IPersistStoragePtr pPersistStorage;
CLSID clsid;
(void)ar;
CxxDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
ASSERT(pDoc->m_lpRootStg != NULL);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document ASSERT(pDoc->m_bCompoundFile);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document
ASSERT(m_lpStorage == NULL);
ASSERT(m_lpLockBytes == NULL);
ASSERT( !ar.m_bForceFlat );
// get item name
GetItemName( szItemName );
// open storage for this item
hResult = pDoc->m_lpRootStg->OpenStorage( T2COLE( szItemName ), NULL,
STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_EXCLUSIVE, 0, 0, &pStorage );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^It is wrong in uncompound document
if( hResult != S_OK )
{
TRACE1( "Warning: unable to open child storage %s.\n", szItemName );
// upon failure throw file exception (item will be cleaned up)
AfxThrowOleException( hResult );
}
ASSERT(pStorage != NULL);
// remember the storage
m_lpStorage = pStorage;
ASSERT(m_lpStorage != NULL);
m_lpStorage->AddRef();
// attempt to load the object from the storage
hResult = ReadClassStg( m_lpStorage, &clsid );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
tUsedStream = FALSE;
if( clsid == CLSID_NULL )
{
hResult = m_lpStorage->OpenStream( L"Contents", NULL, STGM_READ|
STGM_SHARE_EXCLUSIVE, 0, &pStream );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
hResult = ReadClassStm( pStream, &clsid );
if( FAILED( hResult ) )
{
AfxThrowOleException( hResult );
}
tUsedStream = TRUE;
}
m_tExtendedControl = TRUE;
hResult = CExtendedControl::CreateInstance( clsid, this, NULL,
IID_IOleObject, (void**)&m_lpObject );
if( FAILED( hResult ) )
{
m_tExtendedControl = FALSE;
// The control may not like being aggregated on, so just try to create it
// directly and punt the extended control stuff.
hResult = CoCreateInstance( clsid, NULL, CLSCTX_INPROC_SERVER|
CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER, IID_IOleObject,
(void**)&m_lpObject );
if( SUCCEEDED( hResult ) )
{
TCControlTrace( TRACELEVEL_NORMAL, this,
"Could not aggregate on the control, so it won't support extended properties.\n" );
}
}
if( SUCCEEDED( hResult ) )
{
CString strUserType;
GetUserType( USERCLASSTYPE_SHORT, strUserType );
GetDocument()->CreateUniqueItemName( this, strUserType,
m_strDisplayName );
}
if( m_tExtendedControl )
{
m_pExtendedControl = m_lpObject;
ASSERT( m_pExtendedControl != NULL );
m_pExtendedControl->Name = _bstr_t( m_strDisplayName );
}
if( SUCCEEDED( hResult ) )
{
hResult = InitControlInfo();
}
tQuickActivated = FALSE;
if( SUCCEEDED( hResult ) )
{
tQuickActivated = QuickActivate();
if( !tQuickActivated )
{
m_lpObject->GetMiscStatus( DVASPECT_CONTENT, &m_dwMiscStatus );
if( m_dwMiscStatus&OLEMISC_SETCLIENTSITEFIRST )
{
hResult = m_lpObject->SetClientSite( GetClientSite() );
if( FAILED( hResult ) )
{
TCControlTrace( TRACELEVEL_NORMAL, this,
"SetClientSite failed.\n" );
}
}
}
}
if( SUCCEEDED( hResult ) )
{
pPersistStorage = m_lpObject;
if( pPersistStorage != NULL )
{
hResult = pPersistStorage->Load( m_lpStorage );
}
else
{
if( !tUsedStream )
{
hResult = E_NOINTERFACE;
}
else
{
pPSI = m_lpObject;
if( pPSI == NULL )
{
hResult = E_NOINTERFACE;
}
else
{
hResult = pPSI->Load( pStream );
}
}
}
}
if( SUCCEEDED( hResult ) )
{
if( !tQuickActivated )
{
if( !(m_dwMiscStatus&OLEMISC_SETCLIENTSITEFIRST) )
{
hResult = m_lpObject->SetClientSite( GetClientSite() );
if( FAILED( hResult ) )
{
TCControlTrace( TRACELEVEL_NORMAL, this,
"SetClientSite failed.\n" );
}
}
}
}
CheckGeneral(hResult);
}
-- modified at 4:04 Thursday 8th September, 2005
|
|
|
|
|
I tried as bellow,but I think it doesn't work correctly.
Who knows how?? Thank you very much.
IHTMLDocument2 * pDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;
long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
try
{
pDoc = (IHTMLDocument2*)(GetHtmlDocument());
if(pDoc!=NULL)
{
pDoc->get_frames(&pFramesCollection);
if(pFramesCollection!=NULL)
{
pFramesCollection->get_length(&p);
if(p>0)
{
for(int i=0; i<p; i++)
="" {
="" varindex.lval="i;"
="" if(pframescollection-="">item(&varindex, &varresult) ==S_OK)
{
lpDispatch=(LPDISPATCH)varresult.ppdispVal;
if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd)))
{
if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc)))
{
BSTR bstr=NULL;
HRESULT hr=pFrameDoc->get_URL(&bstr);
ASSERT(SUCCEEDED(hr));
CString str= bstr;
SysFreeString(bstr);
pFrameDoc->Release();
pFrameDoc=NULL;
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
}
}
}
}
catch(...)
{
};
try
{
if(pDoc != NULL)
pDoc->Release();
if(pFramesCollection != NULL)
pFramesCollection->Release();
}
catch(...)
{
};
|
|
|
|
|
Code above doesn't look well . I paste it again .
IHTMLDocument2 * pDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IHTMLDocument2 * pFrameDoc=NULL;
IHTMLFramesCollection2 *pFramesCollection=NULL;
LPDISPATCH lpDispatch;
long p;
VARIANT varindex,varresult;
varresult.vt=VT_DISPATCH;
varindex.vt = VT_I4;
try
{
pDoc = (IHTMLDocument2*)(GetHtmlDocument());
if(pDoc!=NULL)
{
pDoc->get_frames(&pFramesCollection);
if(pFramesCollection!=NULL)
{
pFramesCollection->get_length(&p);
if(p>0)
{
for(int i=0; i<p; i++)
="" {
="" varindex.lval="i;"
="" if(pframescollection-="">item(&varindex, &varresult) ==S_OK)
{
lpDispatch=(LPDISPATCH)varresult.ppdispVal;
if (SUCCEEDED(lpDispatch->QueryInterface(IID_IHTMLWindow2, (LPVOID *)&pHTMLWnd)))
{
if(SUCCEEDED(pHTMLWnd->get_document( &pFrameDoc)))
{
BSTR bstr=NULL;
HRESULT hr=pFrameDoc->get_URL(&bstr);
ASSERT(SUCCEEDED(hr));
CString str= bstr;
SysFreeString(bstr);
pFrameDoc->Release();
pFrameDoc=NULL;
}
pHTMLWnd->Release();
pHTMLWnd=NULL;
}
}
}
}
}
}
}
catch(...)
{
};
try
{
if(pDoc != NULL)
pDoc->Release();
if(pFramesCollection != NULL)
pFramesCollection->Release();
}
catch(...)
{
};
|
|
|
|
|
It works perfect for me.
What's wrong?
"tous les sifflets des trains, toutes les sirènes des bateaux
m'ont chanté cent fois la chanson de l'Eldorado"
rechi+
|
|
|
|
|
which site did you use for a test?
I would like to have a try.
Thank u.
|
|
|
|
|
|
I am still using this 2024. Your example is useful and helped me through the jungle. i is an integer not a string. varindex.lval = i;
Than things are working, already. Maybe someone else can use.
|
|
|
|
|
can someone please rewrite this program using a class in a .h file
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
const int MAX_PROPERTIES = 50;
struct property
{
string address;
string suburb;
int price;
};
int readFile(property properties[]);
int menu();
void listAll(property properties[], int items);
void search(property properties[], int items);
void addProperty(property properties[], int &items);
void saveProperties(property properties[], int items);
int main()
{
int option = 0;
bool done = false;
int items = 0;
property properties[MAX_PROPERTIES];
items = readFile(properties);
do
{
option = menu();
switch (option)
{
case 1: listAll(properties, items); break;
case 2: search(properties, items); break;
case 3: addProperty(properties, items); break;
case 4: saveProperties(properties, items); break;
case 5: done = true; break;
default: cout << "Illegal menu option" << endl;
}
} while(!done);
return 0;
}
//
// Read the property listing file
//
int readFile(property properties[])
{
string filename;
string remainder;
int items = 0;
cout << "Enter property filename: ";
cin >> filename;
getline(cin, remainder);
ifstream fin(filename.c_str());
if (!fin.is_open())
{
cout << "File \""<< filename << "\" does not exist" << endl << endl;
exit(1);
}
for (int i = 0; i < MAX_PROPERTIES && fin.peek()!= -1; i++)
{
getline(fin, properties[i].address);
getline(fin, properties[i].suburb);
fin >> properties[i].price;
getline(fin, remainder);
cout << properties[i].address << " " << properties[i].suburb
<< " " << properties[i].price << endl;
items++;
}
fin.close();
return items;
}
//
// Display the menu
// Returns the user selction
//
int menu()
{
int option;
cout << endl;
cout << "Menu:" << endl;
cout << "1 - List all properties" << endl;
cout << "2 - Property search" << endl;
cout << "3 - Add a property" << endl;
cout << "4 - Save property list" << endl;
cout << "5 - Exit" << endl << endl;
cout << "Please enter option: ";
cin >> option;
string remainder;
getline(cin, remainder);
cout << endl;
return option;
}
//
// Display all properties in the current listing
//
void listAll(property properties[], int items)
{
for (int i = 0; i < items; i++)
{
cout << "$" << properties[i].price << " ";
cout << properties[i].address << " ";
cout << properties[i].suburb << endl;
}
}
//
// Search for properties up to a maximum price
//
void search( property properties[], int items )
{
int limit;
cout << "Please enter price limit: $";
cin >> limit;
cout << endl;
for (int i = 0; i < items; i++)
{
if (properties[i].price <= limit)
{
cout << "$" << properties[i].price << " ";
cout << properties[i].address << " ";
cout << properties[i].suburb << endl;
}
}
}
//
// Add a property to the current listings without saving to file
//
void addProperty(property properties[], int &items)
{
if (items == MAX_PROPERTIES)
{
return;
}
cout << "Enter address: ";
getline(cin, properties[items].address);
cout << "Enter suburb: ";
getline(cin, properties[items].suburb);
cout << "Enter price: $";
cin >> properties[items].price;
cout << endl << "Property: " << properties[items].address;
cout << " " << properties[items].suburb;
cout << " at $" << properties[items].price;
cout << " added to list" << endl;
items++;
}
//
// Save the current property listing to a file
//
void saveProperties(property properties[], int items)
{
string filename;
cout << "Enter filename: ";
cin >> filename;
ofstream fout(filename.c_str());
if (!fout.is_open())
{
cout << "File \""<< filename << "\" does not exist" << endl << endl;
return;
}
for( int i = 0; i < items; i++ )
{
fout << properties[i].address << endl;
fout << properties[i].suburb << endl;
fout << properties[i].price << endl;
}
cout << "Property details saved to file \"" << filename << "\"" << endl;
fout.close();
}
could you please prewrite this and post the complete .ccp and .h (containg the class)
-- modified at 22:33 Wednesday 7th September, 2005
|
|
|
|
|
smells like homework
You will never learn anything if others do your homework for you, if however you have a specific question then there are many here who will help you.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Any elementary C++ book or tutorial will teach you that ...
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
Hi, I'm looking for a little help with some code I'm working with.
I'm still learning C++ and would like to use the PlaySound function to play a short (1sec) .wav file when iValue (detailed below) is an integer value of 15, and a different short .wav file if iValue = 14.
This is the code segment I'm currently working with:
if (iValue != -1) {
sprintf(acString,"%d",iValue);
} else {
sprintf(acString,"%s","None");
}
SetDlgItemText(IDC_VALUE,acString);
iValue shows an integer between 0 and 15 depending on input (and shows blank if there is no input).
I've been trying to get it to work for a while, any help would be greatly appreciated.
|
|
|
|
|
use switch
switch(iValue)
{
case 14:
PLaySound....
break;
case 15:
PlaySound....
break;
}
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hello,
Is there a way to get a file icon for a given file extension? I'm displaying a list of files that may or may not exist on the computer and I want to display the correct icon for each file.
I'm currently using a method that uses SHGetFileInfo, but this only works if the file exists on the machine.
Any suggestions?
Thanks,
Ian
|
|
|
|
|
According to the MSDN reference for SHGetFileInfo [^], you can use it to get information on the properties of a file extension "if the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag".
The remaining problem is to get a list of file extensions of interest. Since you have a list of candidate filenames, you can use those directly. If you need to enumerate the extensions on the machine, the quick-and-dirty method would be to enumerate the keys under HKEY_CLASSES_ROOT in the registry.
Software Zen: delete this;
|
|
|
|
|
|
Ian Bowler wrote:
this only works if the file exists on the machine
Could you not create a temporary file (with the right extension), call SHGetFileInfo, and then delete the file?
|
|
|
|
|
Clever solution... I'll keep it in the back of my mind as a last resort...
Thanks.
|
|
|
|
|
Try ExtractIcon() .
Otherwise, you'll need to call AssocQueryString() to get the executable associated with the file extension, load that executable using LoadLibrary() , and then call LoadImage() or LoadIcon() to get the icon's handle.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
good afternoon, all
I am trying to get rid of one of the old link library from my application
I removed it from preprocessor definition, took all the link library files from LINK, but the program will still step into the area says #ifndef __XYZ_APP__ when I am doing debugging.....It really shouldn't behave like this, I also checked if anything like #define __XYZ_APP in header ....still no luck
does any body know why is this happening? thank you for your time
-- modified at 18:25 Wednesday 7th September, 2005
|
|
|
|
|
#ifndef __XYZ_APP__
this means: if __XYZ_APP__ is not defined, compile the code inside of me.
Since you undefined it, that is what should happen
|
|
|
|
|
a lot of confusion to me
ok. Preprocessor symbols can be defined in two ways. (As I know)
1. in the source or header files
2. In the project setting. Please check the project settings, preprossor options..
BAsically All debug relateted preprocessor are defined in project setting only..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
i have been trying to use this in my DLL but an error occurs saying its an unreclared symbol
if i try to include afxwin.h during compile it says i can't include it
am i missing something?
thanks
Andy
|
|
|
|
|
Anonymous wrote:
i have been trying to use this in my DLL but an error occurs saying its an unreclared symbol
Is MFC in your DLL, if NO, then you two option either enable MFC in your DLL or call Win32 version of AfxBeginThread in your DLL like.. CreateThread .
"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
|
|
|
|
|
Anonymous wrote:
i have been trying to use this in my DLL but an error occurs saying its an unreclared symbol
Haven't you also received this compiler message about AfxBeginThread() ? If not, why are you trying to end a thread that has not been started?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
hi, i have a question about interfaces and templates: is it possible to have a function template inside a interface? see code:
__interface ITest {<br />
template<class T> void TestFunc(T& data, int size);<br />
}
is there an alternate method? i get a compiler error on this code. i am just getting started with templates
|
|
|
|
|