Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

crAppStart Cursor always on screen

Post Reply
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: crAppStart Cursor always on screen

Post by salvadordf »

Hi,

Please read this :
https://www.briskbard.com/index.php?lang=en&pageid=cef

Use one of the demos as a base for your project. Then add your customized features to that demo.

Remember that the GlobalCEFApp creation and destruction must be in the DPR file and the call to GlobalCEFApp.StartMainProcess must be in a "if..then" clause.

If you still have problems, I would need to see your code to be able to identify the problem.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: crAppStart Cursor always on screen

Post by salvadordf »

Hi,

I must improve the information in https://www.briskbard.com/index.php?lang=en&pageid=cef
The usage of GlobalCefApp is not explained clearly enough and it's the cause of some confusion.

My apologies. :oops:

The CEF3 code structure is very complicated. It uses one main process and many other processes for rendering, plugins, etc. Let's call them "subprocesses".

To do all that you can do two things :
  • Use two exes : 1 for the main process and the other exe for the subprocesses.
  • Use one exe : Reuse 1 exe and add code in the DPR file that initializes the application normally for the main process or skips the app initialization to be one of the subprocesses. CEF will run the same exe multiple times to create all the subprocesses like Chrome and almost all the CEF4Delphi demos do.
CEF4Delphi tries to simplify all that with GlobalCEFApp. This is the simplest DPR code you can have :

Code: Select all

  GlobalCEFApp := TCefApplication.Create; // creation of GlobalCEFApp

  if GlobalCEFApp.StartMainProcess then // This function decides if this is the main process or a subprocess
    begin	                        
      Application.Initialize;  // Normal initialization of the application in case this is the main process
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end;

  GlobalCEFApp.Free; // Destruction of GlobalCEFApp. All processes and subprocesses must execute it.
GlobalCEFApp.StartMainProcess initializes CEF and decides if this is the main process. In that case, it returns TRUE and the Application.Initialize is executed.

In case GlobalCEFApp.StartMainProcess detects that this is just another subprocess it will be blocked inside the GlobalCEFApp.StartMainProcess function to do whatever it has to do (rendering, etc), then return FALSE to skip the Application.initialize.

Application.Initialize, Application.CreateForm and Application.Run must ONLY be executed if this is the main process.

In your code, the FindWindow function and the splash screen code should only be executed in case it's the main process, so you should move them inside the begin..end after GlobalCEFApp.StartMainProcess

Avoid all calls to Application.ProcessMessages unless you know that the rest of the code in your app will react correctly. In this case, I would delete it because it can create a lot of problems inside the browser.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: crAppStart Cursor always on screen

Post by salvadordf »

Hi,

Your DPR without the splash screen, loading screen, the FindWindow code and the Application.ProcessMessages calls would be like this :

Code: Select all

{$R *.RES}
BEGIN
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.Title := 'TurfBase Play';
  Application.HelpFile := '';
  Application.CreateForm(TDM, DM);
  Application.CreateForm(TDM1, DM1);
  Application.CreateForm(TDM2, DM2);
  Application.CreateForm(TDM4, DM4);
  Application.CreateForm(TForm_Principale, Form_Principale);
  Application.Run;
END.
To add a basic CEF4Delphi browser you would need a DPR like this :

Code: Select all

{$R *.RES}
BEGIN
  GlobalCEFApp := TCefApplication.Create;

  if GlobalCEFApp.StartMainProcess then
    begin
      //    
      // Add the FindWindow code here.    
      //    
      // If you need a splash screen and loading screen add them here.    
      //    
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.Title := 'TurfBase Play';
      Application.HelpFile := '';
      Application.CreateForm(TDM, DM);
      Application.CreateForm(TDM1, DM1);
      Application.CreateForm(TDM2, DM2);
      Application.CreateForm(TDM4, DM4);
      Application.CreateForm(TForm_Principale, Form_Principale);
      Application.Run;
    end;

  GlobalCEFApp.Free;
END.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: crAppStart Cursor always on screen

Post by salvadordf »

Hi,

I made some more tests and I can't reproduce your problem.

The only place where the cursor is modified is in the SimpleOSRBrowser demo because it's what you have to do in OSR mode.
The CEF4Delphi code and the rest of the demos don't modify the cursor.

I created a new application with an empty form (without a TChromium component). I only modified the DPR like this :

Code: Select all

program Project1;

uses
  Vcl.Forms,
  WinApi.Windows,
  uCEFApplication,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

{$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE}

begin
  GlobalCEFApp := TCefApplication.Create;

  GlobalCEFApp.FrameworkDirPath     := 'cef';
  GlobalCEFApp.ResourcesDirPath     := 'cef';
  GlobalCEFApp.LocalesDirPath       := 'cef\locales';
  GlobalCEFApp.cache                := 'cef\cache';
  GlobalCEFApp.cookies              := 'cef\cookies';
  GlobalCEFApp.UserDataPath         := 'cef\User Data';

  if GlobalCEFApp.StartMainProcess then
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end;

  GlobalCEFApp.Free;
end.
I copied the CEF3 binaries, built the project and run it. The cursor was crDefault when the form was shown on the screen.
The demos and BriskBard have the same result.

I can only suggest that you create a simple browser application and then add parts of your application to see when the cursor stays at crAppStart.
Post Reply