 |
|
|
I have many dialogs derrived from CDHtmlDialog. All I want, is for the HTML to let one use "copy" from them. As in, all of the controls on any page at any time. My complexity is that I override OnInitDialog in them to draw the HTML I want as such:
SAFEARRAYBOUND SAFEARRAYBOUND_Temp; SAFEARRAYBOUND_Temp.cElements = 1; SAFEARRAYBOUND_Temp.lLbound = 0; COleSafeArray COleSafeArray_Temp; COleSafeArray_Temp.Create(VT_VARIANT, 1, &SAFEARRAYBOUND_Temp); _variant_t _variant_t_Temp; _variant_t_Temp = L"<html><input type=text value=\"Try to copy me!!!\"></html>"; LONG LONG_Temp = 0; COleSafeArray_Temp.PutElement(&LONG_Temp, &_variant_t_Temp); IDispatch *pIDispatch = NULL; m_pBrowserApp->get_Document(&pIDispatch); IHTMLDocument2 *pIHTMLDocument2 = NULL; IHTMLDocument3 *pIHTMLDocument3 = NULL; pIDispatch->QueryInterface(IID_IHTMLDocument2, (void **) &pIHTMLDocument2); pIDispatch->QueryInterface(IID_IHTMLDocument3, (void **) &pIHTMLDocument3); pIHTMLDocument2->write(COleSafeArray_Temp.parray); pIHTMLDocument2->close();
Can you make your sample so that it works for a CDHtmlDialog? Note, this means, that there is some new class to replace CDHtmlDialog as such:
OLD WAY - BROKE - COPY NOT WORK: class CMyClass : public CDHtmlDialog....
NEW WAY - FIXED - COPY DOES WORK: class CMyClass : public CSomeCDHtmlDialogThatMakesItWorkWithoutChanges...
If I have to open each CDHtmlDialog derrived class and add code, it will be horrible.
Any idea?
Also, is there a way for Java Script inside the HTML to activate the COPY?
ATS++
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
void CMfcieView::OnDocumentComplete(LPCTSTR lpszUrl) { // make sure the main frame has the new URL. This call also stops the animation ((CMainFrame*)GetParentFrame())->SetAddress(lpszUrl);
MSHTML::IHTMLDocument2Ptr pDoc(GetHtmlDocument()); MSHTML::IHTMLElementCollectionPtr allLinks;
IDispatchPtr linkDisp; MSHTML::IHTMLElement* pElem;
long len;
pDoc->get_links(&allLinks); //???????????
CString url54;
allLinks->get_length(&len); for(int i=0;i { tagVARIANT v1; v1.vt = VT_INT; memcpy(&v1.iVal,&i,sizeof(int)); linkDisp =allLinks->item(v1, v1);//??????IDispatch
if(linkDisp!=NULL) { //????????link->get_innerHTML(&url); linkDisp->QueryInterface(__uuidof(IHTMLElement), (void**)&pElem); CString url4 =(char*)pElem->toString(); if(url4.Find("http://") !=-1) { url54 +="\r\n"+url4; } } }
// Allocate global memory for transfer... HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, url54.GetLength()+4);
// Put our string in the global memory... char *ptr = (char *)GlobalLock(hText); strcpy(ptr, url54); GlobalUnlock(hText);
if ( !OpenClipboard() ) { AfxMessageBox( "Cannot open the Clipboard" ); return; } // Remove the current Clipboard contents if( !EmptyClipboard() ) { AfxMessageBox( "Cannot empty the Clipboard" ); return; } // ... // Get the currently selected data, hData handle to // global memory of data // ... // For the appropriate data formats... if ( ::SetClipboardData(CF_TEXT, hText ) == NULL ) { CloseClipboard(); return; }
// Free memory... GlobalFree(hText);
// ... CloseClipboard();
}
?????????,??????! Ma Ying-jeou be the president of whole China!
http://uocn.lookse.org
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Great sharing, thanks a lot~~ But when I try this DDX_DHtml_ElementText with DISPID get from GetIDsOfNames the value return is always empty
Did you try with textbox ?
|
| Sign In·View Thread·PermaLink | 1.80/5 (2 votes) |
|
|
|
 |
|
|
Try DISPID_IHTMLINPUTTEXTELEMENT_VALUE for the DISPID value for an INPUT tag.
DDX_DHtml_ElementText( pDX, _T("Text1"), DISPID_IHTMLINPUTTEXTELEMENT_VALUE, m_csText1String );
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
I used this class to implement my application. but, I encounter a problem, how can I dynamicl add the options from the mfc code to the dropdown(like the combobox) control of the html? On the other words, I must get the data from database and initial to show to the html interface. Such as,I would add "option1"/"option2" and "option3" to the list of the control, What to do?
|
| Sign In·View Thread·PermaLink | 1.86/5 (4 votes) |
|
|
|
 |
|
|
When I open a html ,which has a Applet, by the WebBrowser Control (the Control is hosted in a Dialog-based Application ) ,I got some error ("Free block 0x**** modified after it was freed") What's the reason ?
colin
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
I use CDHTMLDialog to program a simple web browser, and I had a trobule on Http Header modify. I want add my own "User-Agent" when client use my application to browse web.
//------------------------------------------------------------------------------------------------ #define WM_NVTO (WM_USER+1000)
class NvToParam { public: CString URL; DWORD Flags; CString TargetFrameName; CByteArray PostedData; CString Headers; DWORD dwPostDataLen; }; //------------------------------------------------------------------------------------------------ LRESULT Ccdhtml_t1Dlg::OnNvTo(WPARAM wParam, LPARAM lParam) { NvToParam* pNvTo = (NvToParam*)wParam; CDHtmlDialog::Navigate((LPCTSTR)pNvTo->URL, pNvTo->Flags, (LPCTSTR)pNvTo->TargetFrameName, (LPCTSTR)pNvTo->Headers, pNvTo->PostedData.GetData());
delete pNvTo; return 1; }
//------------------------------------------------------------------------------------------------ void Ccdhtml_t1Dlg::OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel) { CString strHeaders(V_BSTR(Headers)); // Check User-Agent if(strHeaders.Find("User-Agent:LHPBrowser 1.0") < 0) { *Cancel = TRUE; // Cancel this request
if(!strHeaders.IsEmpty()) strHeaders += "\r\n"; // Add Customize Http Header strHeaders += "User-Agent:LHPBrowser 1.0";
NvToParam* pNvTo = new NvToParam; ASSERT(V_VT(URL) == VT_BSTR); ASSERT(V_VT(TargetFrameName) == VT_BSTR); ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF)); ASSERT(V_VT(Headers) == VT_BSTR); ASSERT(Cancel != NULL);
USES_CONVERSION;
VARIANT* vtPostedData = V_VARIANTREF(PostData); CByteArray array; if (V_VT(vtPostedData) & VT_ARRAY) { // must be a vector of bytes ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
vtPostedData->vt |= VT_UI1; COleSafeArray safe(vtPostedData);
DWORD dwSize = safe.GetOneDimSize();
LPVOID pVoid; safe.AccessData(&pVoid);
array.SetSize(dwSize); LPBYTE lpByte = array.GetData();
memcpy(lpByte, pVoid, dwSize);
safe.UnaccessData(); } // make real parameters out of the notification
CString strTargetFrameName(V_BSTR(TargetFrameName)); CString strURL(V_BSTR(URL)); DWORD nFlags = V_I4(Flags);
//===================================================== pNvTo->URL = strURL; pNvTo->Flags = nFlags; pNvTo->TargetFrameName = strTargetFrameName; pNvTo->PostedData.Copy(array); pNvTo->Headers = strHeaders; //===================================================== // Post msg PostMessage(WM_NVTO,(WPARAM)pNvTo);
return; } CDHtmlDialog::_OnBeforeNavigate2( pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel ); }
---------------------------------------------------------- After the testing, I found it will work fine on "http reqest", "http form get" and "http form post". But if my http form is "multipart/form-data" (upload file form), some of the post datas will lost.
How should I fix it? Does any one can help me? Or any better method to add http header when navigate a url?
|
| Sign In·View Thread·PermaLink | 2.00/5 (4 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
Great article,
working fine on a single page.
now i'm triyng to connect the events for individual frames and cann't find the way. it is possible to modify your class to acomplish it?
thanks
hecchan
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
 | Wow |  | Anonymous | 6:24 16 May '05 |
|
|
 |
|
|
I agree。The codeproject site is very professional,I am happy to share my articles on it ,but It's difficult because of my poor english .I tried my hand at posting the article,I hope that you will accept it.
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
Hello Luo,
A good idea would be to get an English speaking friend of yours to proof read the article for you. That will definitely improve the quality of your article.
Cheers, Smitha
Every problem has a gift for you in its hands. -- Richard Bach
|
| Sign In·View Thread·PermaLink | 2.67/5 (3 votes) |
|
|
|
 |