here is my whole .cpp file, which i use and i have made comments at the nsIwebsetup call... have a look at it...Is this the correct approach for embedding Gecko...Am i missing something else
1) My goal is to have an engine which renders given Html and performs javascript of that html. A trimmed browser in short(no history,back,forward, ect)...And that too by using C++.. so that i could easily port it to WinCe...Currently both my wince & win32 only render HTML page... 2) Any sample C++ apps to embed gecko..I don't want the XULAPP approach..i need a pure C++ approach.. can anyone help me... #include "stdafx.h" #include "Browse_ce.h" #include <windows.h> #include <commctrl.h> #define MAX_LOADSTRING 100 /* Embedding APIs */ #include "nsEmbedAPI.h" #include "nsEmbedCID.h" #include "nsStringAPI.h" /* XPCOM and its macro utilities */ #include "nsCOMPtr.h" #include "nsComponentManagerUtils.h" #include "nsServiceManagerUtils.h" /* Interfaces (frozen) */ #include "nsIWebBrowser.h" #include "nsIWebBrowserSetup.h" #include "nsIPrefService.h" #include "nsIComponentRegistrar.h" /* Interfaces (non-frozen) */ #include "nsIBaseWindow.h" #include "nsIWebNavigation.h" /* Linker settings */ //#pragma comment(linker, "/NODEFAULTLIB:MSVCRT") #pragma comment(lib, "xpcomglue_s.lib") #pragma comment(lib, "xpcom.lib") #pragma comment(lib, "embed_base_s.lib") #pragma comment(lib, "nspr4.lib") // Global Variables: HINSTANCE g_hInst; // current instance HWND g_hWndMenuBar; // menu bar handle nsresult InitGeckoArea(HWND hWnd, nsIWebBrowser* aContent) ; //XXX You can implement this global as _tWinMain's local. // In that case, you should use nsCOMPtr<nsIWebBrowser> // instead of raw pointer nsIWebBrowser* . nsIWebBrowser* gGecko = nsnull; // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE, LPTSTR); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); #ifndef WIN32_PLATFORM_WFSP INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); #endif // !WIN32_PLATFORM_WFSP int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; /****************************************************/ nsString sBinDir; nsCOMPtr<nsILocalFile> pCOM_lf; nsCOMPtr<nsIWebBrowser> pCOM_wb; nsCOMPtr<nsIWebNavigation> pCOM_wn; sBinDir.Assign (NS_ConvertUTF8toUTF16 ("\\Storage Card")); nsresult n = NS_NewLocalFile(sBinDir, PR_TRUE, getter_AddRefs (pCOM_lf)); nsresult rv = NS_InitXPCOM3 (nsnull, pCOM_lf, nsnull, nsnull, 0); rv = NS_InitEmbedding (pCOM_lf, nsnull); nsCOMPtr<nsIComponentRegistrar> registrar; rv = NS_GetComponentRegistrar(getter_AddRefs(registrar)); rv = registrar->AutoRegister(nsnull); /****************************************************************/ // Perform application initialization: if (!InitInstance(hInstance, nCmdShow)) { NS_IF_RELEASE(gGecko); NS_TermEmbedding(); return FALSE; return FALSE; } #ifndef WIN32_PLATFORM_WFSP HACCEL hAccelTable; hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BROWSE_CE)); #endif // !WIN32_PLATFORM_WFSP // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { #ifndef WIN32_PLATFORM_WFSP if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) #endif // !WIN32_PLATFORM_WFSP { TranslateMessage(&msg); DispatchMessage(&msg); } } /*NS_IF_RELEASE(gGecko); NS_TermEmbedding();*/ return (int) msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BROWSE_CE)); wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = szWindowClass; return RegisterClass(&wc); } // // FUNCTION: InitInstance(HINSTANCE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; TCHAR szTitle[MAX_LOADSTRING]; // title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name g_hInst = hInstance; // Store instance handle in our global variable #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) // SHInitExtraControls should be called once during your application's initialization to initialize any // of the device specific controls such as CAPEDIT and SIPPREF. SHInitExtraControls(); #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_BROWSE_CE, szWindowClass, MAX_LOADSTRING); #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) //If it is already running, then focus on the window, and exit hWnd = FindWindow(szWindowClass, szTitle); if (hWnd) { // set focus to foremost child window // The "| 0x00000001" is used to bring any owned windows to the foreground and // activate them. SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001)); return 0; } #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP if (!MyRegisterClass(hInstance, szWindowClass)) { return FALSE; } hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } if (!gGecko) { nsCOMPtr<nsIWebBrowser> gecko(do_CreateInstance(NS_WEBBROWSER_CONTRACTID)); if (gecko) { /* Here I have no idea to handle rv */ nsresult rv = InitGeckoArea(hWnd, gecko); NS_ADDREF(gGecko = gecko); } } #ifdef WIN32_PLATFORM_PSPC // When the main window is created using CW_USEDEFAULT the height of the menubar (if one // is created is not taken into account). So we resize the window after creating it // if a menubar is present if (g_hWndMenuBar) { RECT rc; RECT rcMenuBar; GetWindowRect(hWnd, &rc); GetWindowRect(g_hWndMenuBar, &rcMenuBar); rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top); MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE); } #endif // WIN32_PLATFORM_PSPC ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; #if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP) static SHACTIVATEINFO s_sai; #endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { #ifndef WIN32_PLATFORM_WFSP case IDM_HELP_ABOUT: DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About); break; #endif // !WIN32_PLATFORM_WFSP #ifdef WIN32_PLATFORM_WFSP case IDM_OK: DestroyWindow(hWnd); break; #endif // WIN32_PLATFORM_WFSP #ifdef WIN32_PLATFORM_PSPC case IDM_OK: SendMessage (hWnd, WM_CLOSE, 0, 0); break; #endif // WIN32_PLATFORM_PSPC default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: #ifdef SHELL_AYGSHELL SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hWnd; mbi.nToolBarId = IDR_MENU; mbi.hInstRes = g_hInst; if (!SHCreateMenuBar(&mbi)) { g_hWndMenuBar = NULL; } else { g_hWndMenuBar = mbi.hwndMB; } #ifndef WIN32_PLATFORM_WFSP // Initialize the shell activate info structure memset(&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); #endif // !WIN32_PLATFORM_WFSP #endif // SHELL_AYGSHELL break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: #ifdef SHELL_AYGSHELL CommandBar_Destroy(g_hWndMenuBar); #endif // SHELL_AYGSHELL PostQuitMessage(0); break; #if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP) case WM_ACTIVATE: // Notify shell of our activate message SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; #endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } #ifndef WIN32_PLATFORM_WFSP // Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: #ifdef SHELL_AYGSHELL { // Create a Done button and size it. SHINITDLGINFO shidi; shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU; shidi.hDlg = hDlg; SHInitDialog(&shidi); } #endif // SHELL_AYGSHELL return (INT_PTR)TRUE; case WM_COMMAND: #ifdef SHELL_AYGSHELL if (LOWORD(wParam) == IDOK) #endif { EndDialog(hDlg, LOWORD(wParam)); return (INT_PTR)TRUE; } break; case WM_CLOSE: EndDialog(hDlg, message); return (INT_PTR)TRUE; } return (INT_PTR)FALSE; } nsresult InitGeckoArea(HWND hWnd, nsIWebBrowser* aContent) { nsresult rv; nsCOMPtr<nsIWebBrowserSetup>mWebSetup = do_QueryInterface(aContent,&rv); if (mWebSetup) { //Here i am getting as success, returns 0x000000 n = mWebSetup->SetProperty(nsIWebBrowserSetup::SETUP_IS_CHROME_WRAPPER,PR_TRUE); //But here i get 0x8000ffff, even if i call this alone. n = mWebSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_JAVASCRIPT,PR_TRUE); } // Get the view's ClientRect which to be passed in // to the InitWindow() call below nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(aContent, &rv)); NS_ENSURE_SUCCESS(rv, rv); RECT rcLocation; ::GetClientRect(hWnd, &rcLocation); if (::IsRectEmpty(&rcLocation)) { rcLocation.bottom++; rcLocation.top++; } rv = baseWindow->InitWindow(hWnd, nsnull, 0, 0, rcLocation.right - rcLocation.left, rcLocation.bottom - rcLocation.top); NS_ENSURE_SUCCESS(rv, rv); rv = baseWindow->Create(); NS_ENSURE_SUCCESS(rv, rv); rv = baseWindow->SetVisibility(PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIWebNavigation> webNavigation(do_QueryInterface(aContent, &rv)); NS_ENSURE_SUCCESS(rv, rv); return webNavigation->LoadURI(NS_LITERAL_STRING("http://discovery-tests/discovery/sample.html").get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull); } #endif // !WIN32_PLATFORM_WFSP -- View this message in context: http://www.nabble.com/Javascript-not-working----tp23849193p23863852.html Sent from the Mozilla - Embedding mailing list archive at Nabble.com. _______________________________________________ dev-embedding mailing list dev-embedding@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-embedding