Create a simple MFC Dialog based application

Built a cool app using CEF that you'd like to share with the community? Talk about it here.

Create a simple MFC Dialog based application

Postby Dublanc » Thu Mar 29, 2012 4:30 am

I had a look at the previous post "Embedding Chromium in MFC application" (http://magpcss.org/ceforum/viewtopic.php?f=6&t=50) about this problem, but the code changed. CefInitialize for example does no longer have 2 parameters - Does anyone have just a code to create a browser in an mfc app ? Even something easy would be perfect.

Thanks
Dublanc
Mentor
 
Posts: 53
Joined: Thu Mar 29, 2012 4:22 am

Re: Create a simple MFC Dialog based application

Postby Dublanc » Mon Apr 02, 2012 8:55 am

For those who are interested by the answer :

Example for a simple MFC Dialog based

in the MainDLG.cpp file

Code: Select all
class myClientHandler : public CefClient
{
  public:
    myClientHandler()  {}
    ~myClientHandler() {}

  protected:
    IMPLEMENT_REFCOUNTING(ClientHandler);
};


Code: Select all
// Global var
CefRefPtr<myClientHandler> g_handler;


In the the method OnInitDialog : (m_chrome_frame can be a frame or "this" if you want a full dialog browser)
Code: Select all
  HWND hWnd;
  RECT rect;
 
  // Init First Chrome
  CefBrowserSettings browserSettings;
  CefWindowInfo info;

  g_handler = new myClientHandler();
  hWnd = m_chrome_frame.GetSafeHwnd();

  m_chrome_frame.GetClientRect(&rect);
  info.SetAsChild(hWnd,rect);

  CefBrowser::CreateBrowser(info,static_cast< CefRefPtr<CefClient> >(g_handler),"http://www.google.com", browserSettings);


Don't forget to init/quit correctly the api - add in the constructor :
Code: Select all
CYOurWonderfullProject::CYOurWonderfullProject(CWnd* pParent /*=NULL*/) : CDialogEx(CYOurWonderfullProject::IDD, pParent)
{
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

  CefSettings settings;
  settings.multi_threaded_message_loop = true;
  CefInitialize(settings);
}

and in OnDestroy() - (Class Wizard on the main dialog => Messages and Add WM_DESTROY)
Code: Select all
void CYOurWonderfullProject::OnDestroy()
{
  CefShutdown();
  CDialogEx::OnDestroy();
}


I hope this will help...

Now i have a big question - How can i get after this a method/function to have a handle on the browser, like ClientHandler::GetBrowser() in the official example

Thanks
Dublanc
Mentor
 
Posts: 53
Joined: Thu Mar 29, 2012 4:22 am

Re: Create a simple MFC Dialog based application

Postby magreenblatt » Mon Apr 02, 2012 9:11 am

Dublanc wrote:Now i have a big question - How can i get after this a method/function to have a handle on the browser, like ClientHandler::GetBrowser() in the official example

Implement the CefLifeSpanHandler::OnAfterCreated callback. Keep a reference to the browser passed to that method (make sure to release the reference in OnBeforeClose).
magreenblatt
Site Admin
 
Posts: 12379
Joined: Fri May 29, 2009 6:57 pm

Re: Create a simple MFC Dialog based application

Postby Dublanc » Tue Apr 03, 2012 3:47 am

So easy...

Thanks ! It works immediatly, just need to implement GetLifeSpanHandler from CefClient Method and everything was fine.

Keep up the good work !
Dublanc
Mentor
 
Posts: 53
Joined: Thu Mar 29, 2012 4:22 am

Re: Create a simple MFC Dialog based application

Postby hikaruxx » Fri Apr 06, 2012 8:36 am

how to fix this???
libcef.dll!100949b6()
[The following framework may be incorrect and / or missing , no symbols are loaded for libcef.dll]
libcef.dll!100819a3()
libcef.dll!10095081()
libcef.dll!100817af()
libcef.dll!101117c9()
libcef.dll!1002db68()
> CefDemo.exe!CefBrowserHost::CreateBrowser(const CefWindowInfo & windowInfo={...}, CefRefPtr<CefClient> client={...}, const CefStringBase<CefStringTraitsUTF16> & url={...}, const CefStructBase<CefBrowserSettingsTraits> & settings={...}) row36 + 0x5e byte C++
user32.dll!77d18734()
user32.dll!77d18816()
user32.dll!77d2a013()
user32.dll!77d2a039()
CefDemo.exe!CWnd::DefWindowProcW(unsigned int nMsg=5737136, unsigned int wParam=5726126, long lParam=5727412) row1029 + 0x20 byte C++
CefDemo.exe!CWnd::OnWndMsg(unsigned int message=5726126, unsigned int wParam=5727412, long lParam=2010220340, long * pResult=0x77d18816) row2004 + 0x11 byte C++
CefDemo.exe!CWnd::WindowProc(unsigned int message=2010220566, unsigned int wParam=2010288763, long lParam=2010277146) row1741 + 0x20 byte C++
user32.dll!77d18734()
user32.dll!77d18816()
user32.dll!77d2927b()
user32.dll!77d2651a()
user32.dll!77d2683e()
user32.dll!77d3f03a()
CefDemo.exe!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x00517d2d, CWnd * pParentWnd=0x006f9992, HINSTANCE__ * hInst=0x006f9888) row315 + 0x2a byte C++
CefDemo.exe!CDialog::DoModal() row579 + 0x20 byte C++
CefDemo.exe!CCefDemoApp::InitInstance() row63 + 0xb byte C++
CefDemo.exe!AfxWinMain(HINSTANCE__ * hInstance=0x0012f328, HINSTANCE__ * hPrevInstance=0xcccccccc, wchar_t * lpCmdLine=0x00000000, int nCmdShow=-858993460) row37 + 0xd byte C++
libcef.dll!101117c9()
libcef.dll!1002db68()
CefDemo.exe!CefBrowserHost::CreateBrowser(const CefWindowInfo & windowInfo={...}, CefRefPtr<CefClient> client={...}, const CefStringBase<CefStringTraitsUTF16> & url={...}, const CefStructBase<CefBrowserSettingsTraits> & settings={...}) row36 + 0x5e byte C++
CefDemo.exe!CCefDemoDlg::OnInitDialog() row136 + 0x4d byte C++
CefDemo.exe!AfxDlgProc(HWND__ * hWnd=0x001a0f5c, unsigned int message=272, unsigned int __formal=986902, unsigned int __formal=986902) row28 + 0x10 byte C++
user32.dll!77d18734()
user32.dll!77d23ce4()
user32.dll!77d23b30()
user32.dll!77d23d5c()
user32.dll!77d18734()
user32.dll!77d18816()
ntdll.dll!7c931db7()
user32.dll!77d2a013()
user32.dll!77d2a039()
CefDemo.exe!CWnd::DefWindowProcW(unsigned int nMsg=272, unsigned int wParam=986902, long lParam=0) row1029 + 0x20 byte C++
CefDemo.exe!CWnd::Default() row274 C++
CefDemo.exe!CDialog::HandleInitDialog(unsigned int __formal=986902, unsigned int __formal=986902) row676 + 0x8 byte C++
CefDemo.exe!CWnd::OnWndMsg(unsigned int message=272, unsigned int wParam=986902, long lParam=0, long * pResult=0x0012f97c) row2004 + 0x11 byte C++
CefDemo.exe!CWnd::WindowProc(unsigned int message=272, unsigned int wParam=986902, long lParam=0) row1741 + 0x20 byte C++
CefDemo.exe!AfxCallWndProc(CWnd * pWnd=0x0012fe18, HWND__ * hWnd=0x001a0f5c, unsigned int nMsg=272, unsigned int wParam=986902, long lParam=0) row240 + 0x1c byte C++
CefDemo.exe!AfxWndProc(HWND__ * hWnd=0x001a0f5c, unsigned int nMsg=272, unsigned int wParam=986902, long lParam=0) row389 C++
user32.dll!77d18734()
user32.dll!77d18816()
user32.dll!77d2927b()
user32.dll!77d2651a()
user32.dll!77d2683e()
user32.dll!77d3f03a()
CefDemo.exe!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x008225c8, CWnd * pParentWnd=0x00000000, HINSTANCE__ * hInst=0x00400000) row315 + 0x2a byte C++
CefDemo.exe!CDialog::DoModal() row579 + 0x20 byte C++
CefDemo.exe!CCefDemoApp::InitInstance() row63 + 0xb byte C++
CefDemo.exe!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020b80, int nCmdShow=1) row37 + 0xd byte C++
CefDemo.exe!wWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00020b80, int nCmdShow=1) row33 C++
CefDemo.exe!__tmainCRTStartup() row324 + 0x35 byte C
CefDemo.exe!wWinMainCRTStartup() row196 C
kernel32.dll!7c817077()
CefDemo.exe!CToolTipCtrl::GetMargin(tagRECT * lprc=0x00660063) row262 + 0x44 byte C++
CefDemo.exe!CToolTipCtrl::GetMargin(tagRECT * lprc=0x002e0031) row262 + 0x44 byte C++
CefDemo.exe!CDataSourceControl::GetBoundClientRow() row2963 C++
hikaruxx
Techie
 
Posts: 11
Joined: Fri Mar 16, 2012 8:21 am


Return to Apps Discussion

Who is online

Users browsing this forum: No registered users and 3 guests