so I created a thread to navigate to these pages (as I can't use wxSleep() in the main function ) and used wxSleep() after loading every page to execute some codes on it
the problem is that after using wxSleep() the browser becomes unusable and if I used it the program crashes and I get (from visual studio debugger) this error :
Exception thrown at 0x57D2EB9A (mshtml.dll) ....
and the debugger goes to line 914 in webview_ie.cpp and says this is the next line to execute when this thread return
this is my code :
1 - main.h
Code: Select all
#include <wx\wx.h>
#include <wx\webview.h>
#include <wx\thread.h>
#include <vector>
#define ID_WEB 598
class Navigator : public wxThread
{
public :
Navigator(wxWebView *browse , wxString rurl , wxString rjs) : wxThread(wxTHREAD_DETACHED) {
browser = browse;
url = rurl;
js = rjs;
}
protected:
wxWebView *browser;
wxString url;
wxString js;
virtual ExitCode Entry();
};
class myFrame : public wxFrame
{
public:
myFrame(wxString title);
protected:
wxPanel *panel;
wxBoxSizer *box;
wxWebView *browser;
Navigator *nav;
};
myFrame::myFrame(wxString title) : wxFrame(nullptr,wxID_ANY,title,wxDefaultPosition,wxSize(600,600)) {
panel = new wxPanel(this, wxID_ANY, wxPoint(-1, -1));
box = new wxBoxSizer(wxVERTICAL);
browser = wxWebView::New(panel, ID_WEB);
box->Add(browser, 1, wxEXPAND | wxALL,0);
panel->SetSizer(box);
wxString url = "https://stackoverflow.com";
wxString js = "function aler(title) {alert(title);} aler(Alert);";
nav = new Navigator(browser, url, js);
nav->Create();
nav->Run();
}
wxThread::ExitCode Navigator::Entry() {
browser->LoadURL(url); // this works fine
wxSleep(10);
browser->RunScript(js); // the program crashes here with the error as I used wxSleep()
return(wxThread::ExitCode*)0;
}
Code: Select all
#include "main.h"
using namespace std;
class App : public wxApp
{
public:
bool OnInit();
myFrame *frame;
};
bool App::OnInit() {
frame = new myFrame("browser");
frame->Show();
return true;
}
wxIMPLEMENT_APP(App);