Prevent main application from closing

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Prevent main application from closing

Postby arvydas » Fri Mar 21, 2014 11:19 am

Hi,

I'm using CEF3 in an MFC based application with muti process support. Everything works great except that I don't want to close the main application window when I close the CEF hosted window, because I want to create/destroy embedded browser windows on demand. How can I prevent cef from closing my main application window when I close the last browser window? CEF windows are hosted on separate windows from main application window.

Regards,
Arvydas
arvydas
Newbie
 
Posts: 4
Joined: Fri Mar 21, 2014 11:05 am

Re: Prevent main application from closing

Postby magreenblatt » Fri Mar 21, 2014 12:12 pm

How are you closing the browser windows? Read the documentation on DoClose and check what your application is doing in OnBeforeClose.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Prevent main application from closing

Postby arvydas » Fri Mar 21, 2014 1:43 pm

magreenblatt wrote:How are you closing the browser windows? Read the documentation on DoClose and check what your application is doing in OnBeforeClose.


Found a way to do this myself. Had to run this command in order to close the window without affecting the main:

CefRefPtr<CefBrowser> browser = m_pChromeHandler->GetBrowser();
::DestroyWindow(browser->GetHost()->GetWindowHandle());
arvydas
Newbie
 
Posts: 4
Joined: Fri Mar 21, 2014 11:05 am

Re: Prevent main application from closing

Postby daka1 » Wed Mar 18, 2015 6:46 am

How do we do similar ::DestroyWindow on mac?
Usually we dont want to quit when the red close button is clicked.
We want to keep running windowless/with a hidden window
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: Prevent main application from closing

Postby magreenblatt » Wed Mar 18, 2015 11:22 am

daka1 wrote:How do we do similar ::DestroyWindow on mac?
Usually we dont want to quit when the red close button is clicked.
We want to keep running windowless/with a hidden window

Do you want to destroy the browser or just hide the window? Did your application create the parent NSWindow or did CEF?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Prevent main application from closing

Postby daka1 » Mon Mar 30, 2015 5:15 am

I want to hide away the window. As it usually happens on OSX apps.

I still have the default cefclient entry point code for spawning my application:

Code: Select all
// Create the main application window.
 NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
 NSRect window_rect = { {0, screen_rect.size.height - sizeWindow.height},
   {sizeWindow.width, sizeWindow.height} };
 NSWindow* mainWnd = [[UnderlayOpenGLHostingWindow alloc]
                      initWithContentRect:window_rect
                      styleMask:(NSTitledWindowMask |
                                 NSClosableWindowMask |
                                 NSMiniaturizableWindowMask |
                                 NSResizableWindowMask )
                      backing:NSBackingStoreBuffered
                      defer:NO];
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: Prevent main application from closing

Postby magreenblatt » Mon Mar 30, 2015 7:28 am

You can implement NSWindowDelegate windowShouldClose to change the behavior when the user attempts to close the window.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: ndesktop and 84 guests