ShowHTMLDialogEx + HTMLDLG_MODELESS modale ?!

Résolu
HeavenForsaker Messages postés 223 Date d'inscription mercredi 13 juillet 2005 Statut Membre Dernière intervention 8 août 2011 - 31 mai 2009 à 20:12
HeavenForsaker Messages postés 223 Date d'inscription mercredi 13 juillet 2005 Statut Membre Dernière intervention 8 août 2011 - 1 juin 2009 à 11:20
Bonjour,

Je tente d'afficher une page HTML à l'intérieur d'une fenêtre, pour ce faire j'ai utilisé la fonction ShowHTMLDialogEx avec le flag HTMLDLG_MODELESS (identique à ShowModelessHTMLDialog) et j'obtiens un résultat pour le moins surprenant, à savoir que la fonction s'exécute correctement (la page HTML s'affiche) mais la fonction ne rend jamais la main au thread appellant !
La fonction ShowHTMLDialogEx se comporte donc comme une fonction modale à la différence qu'elle ne rends jamais la main au thread appellant même lorsqu'on ferme la page HTML.
J'ai également fait le test en utilisant la fonction ShowModelessHTMLDialog et j'obtiens le même résultat.

PS:
modale = bloquante
modeless = non bloquante

Sur MSDN on peut lire :
"This function creates a modeless dialog box that contains HTML. The function does not return until the dialog box has been dismissed.
...
Modal dialog boxes created by this method are synchronous; that is, the call to ShowHTMLDialogEx does not return until the dialog box closes. Modeless dialog boxes created by this method are asynchronous; that is, the dialog box is created in a separate process, and the call to ShowHTMLDialogEx returns before the dialog box closes."

Voici le code :
---------------------------------------------------------------------------------
    CoInitializeEx(0, COINIT_MULTITHREADED);

    HINSTANCE hinstMSHTML = LoadLibrary(_TEXT("MSHTML.DLL"));
    if (hinstMSHTML == NULL)
       return;

    SHOWHTMLDIALOGEXFN* pfnShowModelessHTMLDialog;
    pfnShowModelessHTMLDialog = (SHOWHTMLDIALOGEXFN*)GetProcAddress(hinstMSHTML, "ShowHTMLDialogEx");
    if (pfnShowModelessHTMLDialog)
    {
        IMoniker *pURLMoniker;
        BSTR bstrURL = SysAllocString(L"C:\\doc.html");
        CreateURLMoniker(NULL, bstrURL, &pURLMoniker);
        if (pURLMoniker)
        {
            DWORD dwFlags = HTMLDLG_MODELESS | HTMLDLG_VERIFY;
            HRESULT hres = (*pfnShowModelessHTMLDialog)(hwndParent, pURLMoniker, dwFlags, NULL, NULL, NULL);
            pURLMoniker->Release();
        }

        if (bstrURL)
            SysFreeString(bstrURL);
    }

    FreeLibrary(hinstMSHTML);

    CoUninitialize();

1 réponse

HeavenForsaker Messages postés 223 Date d'inscription mercredi 13 juillet 2005 Statut Membre Dernière intervention 8 août 2011
1 juin 2009 à 11:20
J'ai trouvé, il faut virer CoInitializeEx(0, COINIT_MULTITHREADED); et CoUninitialize();
3
Rejoignez-nous