After Navigate2 Method returns S_OK Stuck at READYSTATE of READYSTATE_LOADING - mfc

I am working on a MFC Document View architecture application which has multiple documents and views and a tabbed window interface.
I have been tasked with making an automatic switch to another tab on the press of the OK button in one of the other tabs. When the other tab is clicked on it uses a C++ wrapper over IWebBrowser2 to navigate to a specific web page.
When this is done manually by clicking on the tab everything is fine and the webpage within the view loads successfully.
In my first attempt at doing this the tab successfully switched in response to a call to
AfxGetMainWnd()->SendMessageToDescendants(SOME_MESSAGE, ...);
however by sending this windows message at the wrong point the application would crash once control returned because the chain of events caused the (modeless) dialog (*) that
sent the message, to no longer exist.
I then found the correct place to make the call, but now when the other tab is activated, it no longer displays the webpage as it should.
To debug this problem I added code to check the READYSTATE in both the situation where it works and the situation where it does not. When the page fails to load (despite the call to Navigate2 returning S_OK), the READYSTATE just stays at READYSTATE_LOADING.
Unfortunately now I am to many edits away from when I had it partially working.
I have added TRACE statements to the most obvious events such as OnSetFocus, CView::OnActivateView but all traces come out in the same order despite the behaviour being different
* hosted in the view

Related

CEFsharp load url is holding on to the previously navigated url

We have a C++ application (using Owl UI framework) which calls a CEFsharp Chromiumbrowser control inside an owl dialog. It is working perfectly the first time and the chromium embedded control shows the page properly. It is important to mention here that the first url which is say "http//www.someurl" navigates internally to "http://www.anotherurl/opensomething" each time. When we close the Owl MDI window and then try to open it again, the CEFSharp browser control tries to go straight to "http://www.anotherurl/opensomething" instead of going to "http//www.someurl" which it is being specifically asked to navigate to. We are using Chromiumbrowser load method to load the url but just cannot make it to load the first url from the second time onward. Our CEFsharp version is 63.03 . However if we open the chromium browser control in its own window and not embed it inside the MDI dialog it works perfectly everytime. Can't figure out so far as to why this is not loading the url properly from the second time around. Thanks for any help in advance.

ShellExecute url in browser does not always set focus on browser

I use ShellExecute in a GUI Aplication (created with Win API) to open a given hyperlink in the default browser of the user like:
ShellExecute(0, 0, "www.stackoverflow.com", 0, 0, SW_SHOWMAXIMIZED); // Just an example
This works and the site is correctly openend in the default browser.
However, I want the browser to take focus once it is started. At the moment this works only sometimes: say I execute the function like shown above in a button-click callback. Then it works as expected and the browser takes focus.
However, it takes some time after the button click until the browser is opened. If I set the focus in the meantime to, say an edit control, the edit control (and with it the whole GUI) keeps the focus with the browser being opened in the background. But I want the behavior to be consistent such that the browser always takes the focus, regardless of the user interaction in the small time period after clicking on the button.
How can this be achieved?
I already tried ShellExecuteEx and WaitForInputIdle, then retrieving the main window handle from the process ID. This however doesn't work unfortunatly, because ShellExecuteEx doesn't always return a process ID (even if SEE_MASK_NOCLOSEPROCESS is set)...
Specify "open" as the second parameter (the operation) instead of 0/NULL.

CEF closing/resizing issues inside a big application plugin

I'm writing a plugin for a big x64 application in C++. I want the plugin to open a dialog and show a web view of my site.
I'm been able to use WKWebView in macOS and it works well. On Windows I'm evaluating CEF https://bitbucket.org/chromiumembedded/cef (please let me know of any alternative, ideally I would like it to be Webkit-based).
Let's say the application framework that is hosting my plugin has already created a window for my plugin and has it's own message loop, so I can only receive events in a sort of WindowProc. I can also get the HWND of the window.
My implementation is inspired by cefsimple example, because cefclient is way too complicated. I've implemented the subprocess architecture with the external executable and everything works fine until it's rendering the client area of the window. Then I have problems with closing the window (it crashes) and resizing the window interactively (the window frame is resized but the web view in the client area does not resize).
I've tried all possible combinations, but I've run out of ideas. Namely:
If I use CefRunMessageLoop() the web view is rendered correctly but the main application does not process the UI events like close window button. Resize does not work.
If I call CefDoMessageLoopWork() myself once in a while (from WindowProc) the web view is rendered correctly and it processes the close button, but it crashes. Resize does not work.
If I use settings.multi_threaded_message_loop = true the web view is rendered correctly and I can close the window without crash. The destructor of the window calls CefShutdown(). But if I try to reopen the window it crashes! Are CefInitialize and CefShutdown allowed to be called only once?
And resizing still does not work. I don't understand why in the cefsimple example resizing works and in my window it does not work.
Besides message processing issues, probably I'm not closing the browser correctly, any advice? Why is so complicated? WKWebView is so straighforward!
There is no error message, no stack trace, no source code, no OS/CEF version - I doubt this question can be answered.
I can only tell you how to close browser cleanly: call CefShutdown at the right time (see cefclient/cefsimple examples) and do not keep any references to CEF objects when calling shutdown.

IE WebBrowser not sending some redrawing messages

I have a property sheet view with few property pages. One of this property page contains a HTML representation via a CHtmlView derived class.
Initially, the .html file is correctly rendered. The problem is that sometimes switching between properties pages sometime the html file is not redraw. The behavior appears randomly.
According to Spy++ in such situation some Windows messages are not sent by WebControl (Internet Explorer_Server layer): WM_ERASEBKGRD, WM_PAINT or WM_NCPAINT.
Approaches such Q179421 or Q183161 are not useful. My machine runs IE 10.
The windows hierarchy is: Shell Embedding -> Shell DocObject View -> Internet Explorer_Server.
Do you know any workaround that would determine Internet Explorer_Server layer to send these messages always?
Update: Even if in the real application I make some intensive processing, I was able to reproduce this bug even with a dummy Html content.

C++ Builder runtime error - cannot focus a disabled or invisible window

On main form I have TPageControl and on all of it's tabs I have corresponding Save buttons which are activated on Alt+S combination.
Of course, depending on which tab is opened at the moment, the handler for corresponding Save button should be called; but I get "cannot focus a disabled or invisible window" runtime error if I try to save with Alt+S.
And I've noticed that, the handler of a Save button from the tab which was active before the current tab, is called, but don't know why.
I tried putting Save buttons in panels (it worked fine for some similar problems), but still the same thing happens.
Cheers.
You could do it all with one button. In the OnClick handler, check which page is the current one, and call the saving function for that page.