⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieembed.cpp

📁 JDesktop Integration Components (JDIC)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        pBrowserWnd->SetReady(instanceNum);        SendSocketMessage(instanceNum, CEVENT_INIT_WINDOW_SUCC);                //save the pointer of BrowserWnd to array        ABrowserWnd.SetAtGrow(instanceNum, pBrowserWnd);        //show window        ShowWindow(hWndClient, SW_SHOW);        UpdateWindow(hWndClient);        SetFocus(hWndClient);        }        break;    case JEVENT_DESTROYWINDOW:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        if(pBrowserWnd != NULL){            hRes = pBrowserWnd->DispEventUnadvise(pBrowserWnd->m_pWB);            pBrowserWnd->DestroyWindow();            delete pBrowserWnd;            ABrowserWnd.SetAt(instanceNum, NULL);        }        SendSocketMessage(instanceNum, CEVENT_DISTORYWINDOW_SUCC);        break;    case JEVENT_SHUTDOWN:        ::PostMessage(gMainWnd, WM_QUIT, 0, 0);        break;    case JEVENT_SET_BOUNDS:        {        if (i != 3) break;        int x, y, w, h;        i = sscanf(mMsgString, "%d,%d,%d,%d", &x, &y, &w, &h);        if (i == 4) {            pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];            ATLASSERT(pBrowserWnd != NULL);            pBrowserWnd->SetWindowPos(NULL, x, y, w, h, SWP_NOZORDER);        }        }        break;    case JEVENT_NAVIGATE:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->Navigate(CComBSTR(mMsgString), NULL, NULL, NULL, NULL);        break;    case JEVENT_NAVIGATE_POST:         mURL = mMsgString;        break;    case JEVENT_NAVIGATE_POSTDATA:         pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        VARIANT vHeaders;        BSTR bstrHeaders;        bstrHeaders = SysAllocString(            L"Content-Type: application/x-www-form-urlencoded\r\n");        V_VT(&vHeaders) = VT_BSTR;        V_BSTR(&vHeaders) = bstrHeaders;        // Construct the POST data with VARIANT type.        // Put data into safe array.        LPSAFEARRAY psa;        VARIANT vPostData;        VariantInit(&vPostData);        psa = SafeArrayCreateVector(VT_UI1, 0, strlen(mMsgString));        LPSTR pPostData;        SafeArrayAccessData(psa, (LPVOID*)&pPostData);        memcpy(pPostData, mMsgString, strlen(mMsgString));        SafeArrayUnaccessData(psa);                // Package the SafeArray into a VARIANT.        V_VT(&vPostData) = VT_ARRAY | VT_UI1;        V_ARRAY(&vPostData) = psa;        // Navigate to the URL, and POST the data.        pBrowserWnd->m_pWB->Navigate(CComBSTR(mURL), NULL, NULL,            &vPostData, &vHeaders);        if (bstrHeaders) {            SysFreeString(bstrHeaders);        }        VariantClear(&vPostData);        break;    case JEVENT_GOBACK:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->GoBack();        break;    case JEVENT_GOFORWARD:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->GoForward();        break;    case JEVENT_REFRESH:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->Refresh();        break;    case JEVENT_STOP:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->Stop();        break;    case JEVENT_GETCONTENT:        {            pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];            // JavaScript to return the content of the currently loaded URL             // in *IE*, which is different from the JavaScript for Mozilla.            char* IE_GETCONTENT_SCRIPT                 = "(document.documentElement||document.body).outerHTML;";            LPSTR exeResult = executeScript(pBrowserWnd, IE_GETCONTENT_SCRIPT);            SendSocketMessage(instanceNum, CEVENT_GETCONTENT, (LPSTR)(exeResult));            delete [] exeResult;            break;        }    case JEVENT_EXECUTESCRIPT:        {            pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];            LPSTR exeResult = executeScript(pBrowserWnd, mMsgString);            SendSocketMessage(instanceNum, CEVENT_EXECUTESCRIPT, (LPSTR)(exeResult));            delete [] exeResult;            break;        }    case JEVENT_SETCONTENT:        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        setContent(pBrowserWnd, mMsgString);        break;    case JEVENT_GETURL:        USES_CONVERSION;        BSTR bsUrl;        pBrowserWnd = (BrowserWindow *) ABrowserWnd[instanceNum];        ATLASSERT(pBrowserWnd != NULL);        pBrowserWnd->m_pWB->get_LocationURL(&bsUrl);        SendSocketMessage(instanceNum, CEVENT_RETURN_URL, W2A(bsUrl));        SysFreeString(bsUrl);        break;    }    delete pInputChar;    return;}//this function is passed as parameter to struct WNDCLASSEX LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){    switch (uMsg)    {    case WM_SOCKET_MSG:        CommandProc ((char*)lParam);        return 0;    }    return DefWindowProc(hWnd, uMsg, wParam, lParam);}//this function is called in CreateHiddenWnd()void RegisterWindowClass(){    WNDCLASSEX  wcx;    ZeroMemory(&wcx, sizeof(WNDCLASSEX));    wcx.cbSize = sizeof(WNDCLASSEX);    wcx.lpfnWndProc = MainWindowProc;    wcx.hInstance = GetModuleHandle(NULL);    wcx.hIcon = NULL; // LoadIcon(wcx.hInstance, MAKEINTRESOURCE(IDR_MAIN));    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);    wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);    wcx.lpszClassName = "SampleWindowClass";    wcx.lpszMenuName = NULL; //MAKEINTRESOURCE(IDR_MAIN);    RegisterClassEx(&wcx);}void CreateHiddenWnd() {    RegisterWindowClass();    gMainWnd = CreateWindowEx(WS_EX_APPWINDOW,        "SampleWindowClass", _T("Browser App"), WS_DISABLED,        -10010, -10010, -10000, -10000, NULL, NULL, 0, NULL);}///////////////////////////////////////////////////////////////////////////////extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/){    if (strstr(lpCmdLine, "-port=")) {        int port = atoi(&lpCmdLine[6]);        gMessenger.SetPort(port);        gMessenger.CreateServerSocket();    }    if (gMessenger.IsFailed()) {        fprintf(stderr, "Failed to create server socket\n");        return -1;    }    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT    //Initializes the COM library for use#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);#else    HRESULT hRes = CoInitialize(NULL);#endif    ATLASSERT(SUCCEEDED(hRes));    _Module.Init(NULL, hInstance, &LIBID_SHDocVw);    //create hidden window for purpose of handling messages    CreateHiddenWnd();    //init new thread for socket communication listening.    HANDLE hThread = CreateThread(NULL,                                  0,                                   PortListening,                                   SocketMsgHandler,                                  0,                                   NULL);    if (hThread == NULL) {        SendSocketMessage(-1, CEVENT_INIT_FAILED);        goto exit;    }    //init atl    AtlAxWinInit();    //process message    MSG msg;    BOOL bRet;    while (TRUE)    {        __try{        if((bRet = GetMessage(&msg, NULL, 0, 0)) == 0)            break;        }        __except(EXCEPTION_EXECUTE_HANDLER){            // patch to issue 277. this is a temporary solution.            bRet = -1;        }        if (bRet == -1)        {            // handle the error and possibly exit        }        else        {            int size = ABrowserWnd.GetSize();            for (int i = 0; i < size; i++) {                BrowserWindow *pBrowserWnd = (BrowserWindow *)ABrowserWnd[i];                if (pBrowserWnd && pBrowserWnd->PreTranslateMessage(&msg)) {                    break;                }            }            if (i == size) {                TranslateMessage(&msg);                 DispatchMessage(&msg);             }        }    }    exit:    _Module.Term();    CoUninitialize();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -