BOOL CGetURL::OnInitDialog() { CDialog::OnInitDialog(); IUnknown *pUnk; CWnd *pWnd = GetDlgItem(IDC_EXPLORER); pUnk = NULL; if(pWnd) m_spBrowser = pWnd->GetControlUnknown(); pWnd = NULL; CRect rcItem; pWnd = GetDlgItem(IDC_PHSTATIC); if(pWnd) { pWnd->GetClientRect(rcItem); pWnd->ClientToScreen(rcItem); pWnd->DestroyWindow(); ScreenToClient(rcItem); rcItem.bottom += 150; if(m_AddrCombo.Create(WS_VSCROLL|WS_CHILD|WS_VISIBLE|CBS_DROPDOWN|CBS_AUTOHSCROLL,rcItem,this,IDC_ADDRCOMBO)) { m_AddrCombo.SetCurSel(0); m_AddrCombo.GetWindowText(m_szCurAddr); if(m_spBrowser && m_szCurAddr.GetLength()) m_spBrowser->Navigate(m_szCurAddr.AllocSysString(),NULL,NULL,NULL,NULL); } } return TRUE; }
BOOL CHTMLContainerDlg::OnInitDialog() { AfxEnableControlContainer(); CDialog::OnInitDialog(); RECT rectClient; GetClientRect(&rectClient); // if we've been created from the dynamic template // set the caption if(!m_lpszTemplateName) SetWindowText(m_strDlgCaption); // check if there is a browser control on the dialog // already CWnd *pCtrl = GetDlgItem(AFX_IDC_BROWSER); LPUNKNOWN lpUnk; if(pCtrl) { lpUnk = pCtrl->GetControlUnknown(); if (lpUnk && SUCCEEDED(lpUnk->QueryInterface(IID_IWebBrowser2, (void **) &m_pBrowserApp))) { m_wndBrowser.Attach(pCtrl->m_hWnd); m_bAttachedControl = TRUE; } } if(m_pBrowserApp == NULL) { // create the control window m_wndBrowser.CreateControl(CLSID_WebBrowser, NULL, WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDC_BROWSER); lpUnk = m_wndBrowser.GetControlUnknown(); if(FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp))) { m_wndBrowser.DestroyWindow(); DestroyWindow(); return TRUE; } } Navigate(m_strURL); m_pBrowserApp->put_Silent(VARIANT_TRUE);//禁止脚本错误提示 //在不同dpi的情况下,使用相同大小的显示 if (m_iWidth > 0 && m_iHeight > 0) { SetWindowPos(NULL, 0, 0, m_iWidth, m_iHeight, SWP_NOMOVE); } if (m_dialogTitle.GetLength() > 0) SetWindowText(m_dialogTitle); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE }
void CGraphRightView::OnDestroy() { if ( m_pGraphSink ) { //Get a pointer to sinks IUnknown, no AddRef. LPUNKNOWN pUnkSink = m_pGraphSink->GetIDispatch(FALSE); CWnd* pWnd = nullptr; pWnd = GetDlgItem(IDC_DMGRAPH_CTRL); LPUNKNOWN pUnk = pWnd->GetControlUnknown(); //Terminate a connection between source and sink. //m_pUnkSrc is IUnknown of server obtained by CoCreateInstance(). //m_dwCookie is a value obtained through AfxConnectionAdvise(). AfxConnectionUnadvise(pUnk, DIID__IDMGraphCtrlEvents, pUnkSink, FALSE, m_dwCookie); //Release the sink object delete m_pGraphSink; m_pGraphSink = nullptr; } CFormView::OnDestroy(); }
/******************************************************************************* Function Name : vHandleConnectionStatusChange Input(s) : bConnectionStatus - Status of the tool connection. TRUE if the tool is going to connected state Output : - Functionality : This function will handle connect event. Will advise sink class on connect and unadvise on disconnect. Member of : CGraphRightView Author(s) : Arunkumar Karri Date Created : 10/12/2012 *******************************************************************************/ void CGraphRightView::vHandleConnectionStatusChange(BOOL bConnectStatus) { if ( bConnectStatus == TRUE ) { if ( m_pGraphSink == nullptr ) { //Create Sink object m_pGraphSink = new CGraphSink(); //Share the Parent window pointer m_pGraphSink->m_pParentWnd = m_pParentWnd; //Get a pointer to sinks IUnknown, no AddRef. CMySink implements only //dispinterface and the IUnknown and IDispatch pointers will be same. LPUNKNOWN pUnkSink = m_pGraphSink->GetIDispatch(FALSE); CWnd* pWnd = nullptr; pWnd = GetDlgItem(IDC_DMGRAPH_CTRL); LPUNKNOWN pUnk = pWnd->GetControlUnknown(); //Establish a connection between source and sink. //m_pUnkSrc is IUnknown of server obtained by CoCreateInstance(). //m_dwCookie is a cookie identifying the connection, and is needed //to terminate the connection. AfxConnectionAdvise(pUnk, DIID__IDMGraphCtrlEvents, pUnkSink, FALSE,&m_dwCookie); } //Set element point size to 0 CComPtr<IDMGraphCollection> spGraphCollection; HRESULT hr = m_pDMGraphCtrl->get_Elements(&spGraphCollection); if(FAILED(hr)) { return; } long lngCount; spGraphCollection->get_Count(&lngCount); // Add items to the list for ( long lngIndex = 0; lngIndex < lngCount; lngIndex++ ) { CComPtr<IDispatch> spDispatch; CComPtr<IDMGraphElement> spGraphElement; //Get item at index lngIndex spGraphCollection->get_Item(lngIndex, &spDispatch); spDispatch.QueryInterface(&spGraphElement); spGraphElement->put_PointSize(0); } } else { //Set element point size to 2 CComPtr<IDMGraphCollection> spGraphCollection; HRESULT hr = m_pDMGraphCtrl->get_Elements(&spGraphCollection); if(FAILED(hr)) { return; } long lngCount; spGraphCollection->get_Count(&lngCount); // Add items to the list for ( long lngIndex = 0; lngIndex < lngCount; lngIndex++ ) { CComPtr<IDispatch> spDispatch; CComPtr<IDMGraphElement> spGraphElement; //Get item at index lngIndex spGraphCollection->get_Item(lngIndex, &spDispatch); spDispatch.QueryInterface(&spGraphElement); spGraphElement->put_PointSize(2); } } }