CreateBrowser spawns a copy of my main window

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.

Re: CreateBrowser spawns a copy of my main window

Postby itsthetaste » Wed Jun 12, 2013 11:26 am

No problem, thanks for posting the code in the first place, its got me going in the right direction... I think.
itsthetaste
Techie
 
Posts: 35
Joined: Mon Jun 10, 2013 8:03 pm

Re: CreateBrowser spawns a copy of my main window

Postby punamg » Fri Dec 13, 2013 2:47 am

daktor says:

Another solution is to add code to the entry point of your application (eg WinMain) to handle when CEF is creating a sub-process. Searching the command line for "--type=" works but there may be better ways to detect that CEF should handle things. Once you know it's CEF, return CefExecuteProcess(...) and exit instead of proceeding into your application.

This fixes the problem without adding an additional executable to your project.


Hi daktor, I am facing this same spawning issue. I donot want to have another additional executable in my project.
Can you please explain what you wrote above. I quiet did not get it.
Also if you have any sample code where you have implemented it, kindly can you share it.

Thanking in advance.
punamg
Techie
 
Posts: 43
Joined: Thu Dec 05, 2013 6:00 am

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Fri Dec 13, 2013 10:29 am

Hi punamg,

The app I work with has:

Code: Select all
INT WINAPI WinMain( HINSTANCE hInInstance, HINSTANCE hPrevInstance, char*, INT nCmdShow )
{
...
}


In that function (or whatever your app's entry function is), you can parse the command line for "--type=". Using that information, if you determine that it is cef that is trying to launch a process, instead of continuing with your WinMain(..) function, immediately return CefExecuteProcess(..).

For example (pseudocode):
Code: Select all
INT WINAPI WinMain( HINSTANCE hInInstance, HINSTANCE hPrevInstance, char*, INT nCmdShow )
{
    if (GetCommandLine().HasStr("--type=="))
    {
        CefExecuteProcess(..);
    }
    else
    {
        // continue as usual
    }
}


Let me know if that is still confusing.
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby magreenblatt » Fri Dec 13, 2013 10:48 am

daktor wrote:In that function (or whatever your app's entry function is), you can parse the command line for "--type=". Using that information, if you determine that it is cef that is trying to launch a process, instead of continuing with your WinMain(..) function, immediately return CefExecuteProcess(..).

Note that CefExecuteProcess does this check internally. You can just look at the return code to determine whether to exit the application or continue.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser spawns a copy of my main window

Postby punamg » Mon Dec 16, 2013 1:37 am

Hi Daktor,

Thank you for the reply.

What I understand from your reply is that from your main application, only for browser you are calling CefExecuteProcess(..), for rest you arent.
My question is how will this stop the main application spawning issue.
I could see that unless from my main application I do something like this and set the browser_subprocess_path to a separate project executable, my main application spawns into 2
Code: Select all
    int exit_code = CefExecuteProcess(main_args, cefApplication.get());
    if (exit_code >= 0) {
        //The sub-process terminated, exit now.
   return exit_code;
    }
    const char *path= "C:/Project/Webkit/applicationTest/SubProcApp/SubProc/Debug/SubProc";
    CefString(&appSettings.browser_subprocess_path).FromASCII(path);


Please help as I donot want my main application to spawn into similar to what you faced earlier in the thread.
The approach above is solving it but this separate project executable I am not sure what to do with.
punamg
Techie
 
Posts: 43
Joined: Thu Dec 05, 2013 6:00 am

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Mon Dec 16, 2013 11:40 am

My question is how will this stop the main application spawning issue.


Based on the behavior of CefExecuteProcess() you do not continue into your main application code under certain circumstances. While you will see your main application process launch multiple times, only one instance should allow code execution to reach your actual application. All other instances of your application process are actually Cef processes.

Check here for more information on CefExecuteProcess().

If you want to use a separate executable to handle Cef processes, let me know and we can talk about that.
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby rupali1201 » Fri Jan 03, 2020 3:54 am

punamg, how you solved multiple instance of your application windows. I have dialog based application and I am calling CefExecuteProcess and CefInitialize in dialog constructor, which is launching one more dialog which I don't want. How to avoid spawning of multiple instance of a window?
rupali1201
Newbie
 
Posts: 5
Joined: Fri Dec 27, 2019 1:57 am

Previous

Return to Support Forum

Who is online

Users browsing this forum: Devyre and 85 guests