nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) ); if ( !ppScriptGlobalObj ) { return NS_ERROR_FAILURE; } nsCOMPtr<nsIDocShell> ppDocShell; ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) ); if ( !ppDocShell ) { return NS_ERROR_FAILURE; } nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) ); if ( !ppBaseWindow ) { return NS_ERROR_FAILURE; }  nsCOMPtr<nsIWidget> ppWidget; ppBaseWindow->GetMainWidget( getter_AddRefs( ppWidget ) ); HWND hMainFrame = (HWND)ppWidget->GetNativeData( NS_NATIVE_WIDGET );
HWND hMainFrame = hwndForDOMWindow( window );
nsNativeAppSupportWin::ReParent( nsIDOMWindowInternal *window, HWND newParent ) {    nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) );    if ( !ppScriptGlobalObj ) {        return NS_ERROR_FAILURE;    }    nsCOMPtr<nsIDocShell> ppDocShell;    ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) );    if ( !ppDocShell ) {        return NS_ERROR_FAILURE;    }    nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) );    if ( !ppBaseWindow ) {        return NS_ERROR_FAILURE;    }    nsCOMPtr<nsIWidget> ppWidget;    ppBaseWindow->GetMainWidget( getter_AddRefs( ppWidget ) );    HWND hMainFrame = (HWND)ppWidget->GetNativeData( NS_NATIVE_WIDGET );    if ( !hMainFrame ) {        return NS_ERROR_FAILURE;    }    // Filter out WM_SETFOCUS messages while reparenting to     // other than the desktop.    //    // For some reason, Windows generates one and it causes    // our focus/activation code to assert.    LONG oldProc = 0;    if ( newParent ) {        // Subclass the window.        oldProc = ::SetWindowLong( hMainFrame,                                   GWL_WNDPROC,                                   (LONG)(WNDPROC)focusFilterProc );        // Store old procedure in window so it is available within        // focusFilterProc.        ::SetProp( hMainFrame, procPropertyName, (HANDLE)oldProc );    }    // Reset the parent.    ::SetParent( hMainFrame, newParent );    // Restore old procedure.    if ( newParent ) {        ::SetWindowLong( hMainFrame, GWL_WNDPROC, oldProc );        ::RemoveProp( hMainFrame, procPropertyName );    }    return NS_OK;}