Exemple #1
0
static HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler *iface, DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
{
    WebBrowserContainer *This = impl_from_IDocHostUIHandler(iface);
    DWORD cmdid, menu_id = 0;
    HMENU menu, submenu;

    TRACE("(%p)->(%d %s)\n", This, dwID, wine_dbgstr_point(ppt));

    menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_WEBBROWSER));
    if (!menu)
        return S_OK;

    /* FIXME: Support more menu types. */
    if(dwID == CONTEXT_MENU_TEXTSELECT)
        menu_id = 1;

    submenu = GetSubMenu(menu, menu_id);

    cmdid = TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
            ppt->x, ppt->y, 0, This->hwndWindow, NULL);
    DestroyMenu(menu);

    switch(cmdid) {
    case IDTB_BACK:
        DoPageAction(This, WB_GOBACK);
        break;
    case IDTB_FORWARD:
        DoPageAction(This, WB_GOFORWARD);
        break;
    case MIID_SELECTALL:
        IWebBrowser2_ExecWB(This->web_browser, OLECMDID_SELECTALL, 0, NULL, NULL);
        break;
    case MIID_VIEWSOURCE:
        FIXME("View source\n");
        break;
    case IDTB_PRINT:
        DoPageAction(This, WB_PRINT);
        break;
    case IDTB_REFRESH:
        DoPageAction(This, WB_REFRESH);
        break;
    case MIID_PROPERTIES:
        FIXME("Properties\n");
        break;
    case MIID_COPY:
        IWebBrowser2_ExecWB(This->web_browser, OLECMDID_COPY, 0, NULL, NULL);
        break;
    case MIID_PASTE:
        IWebBrowser2_ExecWB(This->web_browser, OLECMDID_PASTE, 0, NULL, NULL);
        break;
    case MIID_CUT:
        IWebBrowser2_ExecWB(This->web_browser, OLECMDID_CUT, 0, NULL, NULL);
        break;
    }

    return S_OK;
}
Exemple #2
0
static void TB_OnClick(HWND hWnd, DWORD dwID)
{
    HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);

    switch (dwID)
    {
        case IDTB_STOP:
            DoPageAction(info, WB_STOP);
            break;
        case IDTB_REFRESH:
            DoPageAction(info, WB_REFRESH);
            break;
        case IDTB_BACK:
            DoPageAction(info, WB_GOBACK);
            break;
        case IDTB_HOME:
            NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
            break;
        case IDTB_FORWARD:
            DoPageAction(info, WB_GOFORWARD);
            break;
        case IDTB_PRINT:
            DoPageAction(info, WB_PRINT);
            break;
        case IDTB_EXPAND:
        case IDTB_CONTRACT:
            ExpandContract(info);
            break;
        case IDTB_SYNC:
            DoSync(info);
            break;
        case IDTB_OPTIONS:
            DisplayPopupMenu(info);
            break;
        case IDTB_NOTES:
        case IDTB_CONTENTS:
        case IDTB_INDEX:
        case IDTB_SEARCH:
        case IDTB_HISTORY:
        case IDTB_FAVORITES:
            /* These are officially unimplemented as of the Windows 7 SDK */
            break;
        case IDTB_BROWSE_FWD:
        case IDTB_BROWSE_BACK:
        case IDTB_JUMP1:
        case IDTB_JUMP2:
        case IDTB_CUSTOMIZE:
        case IDTB_ZOOM:
        case IDTB_TOC_NEXT:
        case IDTB_TOC_PREV:
            break;
    }
}
LRESULT CALLBACK MWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
	switch (uMsg){
	case WM_CREATE:
		hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
        return 0 ;
	case WM_COMMAND:
		hMenu = GetMenu (hwnd) ;
		switch (LOWORD (wParam))
          {
		  case ACCELERATOR_COPY:
			   p_IWebBrowser2->ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
			   return 0;
		  case ACCELERATOR_PASTE:
			   p_IWebBrowser2->ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
			   return 0;
		  case ACCELERATOR_DELETE:
			   p_IWebBrowser2->ExecWB(OLECMDID_DELETE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
			   return 0;
		  case ACCELERATOR_SELECTALL:
			   p_IWebBrowser2->ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL);
			   return 0;
		  case ACCELERATOR_FIND:
			   MSG tempmsg;
			   return DoPageAction(p_IWebBrowser2, WEBPAGE_FIND, &tempmsg);
          case 65535:
			   if(hDlgModeless == 0){
				   hDlgModeless = CreateDialog (hInst, TEXT ("NEWWORD"), hwnd, NewWordDlgProc);
				   EnableMenuItem (hMenu, 65535, MF_GRAYED) ;
			   }
               return 0 ;
		  case 65534:
               DialogBox (hInst, TEXT ("ABOUT"), hwnd, AboutDlgProc);
               return 0 ;
		  case 65533:
			   if(hDlgRecord ==0){
				   hDlgRecord = CreateDialog(hInst, TEXT("RECORD"), hwnd, RecordDlgProc);
				   EnableMenuItem(hMenu, 65533, MF_GRAYED);
			   }
			   return 0;
          }
	case WM_SIZE:
		MoveWindow(Googlehwnd, 0, 0, LOWORD (lParam), HIWORD (lParam), 0);
		SendMessage(Googlehwnd, WM_SYSCOMMAND, SC_MAXIMIZE, lParam);
		if(!HollyFirst){
			SendMessage(hwnd, WM_COMMAND, 65535, lParam);
		    HollyFirst = 1;
		}
		return 1;
	case WM_SETFOCUS:
		SetFocus(WBhwnd);
		return 1;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 1;
	}
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Exemple #4
0
static void TB_OnClick(HWND hWnd, DWORD dwID)
{
    HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);

    switch (dwID)
    {
        case IDTB_STOP:
            DoPageAction(info, WB_STOP);
            break;
        case IDTB_REFRESH:
            DoPageAction(info, WB_REFRESH);
            break;
        case IDTB_BACK:
            DoPageAction(info, WB_GOBACK);
            break;
        case IDTB_HOME:
            NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
            break;
        case IDTB_FORWARD:
            DoPageAction(info, WB_GOFORWARD);
            break;
        case IDTB_EXPAND:
        case IDTB_CONTRACT:
        case IDTB_SYNC:
        case IDTB_PRINT:
        case IDTB_OPTIONS:
        case IDTB_BROWSE_FWD:
        case IDTB_BROWSE_BACK:
        case IDTB_JUMP1:
        case IDTB_JUMP2:
        case IDTB_CUSTOMIZE:
        case IDTB_ZOOM:
        case IDTB_TOC_NEXT:
        case IDTB_TOC_PREV:
            break;
    }
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hInstNULL, LPSTR lpszCmdLine, int nCmdShow)
{
	HINSTANCE		Lilycwebdll;
	MSG				msg;
	WNDCLASSEX		wc, Mwc;

	static std::string str;
	std::ifstream file ("GRE.txt");
	if(file.is_open()){
		while (! file.eof() ){
			std::getline(file, str);
			VocList.push_back(str);
		}
		file.close();
	}
	else{
		MessageBox(0, TEXT("Can't open GRE.txt"), TEXT("Error"), 0);
		return -1;
	}

	ZeroMemory(&Mwc, sizeof(WNDCLASSEX));
	Mwc.cbSize = sizeof(WNDCLASSEX);
	Mwc.hInstance = hInstance;
	Mwc.lpfnWndProc = MWndProc;
	Mwc.lpszClassName = TEXT("Mother");
	Mwc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON1)) ;
	Mwc.lpszMenuName = TEXT("GRE");
	RegisterClassEx(&Mwc);

	// Create another window with another browser object embedded in it.
	Mhwnd = CreateWindowEx(0, TEXT("Mother"), TEXT("Lily GRE Vocabulary Suit"), 
			               WS_OVERLAPPEDWINDOW, 
						   CW_USEDEFAULT, CW_USEDEFAULT, 
						   CW_USEDEFAULT, CW_USEDEFAULT, 
						   NULL, NULL, hInstance, 0);
	ShowWindow(Mhwnd, nCmdShow);
	UpdateWindow(Mhwnd);

	// Load our DLL containing the OLE/COM code. We do this once-only. It's named "cwebpage.dll"
	if (Lilycwebdll = LoadLibrary(TEXT("Lilycwebpage.dll")))
	{
		// Get pointers to the EmbedBrowserObject, DisplayHTMLPage, DisplayHTMLStr, and UnEmbedBrowserObject
		// functions, and store them in some globals.

		// Get the address of the EmbedBrowserObject() function. NOTE: Only Reginald has this one
		lpEmbedBrowserObject = (EmbedBrowserObjectPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, EMBEDBROWSEROBJECTNAME);

		// Get the address of the UnEmbedBrowserObject() function. NOTE: Only Reginald has this one
		lpUnEmbedBrowserObject = (UnEmbedBrowserObjectPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, UNEMBEDBROWSEROBJECTNAME);

		// Get the address of the DisplayHTMLPagePtr() function
		lpDisplayHTMLPage = (DisplayHTMLStrPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, DISPLAYHTMLPAGENAME);

		// Get the address of the DisplayHTMLStr() function
		lpDisplayHTMLStr = (DisplayHTMLStrPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, DISPLAYHTMLSTRNAME);

		// Get the address of the ResizeBrowser() function
		lpResizeBrowser = (ResizeBrowserPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, RESIZEBROWSERNAME);

		lpGetWebPtrs = (GetWebPtrsPtr *)GetProcAddress((HINSTANCE)Lilycwebdll, GETWEBPTRSNAME);

		// Register the class of our window to host the browser. 'WindowProc' is our message handler
		// and 'ClassName' is the class name. You can choose any class name you want.
		ZeroMemory(&wc, sizeof(WNDCLASSEX));
		wc.cbSize = sizeof(WNDCLASSEX);
		wc.hInstance = hInstance;
		wc.lpfnWndProc = WndProc;
		wc.lpszClassName = TEXT("Googledic");
		RegisterClassEx(&wc);

		// Create another window with another browser object embedded in it.
		Googlehwnd = CreateWindowEx(0, TEXT("Googledic"), TEXT("Google Dictionary"), 
			                             WS_OVERLAPPED | WS_CHILD, 
										 0, 0, 
										 CW_USEDEFAULT, CW_USEDEFAULT, 
										 Mhwnd, (HMENU) 10, hInstance, 0);
		// For this window, display a URL. This could also be a HTML file on disk such as "c:\\myfile.htm".
		(*lpDisplayHTMLPage)(Googlehwnd, TEXT("http://www.google.com.tw/dictionary"));
		ShowWindow(Googlehwnd, SW_MAXIMIZE);
		UpdateWindow(Googlehwnd);
	}
	else{
		MessageBox(0, TEXT("Can't open Lilycwebpage.dll!"), TEXT("ERROR"), MB_OK);
	    return(-1);
	}

	HACCEL hAccel ;
	hAccel = LoadAccelerators (hInstance, TEXT("GRE_ACCELERATOR")) ;

	while (GetMessage(&msg, 0, 0, 0))
	{
		if(hDlgModeless == 0 || !IsDialogMessage (hDlgModeless, &msg) ){
			if( hDlgRecord == 0 || !IsDialogMessage(hDlgRecord, &msg) ){
			if(WBhwnd == 0)//Don't know where to get the WBhwnd handle, so put it here
				EnumChildWindows(Googlehwnd, WebEnumChildProc, (LPARAM) &WBhwnd);

			//Support for google suggest
			if(msg.hwnd == WBhwnd && msg.message >= WM_KEYDOWN && msg.message <= WM_KEYLAST && DoPageAction(p_IWebBrowser2, WEBPAGE_KEYSTROKE, &msg) == 0)
				continue;

			//Normal message loop
			if (!TranslateAccelerator (Mhwnd, hAccel, &msg)){
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			}}
	}

	// Free the DLL.
	FreeLibrary(Lilycwebdll);

	if(!ListBoxVec.empty()){
			SYSTEMTIME SystemTime; GetSystemTime(&SystemTime);
			std::stringstream ThisInstFileName;
			ThisInstFileName << SystemTime.wYear; ThisInstFileName << ' ';
			ThisInstFileName << ConvertMonthToString(SystemTime.wMonth); ThisInstFileName << ' ';
			ThisInstFileName << SystemTime.wDay; ThisInstFileName << ' ';
			ThisInstFileName << SystemTime.wHour; ThisInstFileName << '.';
			ThisInstFileName << SystemTime.wMinute; ThisInstFileName << '.';
			ThisInstFileName << SystemTime.wSecond; ThisInstFileName << ".txt";
			std::ofstream ThisInstFile(ThisInstFileName.str());
			int ListBoxVecSize = ListBoxVec.size();
			for(int i = 0; i != ListBoxVecSize; ++i){
				ThisInstFile << ListBoxVec[i];
				ThisInstFile << '\n';
			}
			ThisInstFile.close();
		}

	return(0);
}
BOOL DisplayHTMLPage(PWBOBJ pwbo, LPCTSTR pszWebPageName)
{
	IWebBrowser2 *webBrowser2;
	VARIANT myURL;
	IOleObject *browserObject;

	if(!pwbo)
		return FALSE;

	// Special browser commands

	if(!stricmp(pszWebPageName,      "cmd:back"))
		return DoPageAction(pwbo, WEBPAGE_GOBACK, NULL);
	else if(!stricmp(pszWebPageName, "cmd:forward"))
		return DoPageAction(pwbo, WEBPAGE_GOFORWARD, NULL);
//	else if(!stricmp(pszWebPageName, "cmd:home"))
//		return DoPageAction(pwbo, WEBPAGE_GOHOME, NULL);
//	else if(!stricmp(pszWebPageName, "cmd:search"))
//		return DoPageAction(pwbo, WEBPAGE_SEARCH, NULL);
	else if(!stricmp(pszWebPageName, "cmd:refresh"))
		return DoPageAction(pwbo, WEBPAGE_REFRESH, NULL);
	else if(!stricmp(pszWebPageName, "cmd:stop"))
		return DoPageAction(pwbo, WEBPAGE_STOP, NULL);

	else if(!stricmp(pszWebPageName, "cmd:busy")) {
		BOOL bBusy = FALSE;

		DoPageAction(pwbo, WEBPAGE_BUSY, &bBusy);
//		printf("[%d] ", bBusy);
		return bBusy;
	}

	else if(!stricmp(pszWebPageName, "cmd:blank"))
		return DisplayHTMLString(pwbo, "about:blank");

	// Normal page

//	browserObject = *((IOleObject **)GetWindowLong(hwnd, GWL_USERDATA));
	browserObject = *((IOleObject **)pwbo->lparams[0]);

	if(!browserObject)
		return FALSE;

	if(!browserObject->lpVtbl)
		return FALSE;

	if(!browserObject->lpVtbl->QueryInterface)
		return FALSE;

	if(!browserObject->lpVtbl->QueryInterface(browserObject, (IID *)&IID_IWebBrowser2, (void**)&webBrowser2)) {
		VariantInit(&myURL);
		myURL.vt = VT_BSTR;

#ifndef UNICODE
		{
			wchar_t *buffer;
			DWORD size;

			size = MultiByteToWideChar(CP_ACP, 0, pszWebPageName, -1, 0, 0);
			if (!(buffer = (wchar_t *)GlobalAlloc(GMEM_FIXED, sizeof(wchar_t) * size))) goto badalloc;
			MultiByteToWideChar(CP_ACP, 0, pszWebPageName, -1, buffer, size);
			myURL.bstrVal = SysAllocString(buffer);
			GlobalFree(buffer);
		}
#else
		myURL.bstrVal = SysAllocString(pszWebPageName);
#endif

		if (!myURL.bstrVal) {
badalloc:	webBrowser2->lpVtbl->Release(webBrowser2);
			return FALSE;
		}

		webBrowser2->lpVtbl->Navigate2(webBrowser2, &myURL, 0, 0, 0, 0);
		VariantClear(&myURL);
		webBrowser2->lpVtbl->Release(webBrowser2);
		return TRUE;
	}
	return FALSE;
}