static void NavigateForwardOrBackward(HWND hWnd, UINT menuID) { if (!gWebView) return; BOOL wentBackOrForward = FALSE; if (IDM_HISTORY_FORWARD == menuID) gWebView->goForward(&wentBackOrForward); else gWebView->goBack(&wentBackOrForward); }
LRESULT CALLBACK ForwardButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { BOOL wentForward = FALSE; switch (message) { case WM_LBUTTONUP: gWebView->goForward(&wentForward); default: return CallWindowProc(DefButtonProc, hDlg, message, wParam, lParam); } }
void PrintView(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC printDC = getPrinterDC(); if (!printDC) { ::MessageBoxW(0, L"Error creating printing DC", L"Error", MB_APPLMODAL | MB_OK); return; } if (::SetAbortProc(printDC, AbortProc) == SP_ERROR) { ::MessageBoxW(0, L"Error setting up AbortProc", L"Error", MB_APPLMODAL | MB_OK); return; } IWebFramePtr frame; IWebFramePrivatePtr framePrivate; if (FAILED(gWebView->mainFrame(&frame.GetInterfacePtr()))) return; if (FAILED(frame->QueryInterface(&framePrivate.GetInterfacePtr()))) return; framePrivate->setInPrintingMode(TRUE, printDC); UINT pageCount = 0; framePrivate->getPrintedPageCount(printDC, &pageCount); DOCINFO di; initDocStruct(&di, L"WebKit Doc"); ::StartDoc(printDC, &di); // FIXME: Need CoreGraphics implementation void* graphicsContext = 0; for (size_t page = 1; page <= pageCount; ++page) { ::StartPage(printDC); framePrivate->spoolPages(printDC, page, page, graphicsContext); ::EndPage(printDC); } framePrivate->setInPrintingMode(FALSE, printDC); ::EndDoc(printDC); ::DeleteDC(printDC); }
static void NavigateToHistory(HWND hWnd, UINT menuID) { if (!gWebView) return; int historyEntry = menuID - IDM_HISTORY_LINK0; if (historyEntry > gHistoryItems.size()) return; IWebHistoryItemPtr desiredHistoryItem = gHistoryItems[historyEntry]; if (!desiredHistoryItem) return; BOOL succeeded = FALSE; gWebView->goToBackForwardItem(desiredHistoryItem, &succeeded); _bstr_t frameURL; desiredHistoryItem->URLString(frameURL.GetAddress()); ::SendMessage(hURLBarWnd, (UINT)WM_SETTEXT, 0, (LPARAM)frameURL.GetBSTR()); }
static void loadURL(BSTR passedURL) { _bstr_t urlBStr(passedURL); if (!!urlBStr && (::PathFileExists(urlBStr) || ::PathIsUNC(urlBStr))) { TCHAR fileURL[INTERNET_MAX_URL_LENGTH]; DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]); if (SUCCEEDED(::UrlCreateFromPath(urlBStr, fileURL, &fileURLLength, 0))) urlBStr = fileURL; } IWebFramePtr frame; HRESULT hr = gWebView->mainFrame(&frame.GetInterfacePtr()); if (FAILED(hr)) return; IWebMutableURLRequestPtr request; hr = WebKitCreateInstance(CLSID_WebMutableURLRequest, 0, IID_IWebMutableURLRequest, (void**)&request); if (FAILED(hr)) return; hr = request->initWithURL(wcsstr(static_cast<wchar_t*>(urlBStr), L"://") ? urlBStr : _bstr_t(L"http://") + urlBStr, WebURLRequestUseProtocolCachePolicy, 60); if (FAILED(hr)) return; _bstr_t methodBStr(L"GET"); hr = request->setHTTPMethod(methodBStr); if (FAILED(hr)) return; hr = frame->loadRequest(request); if (FAILED(hr)) return; SetFocus(gViewWindow); }
int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int nCmdShow) { #ifdef _CRTDBG_MAP_ALLOC _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); #endif // TODO: Place code here. MSG msg = {0}; HACCEL hAccelTable; INITCOMMONCONTROLSEX InitCtrlEx; InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX); InitCtrlEx.dwICC = 0x00004000; //ICC_STANDARD_CLASSES; InitCommonControlsEx(&InitCtrlEx); _bstr_t requestedURL; int argc = 0; WCHAR** argv = CommandLineToArgvW(GetCommandLineW(), &argc); for (int i = 1; i < argc; ++i) { if (!wcsicmp(argv[i], L"--transparent")) s_usesLayeredWebView = true; else if (!wcsicmp(argv[i], L"--desktop")) s_fullDesktop = true; else if (!requestedURL) requestedURL = argv[i]; } // Initialize global strings LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInst, IDC_WINLAUNCHER, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInst); if (shouldUseFullDesktop()) computeFullDesktopFrame(); // Init COM OleInitialize(NULL); if (usesLayeredWebView()) { hURLBarWnd = CreateWindow(L"EDIT", L"Type URL Here", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT, 0, 0, hInst, 0); } else { hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0); if (!hMainWnd) return FALSE; hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, hMainWnd, 0, hInst, 0); hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0); hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, CONTROLBUTTON_WIDTH * 2, 0, 0, 0, hMainWnd, 0, hInst, 0); ShowWindow(hMainWnd, nCmdShow); UpdateWindow(hMainWnd); } DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC)); DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC)); SetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc)); SetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc)); SetWindowLongPtr(hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc)); SetFocus(hURLBarWnd); RECT clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy }; IWebPreferencesPtr tmpPreferences; if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences.GetInterfacePtr())))) goto exit; if (FAILED(tmpPreferences->standardPreferences(&gStandardPreferences.GetInterfacePtr()))) goto exit; if (!setToDefaultPreferences()) goto exit; HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView.GetInterfacePtr())); if (FAILED(hr)) goto exit; hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate.GetInterfacePtr())); if (FAILED(hr)) goto exit; hr = WebKitCreateInstance(CLSID_WebHistory, 0, __uuidof(gWebHistory), reinterpret_cast<void**>(&gWebHistory.GetInterfacePtr())); if (FAILED(hr)) goto exit; gWebHost = new WinLauncherWebHost(); gWebHost->AddRef(); hr = gWebView->setFrameLoadDelegate(gWebHost); if (FAILED(hr)) goto exit; gPrintDelegate = new PrintWebUIDelegate; gPrintDelegate->AddRef(); hr = gWebView->setUIDelegate(gPrintDelegate); if (FAILED (hr)) goto exit; gAccessibilityDelegate = new AccessibilityDelegate; gAccessibilityDelegate->AddRef(); hr = gWebView->setAccessibilityDelegate(gAccessibilityDelegate); if (FAILED (hr)) goto exit; hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd)); if (FAILED(hr)) goto exit; hr = gWebView->initWithFrame(clientRect, 0, 0); if (FAILED(hr)) goto exit; if (!requestedURL) { IWebFramePtr frame; hr = gWebView->mainFrame(&frame.GetInterfacePtr()); if (FAILED(hr)) goto exit; frame->loadHTMLString(_bstr_t(defaultHTML).GetBSTR(), 0); } hr = gWebViewPrivate->setTransparent(usesLayeredWebView()); if (FAILED(hr)) goto exit; hr = gWebViewPrivate->setUsesLayeredWindow(usesLayeredWebView()); if (FAILED(hr)) goto exit; hr = gWebViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&gViewWindow)); if (FAILED(hr) || !gViewWindow) goto exit; if (usesLayeredWebView()) subclassForLayeredWindow(); resizeSubViews(); ShowWindow(gViewWindow, nCmdShow); UpdateWindow(gViewWindow); hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_WINLAUNCHER)); if (requestedURL.length()) loadURL(requestedURL.GetBSTR()); #pragma warning(disable:4509) // Main message loop: __try { while (GetMessage(&msg, 0, 0, 0)) { #if USE(CF) CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true); #endif if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } __except(createCrashReport(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) { } exit: gPrintDelegate->Release(); shutDownWebKit(); #ifdef _CRTDBG_MAP_ALLOC _CrtDumpMemoryLeaks(); #endif // Shut down COM. OleUninitialize(); return static_cast<int>(msg.wParam); }
extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE, HINSTANCE, LPTSTR, int nCmdShow) { #ifdef _CRTDBG_MAP_ALLOC _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); #endif // TODO: Place code here. MSG msg = {0}; HACCEL hAccelTable; INITCOMMONCONTROLSEX InitCtrlEx; InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX); InitCtrlEx.dwICC = 0x00004000; //ICC_STANDARD_CLASSES; InitCommonControlsEx(&InitCtrlEx); _bstr_t requestedURL; int argc = 0; WCHAR** argv = CommandLineToArgvW(GetCommandLineW(), &argc); for (int i = 1; i < argc; ++i) { if (!wcsicmp(argv[i], L"--transparent")) s_usesLayeredWebView = true; else if (!wcsicmp(argv[i], L"--desktop")) s_fullDesktop = true; else if (!requestedURL) requestedURL = argv[i]; } // Initialize global strings LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInst, IDC_WINLAUNCHER, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInst); if (shouldUseFullDesktop()) computeFullDesktopFrame(); // Init COM OleInitialize(NULL); if (usesLayeredWebView()) { hURLBarWnd = CreateWindow(L"EDIT", L"Type URL Here", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT, 0, 0, hInst, 0); } else { hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInst, 0); if (!hMainWnd) return FALSE; hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE | BS_TEXT, 0, 0, 0, 0, hMainWnd, 0, hInst, 0); hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0); hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, CONTROLBUTTON_WIDTH * 2, 0, 0, 0, hMainWnd, 0, hInst, 0); ShowWindow(hMainWnd, nCmdShow); UpdateWindow(hMainWnd); } DefEditProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC)); DefButtonProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC)); SetWindowLongPtr(hURLBarWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(EditProc)); SetWindowLongPtr(hBackButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(BackButtonProc)); SetWindowLongPtr(hForwardButtonWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(ForwardButtonProc)); SetFocus(hURLBarWnd); RECT clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy }; IWebPreferencesPtr tmpPreferences; if (FAILED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, reinterpret_cast<void**>(&tmpPreferences.GetInterfacePtr())))) goto exit; if (FAILED(tmpPreferences->standardPreferences(&gStandardPreferences.GetInterfacePtr()))) goto exit; if (!setToDefaultPreferences()) goto exit; HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&gWebView.GetInterfacePtr())); if (FAILED(hr)) goto exit; hr = gWebView->QueryInterface(IID_IWebViewPrivate, reinterpret_cast<void**>(&gWebViewPrivate.GetInterfacePtr())); if (FAILED(hr)) goto exit; hr = WebKitCreateInstance(CLSID_WebHistory, 0, __uuidof(gWebHistory), reinterpret_cast<void**>(&gWebHistory.GetInterfacePtr())); if (FAILED(hr)) goto exit; gWebHost = new WinLauncherWebHost(); gWebHost->AddRef(); hr = gWebView->setFrameLoadDelegate(gWebHost); if (FAILED(hr)) goto exit; gPrintDelegate = new PrintWebUIDelegate; gPrintDelegate->AddRef(); hr = gWebView->setUIDelegate(gPrintDelegate); if (FAILED (hr)) goto exit; gAccessibilityDelegate = new AccessibilityDelegate; gAccessibilityDelegate->AddRef(); hr = gWebView->setAccessibilityDelegate(gAccessibilityDelegate); if (FAILED (hr)) goto exit; hr = gWebView->setHostWindow(reinterpret_cast<OLE_HANDLE>(hMainWnd)); if (FAILED(hr)) goto exit; hr = gWebView->initWithFrame(clientRect, 0, 0); if (FAILED(hr)) goto exit; if (!requestedURL) { IWebFramePtr frame; hr = gWebView->mainFrame(&frame.GetInterfacePtr()); if (FAILED(hr)) goto exit; _bstr_t defaultHTML(L"<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src=\"http://webkit.org/images/icon-gold.png\" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>"); frame->loadHTMLString(defaultHTML.GetBSTR(), 0); } hr = gWebViewPrivate->setTransparent(usesLayeredWebView()); if (FAILED(hr)) goto exit; hr = gWebViewPrivate->setUsesLayeredWindow(usesLayeredWebView()); if (FAILED(hr)) goto exit; hr = gWebViewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&gViewWindow)); if (FAILED(hr) || !gViewWindow) goto exit; if (usesLayeredWebView()) subclassForLayeredWindow(); resizeSubViews(); ShowWindow(gViewWindow, nCmdShow); UpdateWindow(gViewWindow); hAccelTable = LoadAccelerators(hInst, MAKEINTRESOURCE(IDC_WINLAUNCHER)); if (requestedURL.length()) loadURL(requestedURL.GetBSTR()); // Main message loop: #if USE(CF) _CFRunLoopSetWindowsMessageQueueMask(CFRunLoopGetMain(), QS_ALLINPUT | QS_ALLPOSTMESSAGE, kCFRunLoopDefaultMode); CFRunLoopRun(); #else while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } #endif exit: gPrintDelegate->Release(); shutDownWebKit(); #ifdef _CRTDBG_MAP_ALLOC _CrtDumpMemoryLeaks(); #endif // Shut down COM. OleUninitialize(); return static_cast<int>(msg.wParam); }