Cannot see icon

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.

Cannot see icon

Postby lkitrossky » Wed Jun 24, 2015 3:59 pm

Hi! We have an application based on CefApp in Windows. In MyApp.rc file mentioned two icon files in RES folder. We edited both (MyApp.ico and small.ico). We renamed file cefsimple,ico into MyApp.ico in the header and the file itself. Now the resulting executable in Windows Explorer is really seen with a new icon. BUT during the run of the application in the bar left corner there is no edited icon, just a white rectangle. What could possibly be wrong?
If a correction is unclear, can the icon be set via the line
Code: Select all
CefBrowserHost::CreateBrowser(window_info, handler.get(), url, browser_settings, NULL);

If there any way to send insert icon in one of parameters of this line?
Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Cannot see icon

Postby fasecero » Wed Jun 24, 2015 11:46 pm

If you have the window handle & the icon handle you can use WM_SETICON message.

Code: Select all
SendMessage(hWnd, WM_SETICON, ICON_BIG, hicon);
SendMessage(hWnd, WM_SETICON, ICON_SMALL, hicon);


WM_SETICON: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632643(v=vs.85).aspx
fasecero
Mentor
 
Posts: 60
Joined: Mon May 12, 2014 2:53 pm

Re: Cannot see icon

Postby lkitrossky » Sat Jun 27, 2015 3:03 pm

The problem is how to get hWnd? Out application has the main class as follows:
Code: Select all
class MyApp : public CefApp, public CefRenderProcessHandler, public CefBrowserProcessHandler
We tried to use CefRenderProcessHandler handlers, which returns a pointer to a browser like
Code: Select all
OnContextCreated(CefRefPtr<CefBrowser> browser..., OnBrowserCreated(CefRefPtr<CefBrowser> browser.., OnBeforeNavigation(CefRefPtr<CefBrowser> browser ...
but in all of them GetHost() returns NULL
Code: Select all
browser->GetHost(); //returns NULL
and there is no way to proceed with
Code: Select all
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();

The same happens if we try to get browser via CefRefPtr<CefFrame> frame, the browser is not null, but GetHost bings NULL.
So, we do not know how to get window handler. Mind, that in our MyApp we have no CefClient and cannot use its methods like
Code: Select all
GetDialogHandler, GetLifeSpanHandler

So, how to do it? Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Cannot see icon

Postby Czarek » Sun Jun 28, 2015 2:00 am

GetHost() can only be called in the browser process.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cannot see icon

Postby lkitrossky » Sun Jun 28, 2015 5:36 am

And how to change icon? I tried just to edit small.ico and also myproject.ico. And I tried to FindWindow + SendMessage, nothing chnages the small icon in the application main window.
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Cannot see icon

Postby fasecero » Sun Jun 28, 2015 7:15 pm

Code: Select all
HWND WINAPI FindWindow(
  _In_opt_ LPCTSTR lpClassName,
  _In_opt_ LPCTSTR lpWindowName
);


FindWindow should work if the window have no parent. I remember once I had problems with this function by using an empty string in lpClassName, it should work using the window class name. lpWindowName must be equal to the caption.
fasecero
Mentor
 
Posts: 60
Joined: Mon May 12, 2014 2:53 pm

Re: Cannot see icon

Postby lkitrossky » Mon Jun 29, 2015 10:52 am

I did the following. In the handler
Code: Select all
MyApp:: OnContextCreated...
added
Code: Select all
HWND hwnd = ::FindWindow(NULL, L"caption text");
It worked. Then
Code: Select all
 LRESULT res = SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
It worked also but only with parameter no-sandbox and icon from a file. That is:
Code: Select all
hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_SMALL), IMAGE_ICON, 32, 32, 0);//no error, but loading of this icon fail
hIcon = (HICON)LoadImage(NULL, L"small.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);//no error, but loading of this icon works only with : --no-sandbox

I do not understand, why the first way fails, while the second is good but demands no-sandbox, must access files.
Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Cannot see icon

Postby fasecero » Mon Jun 29, 2015 12:42 pm

Try using the module handle for the first one

Code: Select all
hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_SMALL), IMAGE_ICON, 32, 32, 0);

Also, the small caption icon needs ICON_SMALL flag

Code: Select all
LRESULT res = SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);

Good luck!
fasecero
Mentor
 
Posts: 60
Joined: Mon May 12, 2014 2:53 pm

Re: Cannot see icon

Postby lkitrossky » Mon Jun 29, 2015 4:37 pm

As before, works only with command line parameter --no-sandbox:( Any additional ideas, please? We are almost there! Just a reminder, our main class MyApp inherits the following three classes: CefApp, CefRenderProcessHandler, CefBrowserProcessHandler, but not CefClient. Thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: Cannot see icon

Postby lkitrossky » Sun Jul 05, 2015 3:53 am

Hi! I found an easy solution for the problem. We had almost empty function
Code: Select all
CefRefPtr<CefBrowserProcessHandler> MyApp::GetBrowserProcessHandler() {return this;}
I put in it the code to reload icon:
Code: Select all
CefRefPtr<CefBrowserProcessHandler> MyApp::GetBrowserProcessHandler(){
   HWND hwnd = ::FindWindow(NULL, L"MyinitialCaptionBeforeBrowse");
    if(NULL != hwnd ){
      HICON hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_SMALL), IMAGE_ICON, 32, 32, 0);
                if(hIcon){
                LRESULT res = SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
               }
       }
      return this;
}
This way it works. The reason it did not work before was that previously it was in
Code: Select all
MyApp::OnContextCreated
with find command on caption L"MyCaptionAfterBrowse", it worked only without sandbox. Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 97 guests