Esempio n. 1
0
bool QCefWebView::CreateBrowser(const QSize& size) {
    //qDebug() << __FUNCTION__ << __LINE__;
    if (browser_state_ != kNone || size.isEmpty()) {
        return false;
    }
    mutex_.lock();
    if (browser_state_ != kNone) {
        mutex_.unlock();
        return false;
    }
    //qDebug() << __FUNCTION__ << __LINE__;
    CefWindowInfo info;
    CefBrowserSettings settings;
#if defined(WIN32)
    RECT rect = {0, 0, size.width(), size.height()};
    info.SetAsChild((HWND) this->winId(), rect);
#else
    CefRect rect(0, 0, size.width(), size.height());
    info.SetAsChild(this->winId(), rect);
#endif
    qcef_client_handler->set_listener(this);
    QString url = url_.isEmpty() ? kUrlBlank : url_.toString();
    CefBrowserHost::CreateBrowser(info,
                                  qcef_client_handler.get(),
                                  CefString(url.toStdWString()),
                                  settings,
                                  NULL);

    browser_state_ = kCreating;
    mutex_.unlock();
    return true;
}
// WM_CREATE handler
BOOL cef_main_window::HandleCreate() 
{
    // Create the single static handler class instance
    g_handler = new ClientHandler();
    g_handler->SetMainHwnd(mWnd);

    RECT rect;

    GetCefBrowserRect(rect);

    CefWindowInfo info;
    CefBrowserSettings settings;

    settings.web_security = STATE_DISABLED;

    // Initialize window info to the defaults for a child window
    info.SetAsChild(mWnd, rect);

    // Creat the new child browser window
    CefBrowserHost::CreateBrowser(info,
        static_cast<CefRefPtr<CefClient> >(g_handler),
        ::AppGetInitialURL(), settings);

    return TRUE;
}
Esempio n. 3
0
void AddWebView(CefWindowHandle parent, RECT windowRect, char* url, Settings* settings) {
  CefWindowInfo windowInfo;
  windowInfo.SetAsChild(parent, windowRect);
  windowInfo.SetTransparentPainting(true);
  g_handler->browserSettings_.web_security_disabled = settings->getBoolean("disableSecurity", false);
  CefBrowser::CreateBrowser(windowInfo, static_cast<CefRefPtr<CefClient>>(g_handler), url, g_handler->browserSettings_);
}
Esempio n. 4
0
int CefJamCEFHtmlView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here


    CRect rcClient;
    this->GetClientRect(&rcClient);

    // TODO:  Add your specialized creation code here
    CefRefPtr<CefJamClientHandler> client(new CefJamClientHandler());
    m_pClientHandler = client;

    CefWindowInfo info;
    info.SetAsChild( m_hWnd, rcClient);

    CefBrowserSettings browserSettings;

    //static_cast<CefRefPtr<CefClient> >(client)
    bool bCreate = CefBrowserHost::CreateBrowser( info,static_cast<CefRefPtr<CefClient> >(client),
                   "http://www.baidu.com", browserSettings);

    return 0;
}
Esempio n. 5
0
int CTransChatWebWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!theApp.GetWindowManager()->Attach(GetSafeHwnd(), _T("trans_chat_web_wnd")))
		return -1;
	
	SetWindowText(_T("专人翻译"));

	g_SessionData.chat_hwnd = GetSafeHwnd();

	m_shadow_win.create(GetSafeHwnd());

	m_Recorder.Attach(GetSafeHwnd());

	//m_pV8Exthandler = new ClientV8ExtHandler(this);

	CefRefPtr<CefWebClient> client(new CefWebClient());
	m_cWebClient = client;

	CefSettings cSettings;
	CefSettingsTraits::init(&cSettings);
	cSettings.multi_threaded_message_loop = true;
	CefRefPtr<CefApp> spApp;
	CefInitialize(cSettings, spApp);

	//CefRegisterExtension("v8/Ext", s_JsExt, m_pV8Exthandler);

	duHwndObj* pWebHwndobj = (duHwndObj*)GetPluginByName(GetSafeHwnd(), _T("chat_web_hwndobj"));
	RECT rc = { 0, 0, 0, 0 };
	pWebHwndobj->GetRect(&rc);
	CefWindowInfo info;
	info.SetAsChild(GetSafeHwnd(), rc);

	TCHAR szHtml[MAX_PATH] = { 0 };
	::GetModuleFileName(GetModuleHandle(NULL), szHtml, _countof(szHtml));
	::PathRemoveFileSpec(szHtml);
	::PathAppend(szHtml, _T("html\\trans.html"));

	CefBrowserSettings browserSettings;
	CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient>>(client),
		szHtml, browserSettings);

	InitExtension();
	//RunExtensionTest(m_cWebClient->GetBrowser());

	//pWebHwndobj->Attach(m_cWebClient->GetBrowser()->GetWindowHandle());

	//m_Recorder.StartRecord();
	
	//StrCpy(m_szVoicePath, _T("C:\\Users\\Administrator\\AppData\\Roaming\\MyEcho\\oDHO7Q3LRUtxLg4E9R1adjrsv5irzYa8\\task\\test.amr"));

	return 0;
}
Esempio n. 6
0
void CefFacade::CreateBrowser(HWND Parent_,const char* startUrl_,pFun pFn_)
{	
	m_clientHandler = new ClientHandler(pFn_); 

	CefWindowInfo info;  
	CefBrowserSettings b_settings;  

	RECT rect;
	GetClientRect(Parent_,&rect);
	info.SetAsChild(Parent_, rect);  

	if(strlen(startUrl_)==0)
		m_StartupURL="about://blank";
	else
		m_StartupURL = string_To_UTF8(startUrl_);
	CefBrowserHost::CreateBrowser(info, m_clientHandler.get(), m_StartupURL, b_settings, NULL);
}
Esempio n. 7
0
	void __stdcall CreateBrowser(HWND Parent_,const char* startUrl_=NULL)
	{
		s_clientHandler = new ClientHandler(NULL); 

		CefWindowInfo info;  
		CefBrowserSettings b_settings;  

		RECT rect;
		GetClientRect(Parent_,&rect);
		info.SetAsChild(Parent_, rect);  
		
		std::string m_StartupURL;
		if(strlen(startUrl_)==0)
			m_StartupURL="about://blank";
		else
			m_StartupURL = string_To_UTF8(startUrl_);
		CefBrowserHost::CreateBrowser(info, s_clientHandler.get(), m_StartupURL, b_settings, NULL);
	}
//Create the browser in our previously created window with hWnd handle
//and the url to load. This function must be called in WM_CREATE
void SimpleCEFDLL_CreateBrowser( HWND hWnd, const wchar_t* url )
{
	CefRefPtr<zSimpleCefHandler> simpleCefHandler = new zSimpleCefHandler;

	g_App->SetCEFHandler( hWnd, simpleCefHandler );

	//We fill the info to adapt our window to embedd the browser
	CefWindowInfo info;

	//Get the window rect
	RECT rect;
	GetClientRect( hWnd, &rect);
	
	//We will create the browser as a child of our window
	info.SetAsChild( hWnd,rect);

	CefBrowserSettings settingsBrowser;
    CefBrowserHost::CreateBrowser(info, simpleCefHandler.get(), CefString( url ), settingsBrowser, NULL);
}
Esempio n. 9
0
value cef_init()
{
	CefSettings settings;
	CefMainArgs args;
	settings.multi_threaded_message_loop = true;
	printf("before init\n");
	CefInitialize(args, settings, NULL);
	printf("after init\n");
	
	HWND hWnd;
	RECT rect;

	// Init First Chrome
	CefBrowserSettings browserSettings;
	CefWindowInfo info;

	g_handler = new myClientHandler();
	DWORD dwProcID = GetCurrentProcessId();
	hWnd = GetTopWindow(GetDesktopWindow());
	while(hWnd)
    {
		DWORD dwWndProcID = 0;
		GetWindowThreadProcessId(hWnd, &dwWndProcID);
		if(dwWndProcID == dwProcID)
			break; 
		hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
    }
	
	printf("hwnd %d\n", hWnd);

	GetClientRect(hWnd, &rect);
	printf("before client rect\n");
	info.SetAsChild(hWnd,rect);
	printf("set as child\n");

	CefBrowserHost::CreateBrowser(info,static_cast< CefRefPtr<CefClient> >(g_handler),"http://www.google.com", browserSettings);
	printf("create browser\n");
	
	return alloc_null();
}
Esempio n. 10
0
void CCEFView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

    CefRefPtr<ClientHandler> client(new ClientHandler());
	m_clientHandler = client;

    CefWindowInfo info;
	RECT rect;
	GetClientRect(&rect);
	info.SetAsChild(GetSafeHwnd(), rect);

	CefBrowserSettings browserSettings;
  browserSettings.web_security_disabled = true;

	char path_buffer[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	errno_t err;
	GetModuleFileNameA(NULL, path_buffer, sizeof(path_buffer));
	err = _splitpath_s(path_buffer, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
	if (err != 0)
	{
		//TODO: Add Error Handler
	}
	std::string s = dir;
	s += "html";
	err = _makepath_s(path_buffer, _MAX_PATH, drive, s.c_str(), "index", "html");
	if (err != 0)
	{
		//TODO: Add Error Handler
	}
	CefBrowser::CreateBrowser(info, static_cast<CefRefPtr<CefClient> >(client), path_buffer, browserSettings); 

	// TODO: Add your specialized code here and/or call the base class
}
Esempio n. 11
0
bool QCefWebView::CreateBrowser(const QSize& size) {
  //qDebug() << __FUNCTION__ << __LINE__;
  if (browser_state_ != kNone || size.isEmpty()) {
    return false;
  }
  mutex_.lock();
  if (browser_state_ != kNone) {
    mutex_.unlock();
    return false;
  }
  //qDebug() << __FUNCTION__ << __LINE__;
  RECT rect;
  rect.left = 0;
  rect.top = 0;
  rect.right = size.width();
  rect.bottom = size.height();

  CefWindowInfo info;
  CefBrowserSettings settings;

  // By default, as a child window.
  info.SetAsChild(this->winId(), rect);

  g_handler->set_listener(this);

  QString url = url_.isEmpty() ? kUrlBlank : url_.toString();
  CefBrowserHost::CreateBrowser(info,
                                g_handler.get(),
                                CefString(url.toStdWString()),
                                settings,
                                NULL);

  browser_state_ = kCreating;
  mutex_.unlock();
  return true;
}
Esempio n. 12
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

#ifdef SHOW_TOOLBAR_UI
  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }
    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else
#endif // SHOW_TOOLBAR_UI
  {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

#ifdef SHOW_TOOLBAR_UI
      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;
#endif // SHOW_TOOLBAR_UI

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      settings.file_access_from_file_urls_allowed = true;
      settings.universal_access_from_file_urls_allowed = true;

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          szInitialUrl, settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_EXIT:
        if (g_handler.get()) {
          g_handler->QuittingApp(true);
    	  g_handler->DispatchCloseToNextBrowser();
    	} else {
          DestroyWindow(hWnd);
		}
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
/*
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
*/
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
#ifdef SHOW_TOOLBAR_UI
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
#endif // SHOW_TOOLBAR_UI
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
#ifdef SHOW_TOOLBAR_UI
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;
#endif // SHOW_TOOLBAR_UI

          HDWP hdwp = BeginDeferWindowPos(1);
#ifdef SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
#endif // SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {

        HWND hWnd = GetActiveWindow();
        SaveWindowRect(hWnd);

        // If we already initiated the browser closing, then let default window proc handle it.
        HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
        if (closing) {
		    RemoveProp(browserHwnd, CLOSING_PROP);
			break;
		}

        g_handler->QuittingApp(true);
        g_handler->DispatchCloseToNextBrowser();
        return 0;
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 13
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info, g_handler.get(),
          g_handler->GetStartupURL(), settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_SCHEME_HANDLER:  // Test the scheme handler
        if (browser.get())
          scheme_test::RunTest(browser);
        return 0;
      case ID_TESTS_BINDING:  // Test JavaScript binding
        if (browser.get())
          binding_test::RunTest(browser);
        return 0;
      case ID_TESTS_DIALOGS:  // Test JavaScript dialogs
        if (browser.get())
          RunDialogTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_DOM_ACCESS:  // Test DOM access
        if (browser.get())
          dom_test::RunTest(browser);
        return 0;
      case ID_TESTS_LOCALSTORAGE:  // Test localStorage
        if (browser.get())
          RunLocalStorageTest(browser);
        return 0;
      case ID_TESTS_ACCELERATED2DCANVAS:  // Test accelerated 2d canvas
        if (browser.get())
          RunAccelerated2DCanvasTest(browser);
        return 0;
      case ID_TESTS_ACCELERATEDLAYERS:  // Test accelerated layers
        if (browser.get())
          RunAcceleratedLayersTest(browser);
        return 0;
      case ID_TESTS_WEBGL:  // Test WebGL
        if (browser.get())
          RunWebGLTest(browser);
        return 0;
      case ID_TESTS_HTML5VIDEO:  // Test HTML5 video
        if (browser.get())
          RunHTML5VideoTest(browser);
        return 0;
      case ID_TESTS_XMLHTTPREQUEST:  // Test XMLHttpRequest
        if (browser.get())
          RunXMLHTTPRequestTest(browser);
        return 0;
      case ID_TESTS_DRAGDROP:  // Test drag & drop
        if (browser.get())
          RunDragDropTest(browser);
        return 0;
      case ID_TESTS_GEOLOCATION:  // Test geolocation
        if (browser.get())
          RunGeolocationTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          ModifyZoom(browser, 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          ModifyZoom(browser, -0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->GetHost()->SetZoomLevel(0.0);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;

          HDWP hdwp = BeginDeferWindowPos(1);
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Let the browser window know we are about to destroy it.
          browser->GetHost()->ParentWindowWillClose();
        }
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 14
0
//
//  FUNCTION: MainWindowWndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK MainWindowWndProc(
    HWND hWnd, 
    UINT message, 
    WPARAM wParam,
    LPARAM lParam) 
{
    PAINTSTRUCT ps;
    HDC hdc;
    HMENU sysMenu;

    // Callback for the main window
    switch (message) 
    {
        case WM_CREATE: 
        {
            DWORD bufferSize = 65535;
            wstring buff;
            buff.resize(bufferSize);
            bufferSize = ::GetEnvironmentVariable(L"lala", &buff[0], bufferSize);

            if (bufferSize)
            {
                buff.resize(bufferSize);
                SetEnvironmentVariable(L"lala", NULL);
            }

            // Add exit option to system menu
            TCHAR szDescription[INFOTIPSIZE];
            StringManager.LoadString(IDS_EXIT_CAFFEINE, szDescription, INFOTIPSIZE);

            sysMenu = GetSystemMenu(hWnd, FALSE);
            InsertMenu(sysMenu, 2, MF_SEPARATOR, 0, L"-");
            AppendMenu(sysMenu, MF_STRING, IDS_EXIT_CAFFEINE, szDescription);

            WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);
            app->m_WindowHandler[mainUUID] = new CaffeineClientHandler();
            app->m_WindowHandler[mainUUID]->SetMainHwnd(hWnd);

            // Create the child windows used for navigation
            RECT rect;

            GetClientRect(hWnd, &rect);

            CefWindowInfo info;
            CefBrowserSettings browser_settings;
            browser_settings.universal_access_from_file_urls = STATE_ENABLED;
//            browser_settings.file_access_from_file_urls = STATE_ENABLED;
            browser_settings.web_security = STATE_DISABLED;
            browser_settings.local_storage = STATE_ENABLED;
            browser_settings.application_cache = STATE_DISABLED;
            browser_settings.javascript_open_windows = STATE_DISABLED;
//            browser_settings.accelerated_compositing = STATE_DISABLED;
            
            // Initialize window info to the defaults for a child window
            info.SetAsChild(hWnd, rect);

            // Create the new child browser window
            wstring URL(L"file:///stub.html?" + AppGetCommandLine()->GetSwitchValue("querystring").ToWString());
            if (AppGetCommandLine()->HasSwitch("yid"))
            {
                URL += L"&yid=" + ExtractYID(AppGetCommandLine()->GetSwitchValue("yid").ToWString());
            }
            //  TODO:  Can we just use the same window handler (assuming we get rid of the globals and add some sync)?
            CefRefPtr<CefBrowser> browser = CefBrowserHost::CreateBrowserSync(info, app->m_WindowHandler[mainUUID].get(), URL, browser_settings, NULL);
            app->m_WindowHandler[mainUUID]->m_MainBrowser = browser;
            mainWinBrowser = browser;

            app->hwndRender = hWnd; // setup current handle to use in Show/HideWindow
        
            CefRefPtr<CefProcessMessage> process_message = CefProcessMessage::Create("setHandle");
            process_message->GetArgumentList()->SetInt(0, reinterpret_cast<int>(hWnd));
            browser->SendProcessMessage(PID_RENDERER, process_message);

            // Send the main window creation start time to the renderer
            process_message = CefProcessMessage::Create("mainWindowCreationTime");
            CefRefPtr<CefBinaryValue> startTime = CefBinaryValue::Create(&beginMainWindowCreationTime, sizeof(CefTime));
            process_message->GetArgumentList()->SetBinary(0, startTime);
            browser->SendProcessMessage(PID_RENDERER, process_message);

            if (bufferSize)
            {
                process_message = CefProcessMessage::Create("lala");
                process_message->GetArgumentList()->SetString(0, buff);
                browser->SendProcessMessage(PID_RENDERER, process_message);
            }

            SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(new WindowExtras));

            SetTimer(hWnd, IDLETIMER, IdleTimerPollIntervalMS, NULL);
            SetTimer(hWnd, NETWORKTIMER, NetworkTimerPollIntervalMS, NULL);

            return 0;
        }

        case WM_MOVE:
            if (app->m_WindowHandler[mainUUID].get())
            {
                //  TODO:  Below is a hack to work around the fact that CEF isn't updating screenX and screenY.  Periodically,
                //  TODO:  check to see if they fix it.  
                //  TODO:  See issue https://code.google.com/p/chromiumembedded/issues/detail?id=1303&thanks=1303&ts=1402082749
                WINDOWINFO wi = {sizeof(WINDOWINFO), 0};
                GetWindowInfo(hWnd, &wi);
                RECT rClient = wi.rcWindow;

                CefString JS = "window.screenLeft = window.screenX = " + to_string(_Longlong(rClient.left)) + "; window.screenTop = window.screenY = " + 
                    to_string(_Longlong(rClient.top)) + ";";
                CefRefPtr<CefFrame> frame = app->m_WindowHandler[mainUUID]->GetBrowser()->GetMainFrame();
                frame->ExecuteJavaScript(JS, frame->GetURL(), 0);

                //  TODO:  Another workaround.  For whatever reason, the window positions get updated when the size changes,
                //  TODO:  but not when the window is moved.
                CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) 
                {
                    wi.cbSize = sizeof(WINDOWINFO);
                    GetWindowInfo(hwnd, &wi);
                    RECT rWindow = wi.rcWindow;

                    MoveWindow(hwnd, 0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top + 1, FALSE);
                    MoveWindow(hwnd, 0, 0, rWindow.right - rWindow.left, rWindow.bottom - rWindow.top, FALSE);
                }

                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent("move");
            }

            break;

        case WM_POWERBROADCAST:
            if (app->m_WindowHandler[mainUUID].get())
            {
                if (wParam == PBT_APMRESUMEAUTOMATIC || wParam == PBT_APMSUSPEND)
                {
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(wParam == PBT_APMSUSPEND? "suspend" : "resume");
                    //  Do we really need a return value?
                    return TRUE;
                }
            }
            break;

        case WM_WTSSESSION_CHANGE:
            if (app->m_WindowHandler[mainUUID].get())
            {
                string eventName;

                switch(wParam)
                {
                    //  Used
                    case WTS_SESSION_LOGON:
                        eventName = "os:logon";
                        break;
                    //  Used
                    case WTS_SESSION_LOGOFF:
                        eventName = "os:logoff";
                        break;
                    //  Used
                    case WTS_SESSION_LOCK:
                        eventName = "os:locked";
                        break;
                    //  Used
                    case WTS_SESSION_UNLOCK:
                        eventName = "os:unlocked";
                        break;
                }

                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(eventName);
            }
            break;

        case WM_PAINT:
            {
                //RECT cr = {0,};
                //::GetClientRect(hWnd, &cr);
                //::InvalidateRect(hWnd, &cr, FALSE);
                hdc = BeginPaint(hWnd, &ps);
                EndPaint(hWnd, &ps);
                return 0;
            }

        case WM_ACTIVATE:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent((LOWORD(wParam)>0)? "activated" : "deactivated");
            }
            break;
        case WM_SETFOCUS:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                // Pass focus to the browser window
                CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) PostMessage(hwnd, message, wParam, lParam);
            }
            return 0;

        case WM_SIZE:
            // Minimizing resizes the window to 0x0 which causes our layout to go all
            // screwy, so we just ignore it.
            if (wParam != SIZE_MINIMIZED && app->m_WindowHandler[mainUUID].get() && 
                app->m_WindowHandler[mainUUID]->GetBrowser()) 
            {
                    CefWindowHandle hwnd = app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                    if (hwnd) 
                    {
                        //  This will send a WM_SIZE and WM_PAINT message to the render process
                        SetWindowPos(hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER); 
                        return 0;
                    }
            }
            break;

        case WM_ERASEBKGND:
            if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) {
                CefWindowHandle hwnd =
                    app->m_WindowHandler[mainUUID]->GetBrowser()->GetHost()->GetWindowHandle();
                if (hwnd) {
                    // Dont erase the background if the browser window has been loaded
                    // (this avoids flashing)
                    return 0;
                }
            }
            break;

        case WM_SYSCOMMAND:
            if (wParam == IDS_EXIT_CAFFEINE) {
                PostMessage(hWnd, WM_CLOSE, g_exitCode, 0);
                return 0;
            }
            break;

        case WM_COMMAND:
            // Currently only option from the context menu is to exit, hence the fall through to the WM_CLOSE
            wParam = g_exitCode;

        case WM_CLOSE:
        {
            if (devMode || enableClose)
            {
                wParam = g_exitCode;
            }

            CefRefPtr<CaffeineClientHandler> handler = app->m_WindowHandler[mainUUID].get();

            if (handler && !handler->IsClosing()) {
                if (wParam == g_exitCode) // Jump list exit
                {
                    for (map<string, CefRefPtr<CaffeineClientHandler> >::iterator it=app->m_WindowHandler.begin(); it!=app->m_WindowHandler.end(); ++it)
                    {
                        if(it->second.get()) 
                        {
                            CefRefPtr<CefBrowser> browser = it->second->GetBrowser();
                            browser->GetHost()->CloseBrowser(false);
                        }
                    }

					//CefRefPtr<CefBrowser> browser = handler->GetBrowser();
					//if (browser.get()) {
					//	browser->GetHost()->CloseBrowser(false);
					//}
				} else {
                    ShowWindow(hWnd, SW_MINIMIZE);
                }
                return 0;
            }

            break;
        }

        case WM_TIMER:
        {
            if(IDLETIMER == wParam)
            {
                //  TODO:  Check timer id
                LASTINPUTINFO lif = {sizeof(LASTINPUTINFO), 0};
                GetLastInputInfo(&lif);
                UINT IdleTimePassed = GetTickCount() - lif.dwTime;
                
                WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
                bool CurrentlyIdle = (pWE->IdleTimeThreshold < IdleTimePassed);
                if(CurrentlyIdle != pWE->IsIdle)
                {
                    const CefString EventName = (CurrentlyIdle? "startIdle" : "stopIdle");
                    pWE->IsIdle = CurrentlyIdle;
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(EventName);
                }
            }
            //  TODO:  When we drop XP support, we can use COM and get network connectivity events.
            else if(NETWORKTIMER == wParam)
            {
                WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
                bool CurrentlyConnected = pWE->NetworkAvailable();
                if(CurrentlyConnected != pWE->IsConnected)
                {
                    const CefString EventName = (CurrentlyConnected? "os:online" : "os:offline");
                    pWE->IsConnected = CurrentlyConnected;
                    app->m_WindowHandler[mainUUID]->CreateAndDispatchCustomEvent(EventName);
                }
            }
            break;
        }

        case WM_DESTROY:
        {
            WTSUnRegisterSessionNotification(hWnd);
            // The frame window has exited

            if (!devMode)
            {
                jumpList.RemoveAllTasks();
            }

            KillTimer(hWnd, IDLETIMER);
            KillTimer(hWnd, NETWORKTIMER);
            WindowExtras *pWE = reinterpret_cast<WindowExtras *>(::GetWindowLongPtr(hWnd, 0));
            delete pWE;
            SetWindowLongPtr(hWnd, 0, 0);
            SetShutdownFlag(true);
            PostQuitMessage(0);
            return 0;
        }

        case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO minmaxInfoPtr = (LPMINMAXINFO) lParam;
            minmaxInfoPtr->ptMinTrackSize.x = MAIN_WINDOW_MIN_WIN_WIDTH;
            minmaxInfoPtr->ptMinTrackSize.y = MAIN_WINDOW_MIN_WIN_HEIGHT;

            // Keep the width the same
            RECT rect;
            GetWindowRect(hWnd, &rect);
            minmaxInfoPtr->ptMaxSize.x = (rect.right - rect.left);

            // Keep window at same position
            minmaxInfoPtr->ptMaxPosition.x = rect.left;
            minmaxInfoPtr->ptMaxPosition.y = 0;

            SystemParametersInfo( SPI_GETWORKAREA, 0, &rect, 0 );
            minmaxInfoPtr->ptMaxSize.y = (rect.bottom - rect.top);

            return 0;
        }

        case WM_COPYDATA:
        {
            BOOL retval = FALSE;
            PCOPYDATASTRUCT pCds = reinterpret_cast<PCOPYDATASTRUCT>(lParam);
            if (pCds->dwData == WM_PENDING_YID) 
            {
                if (app->m_WindowHandler[mainUUID].get() && app->m_WindowHandler[mainUUID]->GetBrowser()) 
                {
                    CefRefPtr<CefFrame> frame = app->m_WindowHandler[mainUUID]->GetBrowser()->GetMainFrame();
                    wstring code = L"Caffeine.pendingYIDs.push(\"";
                    //  TODO:  Escape this ... otherwise there's an XSS
                    code += static_cast<LPWSTR>(pCds->lpData);
                    code += L"\");";
                    frame->ExecuteJavaScript(code, frame->GetURL(), 0);
                }

                retval = TRUE;
            }
            return retval;
        }

        case CAFFEINE_SOCKETS_MSG:
            CefRefPtr<CefProcessMessage> process_message = CefProcessMessage::Create("invokeSocketMethod");
            process_message->GetArgumentList()->SetInt(0, wParam);
            if (WSAGETSELECTERROR(lParam))
            {
                process_message->GetArgumentList()->SetString(1, "error");
                process_message->GetArgumentList()->SetInt(2, WSAGETSELECTERROR(lParam));
            }
            else
            {
                //  No error
                switch(WSAGETSELECTEVENT(lParam))
                {
                    case FD_CONNECT:
                        process_message->GetArgumentList()->SetString(1, "connect");
                        break;
                    case FD_CLOSE:
                        process_message->GetArgumentList()->SetString(1, "close");
                        break;
                    case FD_READ:
                        process_message->GetArgumentList()->SetString(1, "read");
                        break;
                    case FD_WRITE:
                        process_message->GetArgumentList()->SetString(1, "write");
                        break;
                }
            }
            mainWinBrowser->SendProcessMessage(PID_RENDERER, process_message);
            break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 15
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
		  browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else if (message == uFindMsg) {
    // Find event.
    LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;

    if (lpfr->Flags & FR_DIALOGTERM) {
      // The find dialog box has been dismissed so invalidate the handle and
      // reset the search results.
      hFindDlg = NULL;
      if (g_handler.get()) {
        g_handler->GetBrowser()->StopFinding(true);
        szLastFindWhat[0] = 0;
        findNext = false;
      }
      return 0;
    }

    if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get())  {
      // Search for the requested string.
      bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
      if (matchCase != lastMatchCase ||
          (matchCase && wcsncmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
          (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) {
        // The search string has changed, so reset the search results.
        if (szLastFindWhat[0] != 0) {
          g_handler->GetBrowser()->StopFinding(true);
          findNext = false;
        }
        lastMatchCase = matchCase;
		wcscpy(szLastFindWhat, szFindWhat);
        //wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR), szFindWhat);
      }

      g_handler->GetBrowser()->Find(0, lpfr->lpstrFindWhat,
          (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
      if (!findNext)
        findNext = true;
    }

    return 0;
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowser::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          g_handler->GetStartupURL(), settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
	    /*
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
		*/
        return 0;
      case ID_FIND:
        if (!hFindDlg) {
          // Create the find dialog.
          ZeroMemory(&fr, sizeof(fr));
          fr.lStructSize = sizeof(fr);
          fr.hwndOwner = hWnd;
          fr.lpstrFindWhat = szFindWhat;
          fr.wFindWhatLen = sizeof(szFindWhat);
          fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;

          hFindDlg = FindText(&fr);
        } else {
          // Give focus to the existing find dialog.
          ::SetFocus(hFindDlg);
        }
        return 0;
      case ID_PRINT:
        if (browser.get())
          browser->GetMainFrame()->Print();
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_BINDING:  // Test the V8 binding handler
        if (browser.get())
          RunBindingTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_EXTENSION:  // Test the V8 extension handler
        if (browser.get())
          RunExtensionTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_PERFORMANCE:  // Test the V8 performance
        if (browser.get())
          RunExtensionPerfTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_EXECUTE:  // Test execution of javascript
        if (browser.get())
          RunJavaScriptExecuteTest(browser);
        return 0;
      case ID_TESTS_JAVASCRIPT_INVOKE:
        if (browser.get())
          RunJavaScriptInvokeTest(browser);
        return 0;
      case ID_TESTS_PLUGIN:  // Test the custom plugin
        //if (browser.get())
        //  RunPluginTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_TRANSPARENT_POPUP:  // Test a transparent popup window
        if (browser.get())
          RunTransparentPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_SCHEME_HANDLER:  // Test the scheme handler
        if (browser.get())
          RunSchemeTest(browser);
        return 0;
      case ID_TESTS_UIAPP:  // Test the UI app
        //if (browser.get())
        //  RunUIPluginTest(browser);
        return 0;
      case ID_TESTS_OSRAPP:  // Test the OSR app
        //if (browser.get())
        //RunOSRPluginTest(browser, false);
        return 0;
      case ID_TESTS_TRANSPARENT_OSRAPP:  // Test the OSR app with transparency
        //if (browser.get())
        //  RunOSRPluginTest(browser, true);
        return 0;
      case ID_TESTS_DOMACCESS:  // Test DOM access
        if (browser.get())
          RunDOMAccessTest(browser);
        return 0;
      case ID_TESTS_LOCALSTORAGE:  // Test localStorage
        if (browser.get())
          RunLocalStorageTest(browser);
        return 0;
      case ID_TESTS_ACCELERATED2DCANVAS:  // Test accelerated 2d canvas
        if (browser.get())
          RunAccelerated2DCanvasTest(browser);
        return 0;
      case ID_TESTS_ACCELERATEDLAYERS:  // Test accelerated layers
        if (browser.get())
          RunAcceleratedLayersTest(browser);
        return 0;
      case ID_TESTS_WEBGL:  // Test WebGL
        if (browser.get())
          RunWebGLTest(browser);
        return 0;
      case ID_TESTS_DRAGDROP:  // Test drag & drop
        if (browser.get())
          RunDragDropTest(browser);
        return 0;
      case ID_TESTS_GEOLOCATION:  // Test geolocation
        if (browser.get())
          RunGeolocationTest(browser);
        return 0;
      case ID_TESTS_XMLHTTPREQUEST:  // Test XMLHttpRequest
        if (browser.get())
          RunXMLHTTPRequestTest(browser);
        return 0;
      case ID_TESTS_WEBURLREQUEST:
        if (browser.get())
          RunWebURLRequestTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->SetZoomLevel(0.0);
        return 0;
      case ID_TESTS_DEVTOOLS_SHOW:
        if (browser.get())
          browser->ShowDevTools();
        return 0;
      case ID_TESTS_DEVTOOLS_CLOSE:
        if (browser.get())
          browser->CloseDevTools();
        return 0;
      case ID_TESTS_MODALDIALOG:
        if (browser.get())
          RunModalDialogTest(browser);
        return 0;
      case ID_TESTS_GETIMAGE:
        if (browser.get())
          RunGetImageTest(browser);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Pass focus to the browser window
        PostMessage(g_handler->GetBrowserHwnd(), WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Resize the browser window and address bar to match the new frame
        // window size
        RECT rect;
        GetClientRect(hWnd, &rect);
        rect.top += URLBAR_HEIGHT;

        int urloffset = rect.left + BUTTON_WIDTH * 4;

        HDWP hdwp = BeginDeferWindowPos(1);
        hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
          0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
        hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL,
          rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
          SWP_NOZORDER);
        EndDeferWindowPos(hdwp);
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowserHwnd()) {
        // Dont erase the background if the browser window has been loaded
        // (this avoids flashing)
        return 0;
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Let the browser window know we are about to destroy it.
          browser->ParentWindowWillClose();
        }
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 16
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  // static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL, stopWnd = NULL, editWnd = NULL;
  // static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

    
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info, g_handler.get(),
          g_handler->GetStartupURL(), settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        DestroyWindow(hWnd);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;

      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          ModifyZoom(browser, 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          ModifyZoom(browser, -0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->GetHost()->SetZoomLevel(0.0);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);

          HDWP hdwp = BeginDeferWindowPos(1);
          
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Let the browser window know we are about to destroy it.
          browser->GetHost()->ParentWindowWillClose();
        }
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 17
0
void Application::createBrowser()
{
    std::string startup_document = _config->startDocument();

    // test if absolute url with http or https
    if(Helper::StringUtils::starts_with(startup_document, "http://") || Helper::StringUtils::starts_with(startup_document, "https://"))
    {
        _startupUrl = startup_document;
    }
    else
    {
        Helper::Path www_dir = _pathManager->getApplicationDir() + "www";
        std::string www_dir_str = www_dir.filePath();
        if(!Helper::StringUtils::starts_with(www_dir_str, "/"))
            www_dir_str = "/" + www_dir_str;
        _startupUrl = "file://" + www_dir_str + "/" + startup_document;
    }




    CefWindowInfo info;
    bool transparent = true;

    //bool offscreenrendering = false;
    //config()->getBoolPreference("OffScreenRendering", offscreenrendering);

    /*
    if(offscreenrendering)
    {
      CefRefPtr<Client::RenderHandler> osr_window = createOSRWindow(_mainWindow, _client.get(), transparent);
      _client->setOSRHandler(osr_window);
      // old
      //info.SetTransparentPainting(transparent ? true : false);
      //info.SetAsOffScreen(osr_window->handle());
      info.SetAsWindowless(osr_window->handle(), transparent);
    }
    else*/
    {
        RECT rect;
        GetClientRect(_mainWindow, &rect);
        info.SetAsChild(_mainWindow, rect);
    }

    /*
    RECT r;
    r.left = 0; r.top = 0; r.right = 700; r.bottom = 500;
    info.SetAsChild(_mainWindow, r);
    */

    //TODO: move the settings into config.xml
    CefBrowserSettings browserSettings;

    //browserSettings.developer_tools = STATE_ENABLED;
    browserSettings.file_access_from_file_urls = STATE_ENABLED;
    browserSettings.universal_access_from_file_urls = STATE_ENABLED;
    browserSettings.web_security = STATE_DISABLED;
    browserSettings.application_cache = STATE_ENABLED;
    browserSettings.local_storage = STATE_ENABLED;
    //browserSettings.accelerated_compositing = STATE_ENABLED; ??

    // init plugin manager (also create the plugins with onload=true)
    _pluginManager->init();

    // Create the browser asynchronously and load the startup url
    HL_DEBUG(logger, "create browser with startup url: '" + _startupUrl + "'");
    CefBrowserHost::CreateBrowser(info, _client.get(), _startupUrl, browserSettings, NULL);
}
Esempio n. 18
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }

    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else if (message == uFindMsg) {
    // Find event.
    LPFINDREPLACE lpfr = (LPFINDREPLACE)lParam;

    if (lpfr->Flags & FR_DIALOGTERM) {
      // The find dialog box has been dismissed so invalidate the handle and
      // reset the search results.
      hFindDlg = NULL;
      if (g_handler.get()) {
        g_handler->GetBrowser()->GetHost()->StopFinding(true);
        szLastFindWhat[0] = 0;
        findNext = false;
      }
      return 0;
    }

    if ((lpfr->Flags & FR_FINDNEXT) && g_handler.get())  {
      // Search for the requested string.
      bool matchCase = (lpfr->Flags & FR_MATCHCASE?true:false);
      if (matchCase != lastMatchCase ||
          (matchCase && wcsncmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0) ||
          (!matchCase && _wcsnicmp(szFindWhat, szLastFindWhat,
              sizeof(szLastFindWhat)/sizeof(WCHAR)) != 0)) {
        // The search string has changed, so reset the search results.
        if (szLastFindWhat[0] != 0) {
          g_handler->GetBrowser()->GetHost()->StopFinding(true);
          findNext = false;
        }
        lastMatchCase = matchCase;
        wcscpy_s(szLastFindWhat, sizeof(szLastFindWhat)/sizeof(WCHAR),
            szFindWhat);
      }

      g_handler->GetBrowser()->GetHost()->Find(0, lpfr->lpstrFindWhat,
          (lpfr->Flags & FR_DOWN)?true:false, matchCase, findNext);
      if (!findNext)
        findNext = true;
    }

    return 0;
  } else {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;

      CefWindowInfo info;
      CefBrowserSettings settings;

      if (AppIsOffScreenRenderingEnabled()) {
        CefRefPtr<CefCommandLine> cmd_line = AppGetCommandLine();
        bool transparent =
            cmd_line->HasSwitch(cefclient::kTransparentPaintingEnabled);

        CefRefPtr<OSRWindow> osr_window =
            OSRWindow::Create(&g_main_browser_provider, transparent);
        osr_window->CreateWidget(hWnd, rect, hInst, szOSRWindowClass);
        info.SetAsOffScreen(osr_window->hwnd());
        info.SetTransparentPainting(transparent ? TRUE : FALSE);
        g_handler->SetOSRHandler(osr_window.get());
      } else {
        // Initialize window info to the defaults for a child window.
        info.SetAsChild(hWnd, rect);
      }

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info, g_handler.get(),
          g_handler->GetStartupURL(), settings, NULL);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        return 0;
      case IDM_EXIT:
        if (g_handler.get())
          g_handler->CloseAllBrowsers(false);
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_FIND:
        if (!hFindDlg) {
          // Create the find dialog.
          ZeroMemory(&fr, sizeof(fr));
          fr.lStructSize = sizeof(fr);
          fr.hwndOwner = hWnd;
          fr.lpstrFindWhat = szFindWhat;
          fr.wFindWhatLen = sizeof(szFindWhat);
          fr.Flags = FR_HIDEWHOLEWORD | FR_DOWN;

          hFindDlg = FindText(&fr);
        } else {
          // Give focus to the existing find dialog.
          ::SetFocus(hFindDlg);
        }
        return 0;
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
      case ID_TESTS_GETSOURCE:  // Test the GetSource function
        if (browser.get())
          RunGetSourceTest(browser);
        return 0;
      case ID_TESTS_GETTEXT:  // Test the GetText function
        if (browser.get())
          RunGetTextTest(browser);
        return 0;
      case ID_TESTS_POPUP:  // Test a popup window
        if (browser.get())
          RunPopupTest(browser);
        return 0;
      case ID_TESTS_REQUEST:  // Test a request
        if (browser.get())
          RunRequestTest(browser);
        return 0;
      case ID_TESTS_PLUGIN_INFO:  // Test plugin info
        if (browser.get())
          RunPluginInfoTest(browser);
        return 0;
      case ID_TESTS_ZOOM_IN:
        if (browser.get())
          ModifyZoom(browser, 0.5);
        return 0;
      case ID_TESTS_ZOOM_OUT:
        if (browser.get())
          ModifyZoom(browser, -0.5);
        return 0;
      case ID_TESTS_ZOOM_RESET:
        if (browser.get())
          browser->GetHost()->SetZoomLevel(0.0);
        return 0;
      case ID_TESTS_TRACING_BEGIN:
        g_handler->BeginTracing();
        return 0;
      case ID_TESTS_TRACING_END:
        g_handler->EndTracing();
        return 0;
      case ID_TESTS_PRINT:
        if(browser.get())
          browser->GetHost()->Print();
        return 0;
      case ID_TESTS_OTHER_TESTS:
        if (browser.get())
          RunOtherTests(browser);
        return 0;
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        if (AppIsOffScreenRenderingEnabled()) {
          // Give focus to the OSR window.
          CefRefPtr<OSRWindow> osr_window =
              static_cast<OSRWindow*>(g_handler->GetOSRHandler().get());
          if (osr_window)
            ::SetFocus(osr_window->hwnd());
        } else {
          // Give focus to the browser.
          g_handler->GetBrowser()->GetHost()->SetFocus(true);
        }
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;

          HDWP hdwp = BeginDeferWindowPos(1);
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_ENTERMENULOOP:
      if (!wParam) {
        // Entering the menu loop for the application menu.
        CefSetOSModalLoop(true);
      }
      break;

    case WM_EXITMENULOOP:
      if (!wParam) {
        // Exiting the menu loop for the application menu.
        CefSetOSModalLoop(false);
      }
      break;

    case WM_CLOSE:
      if (g_handler.get() && !g_handler->IsClosing()) {
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        if (browser.get()) {
          // Notify the browser window that we would like to close it. This
          // will result in a call to ClientHandler::DoClose() if the
          // JavaScript 'onbeforeunload' event handler allows it.
          browser->GetHost()->CloseBrowser(false);

          // Cancel the close.
          return 0;
        }
      }

      // Allow the close.
      break;

    case WM_DESTROY:
      // Quitting CEF is handled in ClientHandler::OnBeforeClose().
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Esempio n. 19
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

    // callback for the main window
    switch (message)
    {
    case WM_CREATE:
    {
        // create the single static handler class instance
        g_handler = new ClientHandler();
        g_handler->SetMainHwnd(hWnd);

        // create the child windows used for navigation
        RECT rect;
        GetClientRect(hWnd, &rect);

        CefWindowInfo info;
        CefBrowserSettings settings;
        settings.web_security = STATE_DISABLED;

        // initialize window info to the defaults for a child window.
        info.SetAsChild(hWnd, rect);

        // create the new child browser window
        CefBrowserHost::CreateBrowser(info, g_handler.get(), g_handler->GetStartupURL(), settings, NULL);

        // Todo: find a better solution for applying this e.g. with timeout in case showing of windows initially fails
        //ShowWindow(hWnd, SW_SHOWDEFAULT);
        //UpdateWindow(hWnd);
        SetTimer(hWnd, TIMER_SHOW_WINDW, 5000, NULL);

        return 0;
    }

    case WM_TIMER:
        if (wParam == TIMER_SHOW_WINDW)
        {
            HWND hWndMain = g_handler->GetMainHwnd();
            if (!IsWindowVisible(hWndMain))
            {
                ShowWindow(hWndMain, g_nCmdShow);
                UpdateWindow(hWndMain);
            }
            KillTimer(hWndMain, TIMER_SHOW_WINDW);
            return 0;
        }
        return 1;

    case WM_COMMAND:
    {
        CefRefPtr<CefBrowser> browser;
        if (g_handler.get())
            browser = g_handler->GetBrowser();

        int wmId = LOWORD(wParam);
        int wmEvent = HIWORD(wParam);

        // parse the menu selections
        if (g_mapMenuCommands.find(wmId) != g_mapMenuCommands.end())
        {
            String commandId = g_mapMenuCommands[wmId];
            if (g_handler.get())
            {
                CefRefPtr<CefListValue> args = CefListValue::Create();
                args->SetString(0, commandId);
                g_handler->GetClientExtensionHandler()->InvokeCallbacks(TEXT("onMenuCommand"), args);
            }

            return 0;
        }
        else
        {
            // handle other menu commands
            switch (wmId)
            {
            case IDM_EXIT:
                if (g_handler.get())
                    g_handler->CloseAllBrowsers(false);
                return 0;
            }
        }

        break;
    }

    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        return 0;

    case WM_SETFOCUS:
        if (g_handler.get() && g_handler->GetBrowser())
        {
            // pass focus to the browser window
            CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
            if (hwnd)
                PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
        }
        return 0;

    case WM_SIZE:
        // minimizing resizes the window to 0x0 which causes our layout to go all
        // screwy, so we just ignore it.
        if (wParam != SIZE_MINIMIZED && g_handler.get() && g_handler->GetBrowser())
        {
            CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
            if (hwnd)
            {
                // resize the browser window and address bar to match the new frame window size
                RECT rect;
                GetClientRect(hWnd, &rect);

                HDWP hdwp = BeginDeferWindowPos(1);
                hdwp = DeferWindowPos(hdwp, hwnd, NULL,
                                      rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER);
                EndDeferWindowPos(hdwp);
            }
        }
        break;

    case WM_ERASEBKGND:
        if (g_handler.get() && g_handler->GetBrowser())
        {
            CefWindowHandle hwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
            if (hwnd)
            {
                // don't erase the background if the browser window has been loaded (this avoids flashing)
                return 1;
            }
        }
        break;

    case WM_ENTERMENULOOP:
        if (!wParam)
        {
            // entering the menu loop for the application menu
            CefSetOSModalLoop(true);
        }
        break;

    case WM_EXITMENULOOP:
        if (!wParam)
        {
            // Exiting the menu loop for the application menu.
            CefSetOSModalLoop(false);
        }
        break;

    case WM_CLOSE:
        if (g_handler.get() && !g_handler->IsClosing())
        {
            WINDOWPLACEMENT wpl;
            wpl.length = sizeof(WINDOWPLACEMENT);
            GetWindowPlacement(App::GetMainHwnd(), &wpl);
            Rect r;
            r.x = wpl.rcNormalPosition.left;
            r.y = wpl.rcNormalPosition.top;
            r.w = wpl.rcNormalPosition.right - wpl.rcNormalPosition.left;
            r.h = wpl.rcNormalPosition.bottom - wpl.rcNormalPosition.top;
            SaveWindowPlacement(&r, wpl.showCmd);

            g_handler->GetClientExtensionHandler()->InvokeCallbacks(TEXT("onAppTerminating"), CefListValue::Create());

            CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
            if (browser.get())
            {
                // Notify the browser window that we would like to close it. This
                // will result in a call to ClientHandler::DoClose() if the
                // JavaScript 'onbeforeunload' event handler allows it.
                browser->GetHost()->CloseBrowser(false);

                // cancel the close
                return 0;
            }
        }

        // allow the close
        break;

    case WM_DESTROY:
        // quitting CEF is handled in ClientHandler::OnBeforeClose().
        return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 20
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    PAINTSTRUCT ps;
    HDC hdc;
    switch (message) {
    case WM_CREATE: {
        g_handler = new ClientHandler();
        RECT rect;
        GetClientRect(hWnd, &rect);
        CefBrowserSettings settings;
        settings.plugins_disabled = false;
        settings.file_access_from_file_urls_allowed = true;
        settings.universal_access_from_file_urls_allowed = true;
        CefWindowInfo info;
        info.SetAsChild(hWnd, rect);
        WCHAR full_path[MAX_PATH];
        get_abs_path_exe(L"web\\search.htm",full_path);
        if(_waccess(full_path,0)==0) {
            CefBrowser::CreateBrowser(info,
                                      static_cast<CefRefPtr<CefClient>>(g_handler), full_path,settings);
        } else if(_waccess(L"E:\\Documents\\gigaso\\browser\\web\\search2.htm",0)==0) {
            CefBrowser::CreateBrowser(info,
                                      static_cast<CefRefPtr<CefClient>>(g_handler), L"E:\\Documents\\gigaso\\browser\\web\\search2.htm",settings);
        } else {
            CefBrowser::CreateBrowser(info,
                                      static_cast<CefRefPtr<CefClient>>(g_handler), L"about:blank",settings);
        }
    }
    return 0;
    case WM_ACTIVATE:
        if((short)wParam!=WA_INACTIVE) {
            //SetForegroundWindow(hWnd);
            trans_focus();
        }
        return 0;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        return 0;
    case WM_SETFOCUS:
        trans_focus();
        return 0;
    case WM_SIZE:
        if(g_handler.get() && g_handler->GetBrowserHwnd()) {
            RECT rect;
            GetClientRect(hWnd, &rect);
            HDWP hdwp = BeginDeferWindowPos(1);
            hdwp = DeferWindowPos(hdwp, g_handler->GetBrowserHwnd(), NULL,
                                  rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
                                  SWP_NOZORDER);
            EndDeferWindowPos(hdwp);
        }
        break;
    case WM_ERASEBKGND:
        if(g_handler.get() && g_handler->GetBrowserHwnd()) {
            // Dont erase the background if the browser window has been loaded
            // (this avoids flashing)
            return 0;
        }
        break;
    case WM_CLOSE:
        // All clients must forward the WM_CLOSE call to all contained browser
        // windows to give those windows a chance to cleanup before the window
        // closes. Don't forward this message if you are cancelling the request.
        if(g_handler.get())
        {
            HWND hWnd = g_handler->GetBrowserHwnd();
            if (hWnd)
                ::SendMessage(hWnd, WM_CLOSE, 0, 0);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}
Esempio n. 21
0
LRESULT CALLBACK TransparentWnd::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static CefRefPtr<CefBrowser> browser = NULL;
	static HWND browserhWnd=NULL;
	static RECT rect;
	static TransparentWnd* handler;
	static int top=GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYCAPTION)-2,left=GetSystemMetrics(SM_CXFRAME);
	switch (message)
	{
	case WM_INIT:
		{
			// Create the single static handler class instance
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			CefRefPtr<MyHandler> g_handler=handler->g_handler;
			g_handler->SetMainHwnd(hWnd);


			GetClientRect(hWnd, &rect);

			CefWindowInfo info;
			CefBrowserSettings settings;

			// Populate the settings based on command line arguments.
			AppGetBrowserSettings(settings);
			// Initialize window info to the defaults for a child window
			info.SetAsChild(hWnd, rect);

			if(handler->isTransparent){
				info.m_bWindowRenderingDisabled = TRUE;
				info.SetTransparentPainting(TRUE);
			}

			// Creat the new child browser window
			CefBrowser::CreateBrowserSync(info,
				static_cast<CefRefPtr<CefClient> >(g_handler),
				handler->GetUrl(), settings);
			DragAcceptFiles(hWnd,TRUE);
		}
		break;
	case WM_NOTIFYICON:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			handler->TaskMouseHandler(lParam);
		}
		break;
	case WM_ACTIVATE:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			handler->FocusHandler();
		}
		break;
	case WM_CLOSE:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			if(handler->g_handler->win){
				handler->CloseHandler();
				return 0;
			};
		}
		break;
	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			if(handler->isEnableDrag){
				SetCapture(hWnd);
				handler->dragX=LOWORD(lParam);
				handler->dragY=HIWORD(lParam);
				handler->isDrag=true;
			}
		}
		break;

	case WM_LBUTTONUP:
	case WM_RBUTTONUP:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			if (GetCapture() == hWnd)
				ReleaseCapture();
			handler->isDrag=false;
		}
		break;

	case WM_MOUSEMOVE:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			if(handler->isDrag){
				POINT pt;
				GetCursorPos(&pt);
				handler->Move(pt.x-handler->dragX, pt.y-handler->dragY);
				handler->MoveHandler(handler->x,handler->y);
			}
		}
		break;

	case WM_SIZE:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			switch(wParam){
			case SIZE_MINIMIZED:
				ShowWindow(handler->hWnd, SW_MINIMIZE);
				break;
			case SIZE_RESTORED:
				break;
			default:
				handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
				GetWindowRect(hWnd, &rect);
				int m_x = rect.left;
				int m_y = rect.top;
				int m_nWidth = rect.right - rect.left;
				int m_nHeight = rect.bottom - rect.top;
				if(rect.right-rect.left>0){
					handler->SetSize(m_nWidth,m_nHeight);
				}
			}
			if(!handler->isTransparent){
				RECT  rect;
				GetClientRect(hWnd, &rect);
				MoveWindow(handler->g_handler->GetBrowserHwnd(), rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, false);
			}
		}
		break;
	case WM_SIZING:
		{
			handler=(TransparentWnd*)GetWindowLong(hWnd, GWL_USERDATA);
			LPRECT lpRect=(LPRECT)lParam;
			int m_nWidth = lpRect->right-lpRect->left;
			int m_nHeight = lpRect->bottom-lpRect->top;
			handler->Move(lpRect->left,lpRect->top);
			handler->SetSize(m_nWidth,m_nHeight);
		}
		break;
	default:
		break;
	}	

	return DefWindowProc(hWnd, message, wParam, lParam);
}