Click here to Skip to main content
15,898,134 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString to TCHAR Pin
Orkun GEDiK11-Feb-04 10:33
Orkun GEDiK11-Feb-04 10:33 
GeneralRe: CString to TCHAR Pin
satcat11-Feb-04 11:58
satcat11-Feb-04 11:58 
GeneralRe: CString to TCHAR Pin
John M. Drescher11-Feb-04 17:06
John M. Drescher11-Feb-04 17:06 
GeneralCListCtrl Item Search Efficiency :: MFC Pin
valikac11-Feb-04 8:55
valikac11-Feb-04 8:55 
GeneralCreate own window styles Pin
BrockVnm11-Feb-04 8:17
BrockVnm11-Feb-04 8:17 
GeneralRe: Create own window styles Pin
Antti Keskinen11-Feb-04 8:52
Antti Keskinen11-Feb-04 8:52 
GeneralRe: Create own window styles Pin
BrockVnm11-Feb-04 9:08
BrockVnm11-Feb-04 9:08 
GeneralMemory leak while traversing through HTML frames Pin
Member 85966411-Feb-04 7:55
Member 85966411-Feb-04 7:55 
hi,
i have modified the code of brochure machine which is available in the MSDN for my requirement.

what the earlier Code does??
----------------------------
It gets the handle of current IE instance get the handle of the document and invokes print command on the OLECOMMAND TARGET
Earlier Code snippet(Microsoft)
----------------------
launcPT()
{
CComPtr<iolecontainer> spContainer;
CComPtr<iserviceprovider> spSP;
CComPtr<iwebbrowser2> spWB;
CComPtr<idispatch> spDisp;
CComPtr<ihtmldocument2> spDoc;
CComPtr<iolecommandtarget> spCT;
CComVariant vPTPath = "res://CramerPrintControl.dll/PT.htm";
m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
spWB->get_Document(&spDisp);
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
spCT->Exec(&CGID_MSHTML, IDM_PRINTPREVIEW, NULL, &vPTPath, NULL);
return S_OK;
}
----------------------------
I want to print the document which is residing in one of the frames of the document ,so i traverse through the frame collection and get the document in the desired frame and try to print it.when i try to do this,after repetitive invokation,the IE crashes,i dont know the reason may be there is a memory leak in my code or may be i am doing something wrng.i am new to vc++.so please have a glance at my code and point out the problems.
i am really stuck here.
Recent code
----------------------------
launchPTNEW(){
CComPtr<iolecontainer> spContainer;
CComPtr<iserviceprovider> spSP;
CComPtr<iwebbrowser2> spWB;
CComPtr<idispatch> spDisp;
CComPtr<idispatch> spContentFrameDisp;
CComPtr<idispatch> spBodyFrameDisp;
CComPtr<ihtmldocument2> spDoc;
CComPtr<iolecommandtarget> spCT;
//tell the path to pick up the print template

CComVariant vPTPath = "res://CramerPrintControl.dll/PT.htm";
//CComVariant vPTPath = "D:/gvs/freshprinting/newPT.htm";
//CComVariant vPTPath = "D:/gvs/freshprinting/paul.htm";

//please get the contianer of the current browser
m_spClientSite->GetContainer(&spContainer);
spContainer->QueryInterface(IID_IServiceProvider, (void**)&spSP);
//get the browser control
spSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser, (void**)&spWB);
//get the Idispatch of the document in the main browser
spWB->get_Document(&spDisp);


HRESULT hr;


// Get an IDispatch pointer for the
// IOleCommandTarget interface.
//1. get the dispacther interface from the browser document

//get the document in the browser
spDisp->QueryInterface(IID_IHTMLDocument2, (void**)&spDoc);
//hr=spDoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);


//hold the frame name while iterating through the frames
CComBSTR bstrFrameName;
//this is the frame i am interested in
CComBSTR bstrContentName(OLESTR("ContentFrame"));
//this is the frame i want to print
CComBSTR bstrBodyName(OLESTR("body"));
//this is the frame i want to print
CComBSTR bstrResultsName(OLESTR("ResultsFrame"));

//declare the html frames collection
CComPtr<ihtmlframescollection2> framescol;
//IHTMLFramesCollection2* framescol=NULL;

//spDoc->get_frames(&framescol);
//2. get the window containing the document

CComPtr<ihtmlwindow2> pDocumentWin;
//IHTMLWindow2* pDocumentWin;
//get the window the current document resides
hr=spDoc->get_parentWindow(&pDocumentWin);
//pDocumentWin->get_name(&bstrFrameName);
if(SUCCEEDED (hr)) {
//3. get the parent window
CComPtr<ihtmlwindow2> pParentWin;
//IHTMLWindow2* pParentWin;
hr=pDocumentWin->get_parent(&pParentWin);
//gvschnaged
CComPtr<ihtmldocument2> pParentFramedoc;
//IHTMLDocument2* pParentFramedoc;
//4.get the document of the parent window
hr=pParentWin->get_document(&pParentFramedoc);
//5.get all the frames of the parent window
hr=pParentFramedoc->get_frames(&framescol);

LONG len;
//how many number of frames are there in the current document
framescol->get_length(&len);
//loop through and find out the name
int i;
for (i=0;i<len;++i)
{
="" variant="" var1;
="" var1.vt="VT_UINT;
" var1.lval="i;
" var2;
="" var2.vt="VT_DISPATCH;
" get="" each="" frame="" in="" collection
="" hr="framescol-">item(&var1, &var2);
if(hr == S_OK) //ERROR
{
IDispatch* pDisp;
pDisp=var2.pdispVal;
CComPtr<ihtmlwindow2> pFrameWin;
//IHTMLWindow2* pFrameWin;
//get the next window frame
hr=var2.pdispVal->QueryInterface(IID_IHTMLWindow2,(void**)&pFrameWin);
if(SUCCEEDED (hr))
{
//empty it beofre you pass it to avoid memory leak
//if(bstrFrameName )
//{
bstrFrameName.Empty();
//}
//what is the frame name???
hr = pFrameWin->get_name(&bstrFrameName);
//is the frame name mathing with the ContentFrame??
//if (_bstr_t(bstrFrameName, TRUE) == _bstr_t(bstrContentName, TRUE))
if (bstrFrameName== bstrContentName)
{
//release the string resources
::SysFreeString(bstrFrameName);
::SysFreeString(bstrContentName);

//get the body frame with in the content frame
//////////////////////
//gvschanged
CComPtr<ihtmldocument2> pContentFramedoc;
//IHTMLDocument2* pContentFramedoc;
hr=pFrameWin->get_document(&pContentFramedoc);//problem
if(SUCCEEDED (hr))
{


//declare the html frames collection
CComPtr<ihtmlframescollection2> contentFrames;
//IHTMLFramesCollection2* contentFrames=NULL;
//get all the frames in the content frame
pContentFramedoc->get_frames(&contentFrames);

LONG Contentlen;
//how many number of frames are there in the current document
contentFrames->get_length(&Contentlen);
//hold the frame name in the second iteration
CComBSTR bstrContFrameName;

//loop through and find out the name
int j;
for (j=0;j<contentlen;++j)
{
="" variant="" framerequested;
="" frameout;
="" framerequested.vt="VT_UINT;
" framerequested.lval="j;
" ccomptr<ihtmlwindow2=""> pBodyFrameWindow;
//IHTMLWindow2* pBodyFrameWindow;
//get each frame residing in the content frame
hr=contentFrames->item(&frameRequested, &frameOut);
//get the window handle of the frame
hr = frameOut.pdispVal->QueryInterface(IID_IHTMLWindow2, (void**)&pBodyFrameWindow);
if(SUCCEEDED (hr))
{
//empty it beofre you pass it to avoid memory leak
//if(bstrContFrameName)
//{
bstrContFrameName.Empty();
//}
//what is the frame name???
hr = pBodyFrameWindow->get_name(&bstrContFrameName);
//check if this frame is body frame
//if (_bstr_t(bstrContFrameName, TRUE) == _bstr_t(bstrBodyName, TRUE))
if ((bstrContFrameName == bstrBodyName) || (bstrContFrameName == bstrResultsName))
{
//release the string resources
::SysFreeString(bstrContFrameName);
::SysFreeString(bstrBodyName);
::SysFreeString(bstrResultsName);
//gvschanged
CComPtr<ihtmldocument2> pBodyFramedoc;
//IHTMLDocument2* pBodyFramedoc;
//get the document of the body frame
hr=pBodyFrameWindow->get_document(&pBodyFramedoc);
if(hr == S_OK)
{
///
//release the variantts
VariantClear(&var1);
VariantClear(&var2);
VariantClear(&frameOut);
VariantClear(&frameRequested);

///
//spBodyFrameDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pBodyFramedoc);
//get the OLE command target of the document to be printed
hr=pBodyFramedoc->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
//Go for print previewing the body frame document.
hr=spCT->Exec(&CGID_MSHTML, IDM_PRINTPREVIEW, NULL, &vPTPath, NULL);
//spCT->Release();
return S_OK;
}

}
}


}

}




}

}
}
}
}

return S_OK;
}
-----------------------------
GeneralRe: Memory leak while traversing through HTML frames Pin
Peter Weyzen11-Feb-04 8:14
Peter Weyzen11-Feb-04 8:14 
GeneralLocallizing to Hebrew Pin
LukeV11-Feb-04 7:01
LukeV11-Feb-04 7:01 
GeneralRe: Locallizing to Hebrew Pin
Peter Weyzen11-Feb-04 7:31
Peter Weyzen11-Feb-04 7:31 
GeneralRe: Locallizing to Hebrew Pin
LukeV11-Feb-04 7:47
LukeV11-Feb-04 7:47 
GeneralRe: Locallizing to Hebrew Pin
Peter Weyzen11-Feb-04 7:52
Peter Weyzen11-Feb-04 7:52 
GeneralRe: Locallizing to Hebrew Pin
LukeV11-Feb-04 8:29
LukeV11-Feb-04 8:29 
GeneralRe: Locallizing to Hebrew Pin
Anonymous11-Feb-04 11:58
Anonymous11-Feb-04 11:58 
GeneralRe: Locallizing to Hebrew Pin
LukeV11-Feb-04 12:19
LukeV11-Feb-04 12:19 
GeneralRe: Locallizing to Hebrew Pin
Anonymous11-Feb-04 14:03
Anonymous11-Feb-04 14:03 
GeneralRe: Locallizing to Hebrew Pin
LukeV11-Feb-04 13:05
LukeV11-Feb-04 13:05 
GeneralOutlook Programming - User-Defined Fields Pin
Christian Zellner11-Feb-04 6:46
Christian Zellner11-Feb-04 6:46 
GeneralCDBConnection-&gt;m_pErrorInfo Pin
Chris Ulliott11-Feb-04 6:38
Chris Ulliott11-Feb-04 6:38 
GeneralFlickering at resizing on MFC app Pin
JimmyChu11-Feb-04 6:33
JimmyChu11-Feb-04 6:33 
GeneralRe: Flickering at resizing on MFC app Pin
Anonymous11-Feb-04 6:51
Anonymous11-Feb-04 6:51 
GeneralRe: Flickering at resizing on MFC app Pin
Roger Allen11-Feb-04 6:52
Roger Allen11-Feb-04 6:52 
Generalvisual c++ Pin
11-Feb-04 6:26
suss11-Feb-04 6:26 
GeneralRe: visual c++ Pin
Antti Keskinen11-Feb-04 6:39
Antti Keskinen11-Feb-04 6:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.