|
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;
}
-----------------------------
|
|
|
|
|
My COM is rusty -- but do you Release() everything you QueryInterface to get?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Hi,
my resource project is in Hebrew but all I see are '????'s. Any hints?
Thanks!
---------------
Tired of Spam? InboxShield for Microsoft® Outlook® and Outlook Express®
http://www.inboxshield.com
|
|
|
|
|
(1) What character set do you display with? UNICODE? MBCS? etc...
(2) What language packs do you have installed on your computer?
(3) What operating system?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Peter Weyzen wrote:
(1) What character set do you display with? UNICODE? MBCS? etc...
(2) What language packs do you have installed on your computer?
(3) What operating system?
1) MBCS
2) English. I don't have the multi-language package
3) Win XP
Thanks!
---------------
Tired of Spam? InboxShield for Microsoft® Outlook® and Outlook Express®
http://www.inboxshield.com
|
|
|
|
|
so -- you don't seem to have a Hebrew character set on your computer....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
I guess! The problem is that my contact in Israel, whom have the Hebrew package installed, told me that all the strings in my app were ???????. Should have mentionned that earlier
One thing that I should mention is that the string table language's is Hebrew but the dialogs are in english. Perhaps the problem lays there?
---------------
Tired of Spam? InboxShield for Microsoft® Outlook® and Outlook Express®
http://www.inboxshield.com
|
|
|
|
|
Does your friend's default locale is hebrew and what locale do you use in your program, default ?
Note : it seems better to use STL's locale class to set the locale, rather then win api directly, this all locales are set the same, win32 and c runtime.
I would recommend to switch to Unicode, it is so much easier to deal with, especially when you mix two or more langauges, the effort might well worth it. Also, try to install hebrew support on your machine (On my w2k it's in Control Panel\Regional Options\General tab, check hebrew, don't have xp machine nearby, but beleive it's in the same place). And of course the font you using must have hebrew charset.
Edward.
|
|
|
|
|
Here's what I did so far :
in the .rc files :
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_HEB)
LANGUAGE LANG_HEBREW, SUBLANG_DEFAULT
#pragma code_page(1255)
...
...
...
I did change every dialog's language to Arial so it can show Hebrew
FONT 8, "Arial", 400, 0, 0xB1
Heck, the editor won't even open the .rc file anymore because it says it's in Hebrew... so I guess the .rc files are fine!
Every place that I could find English as the language I would set it to Hebrew.
Now, in the Outlook toolbar and in the system menu's, the strings are showing correctly (I have Office 2003 and I added Hebrew) but all my dialogs are showing ?????????. I haven't been able to set Hebrew as a language for Windows XP. I'm using LoadString, is there something particular to do?
It's not showing correctly on my computer but I'll check with my contact in Israel...
---------------
Tired of Spam? InboxShield for Microsoft® Outlook® and Outlook Express®
http://www.inboxshield.com
|
|
|
|
|
I looked at the page you've sent. Does "arial" on your system has hebrew charset ? Since the menus are shown corretcly you can try to change "arial" to "MS Shell Dlg" (it's probably mapped to "Microsoft Sans Serif" whatever it is it has hebrew char). Since the title and labels appear to be RTL I assume you have set code page to hebrew.
LoadString loads the string for your current thread locale (same applies to DialogBox, FindResource etc.), this way you can have resources for multiple languages in your resource file and those functions will try to find the closest match for the current thread's locale.
Edward
|
|
|
|
|
Ok, so far I've been 30% successful : the toolbars are showing correctly and some controls in my dialogs are fine as well (see link for screenshot). I was also able to display Hebrew correctly on Win XP and in Visual Studio.
Why are there some controls that won't display correctly?
Screenshot: http://www.edovia.com/hebrewBug.jpg[^]
Thanks!
---------------
Tired of Spam? InboxShield for Microsoft® Outlook® and Outlook Express®
http://www.inboxshield.com
|
|
|
|
|
Hi,
now it´s time for me to create user-defined fields in an outlook form.
The Problem:
How can I access those fields in my code ?
I´m using C++ and outlook´s type libary(create wrapper classes)
For example:
If I want to access the full name of an ContactItem I can use.
_ContactItem c_item(...
CString full_name = c_item.GetFullName();
But how is it with custom fields ?
Thanks a lot for helping me - Chris
|
|
|
|
|
Why would my CDBConnection->m_pErrorInfo be NULL after I have purposely entered an incorrect password?
Thanks,
Chris
|
|
|
|
|
Hi all,
I have written an MFC application with standard controls. But I realized that at resizing the window, the whole window flicker.
I saw that there are a lot of posting on flicker-free app in here already. But since I am not writing any fancy graphics object, I am thinking if there is a way of doing double buffering (one way of removing flickering) without having to manipulate deeply on the OnDraw() function.
I tried the Keith Rule's CMemDC object in my own derived view and override the OnDraw () to be
{
CRect bounds;
CRect lBounds;
GetClientRect(&bounds);
lBounds = bounds;
CMemDC pDC(dc, &lBounds);
CFormView::OnDraw(pDC); //CFormView is my parent
}
But on resizing, the app still flicker.
Any suggestion?
Thanks a lot,
Jimmy Chu
|
|
|
|
|
Check if you window class has CS_HREDRAW or CS_VREDRAW style if it has, remove them
Edward
|
|
|
|
|
You can reduce the amount of flickering by handling the WM_ERASEBKGND message. I usually do it like this:
BOOL CCommunicationView::OnEraseBkgnd(CDC* pDC)
{
static int dont_erase_indexes[] =
{
IDC_DPAS_LAMP,
IDC_INSTRUMENT_TYPE,
IDC_LABEL1,
IDC_LABEL2,
IDC_DESTINATION,
IDC_CURRENT_STATUS,
IDC_LOG,
IDC_GRAPH,
IDC_DOWNLOAD_STATUS,
IDC_DOWNLOAD_PROGRESS,
ID_AUTO_LOAD,
IDC_UPLOAD_ASSAYS,
IDC_AUTO_UPLOAD,
IDC_BROWSE_FOR_FOLDER,
IDC_AUTOREFINE_GRAPH,
IDC_DIRECT_CONTROL_STATUS,
IDC_ABORT_ASSAY
};
CRect clip;
pDC->SaveDC();
for (int i = 0; i < sizeof(dont_erase_indexes) / sizeof(int); i++)
{
CWnd *pWnd = GetDlgItem(dont_erase_indexes[i]);
if (pWnd && pWnd->IsWindowVisible())
{
pWnd->GetWindowRect(&clip);
ScreenToClient(&clip);
pDC->ExcludeClipRect(&clip);
}
}
pDC->GetClipBox(&clip);
pDC->FillSolidRect(clip, GetSysColor(COLOR_BTNFACE));
pDC->RestoreDC(-1);
return FALSE;
}
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
is it possible to make a complete windows program in visual basic c++ i have only just started learning this and was wondering just what you can do with it also does ne one know of any sites that can give me lots of info to help me plz cheers, or would borland be better
|
|
|
|
|
It is possible to make programs with both Visual Basic and Visual C++. The C++ version is harder to learn, but gives much greater degree of control over the applications you create and over your system.
VB, on the other hand, is much quicker to learn, but when you need to do something more difficult like customize a Windows control, it starts to run out of options.
For a good book, try to find a one with 'Learn yourself Visual C++ in xx days'. They are easy to understand, quick and effective. However, if you have no prior experience in C/C++, I suggest getting a decent book from this area first and reading it. Understanding and mastering C/C++ is the key in being a succesfull programmer for Visual C++.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I think you're a bit too confused ...
are you talking about C++ or visual basic ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
It is quite possible to build complete Windows applications using either tool, Visual Basic or Visual C++. That's what they were designed to do. VC++ is harder to learn, but it also offers far more control over the target platform. VB is simple to learn, but it hides much of the detail from you and makes it simple to fall into sloppy coding habits. Borland has made excellent products in the past, but I haven't used any of them in 10 years or so. Which product you use is a matter of personal taste, but I suspect that you'll have fewer hassles using products made for Windows programming by the folks who make Windows.
As for sites that offer assistance and code samples, you can't do better than this one. Pick a language and start reading through the articles under that heading. You would also be well advised to pick up a couple of books on the language you choose to learn. Microsoft documentation is adequate for reference and quite complete, but it's useless and overwhelming for learning.
Heard in Bullhead City - "You haven't lost your girl - you've just lost your turn..." [sigh] So true...
|
|
|
|
|
Most excellent synopsis by Antti and Roger
May I add one thing. If you are wanting to learn Visual C++ ... It would probably do you well to pick up a book about "What is OOP" or "Understanding OOP" (OOP = Object Oriented Programming) C++ is an object orientated language so in order to do a lot of things that you'll want to do when you create a Windows app, you will need to understand what object oriented programming is all about!
shultas
|
|
|
|
|
I'm wanting to implement PNG file loading in a C++ like Photoshop .8bf plugin development language (FilterMeister). This language has no support for functions, linked-libraries, advanced file manipulation...
I'm trying to find sourcecode for a PNG loader in C/C++ but the best I've found is hazy details on the zlib site. Not being a real coder I need a link to an actual example that I can work from, instead of definitions and technical details.
Thanks for any help,
Shifty Geezer
...
|
|
|
|
|
I'm having trouble linking a CVF subroutine with my VC++ source code. I have the declarations in place and can successfully compile, but when I link, I get the following error -
error LNK2001: unresolved external symbol "void __cdecl LSQFIT(float *,float *,int *,int *)" (?LSQFIT@@$$J0YAXPAM0PAH1@Z)
My source and external subroutine are below -
extern "C" void LSQFIT(float*xp, float*fxp, int*nx, int*maxord);
int main()
{
float fxp[1000],xp[1000];
int maxord[1],nx[1];
*nx = 10;
*maxord = 3;
LSQFIT(xp,fxp,nx,maxord);
....
CVF subroutine -
SUBROUTINE LSQFIT(XP,FXP,NX,MAXORD)
DIMENSION XP(1),FXP(1),COEFF(11),ERR(10)
|
|
|
|
|
While I might be wrong, I'm pretty sure that your main and function declation are in C.
SUBROUTINE LSQFIT(XP,FXP,NX,MAXORD)
DIMENSION XP(1),FXP(1),COEFF(11),ERR(10)
Looks awfully like it is in FORTRAN... While it may be theoretically possible to link the
two, it's very hard at the least. It's bad enough mixing C and C++...
You'd be better looking for a C implementation, or porting the algorithm from Fortan to C.
Iain.
|
|
|
|
|
I am writing an application in MFC. What I am trying to do is see every internet packet that is being recieved or sent through my computer. I am assuming that I am going to need to use Winsock? Other than that, I have no clue, so any help is appreciated.
-Dev578
|
|
|
|
|