Compartir a través de


NM_INLINE_STYLE

4/8/2010

This notification message is sent by the HTML viewer control to notify the application that a stylesheet is about to be loaded via the <link> tag and gives the application a chance to bypass the operation. An alternate stylesheet can be added at this time using the DTM_ADDSTYLE message.

Syntax

NM_HTMLVIEW * pnmHTMLView = (NM_HTMLVIEW *)lParam;
szHrefText = pnmHTMLView->szTarget;

Parameters

  • pnmHTMLView
    Points to an NM_HTMLVIEW structure that contains information about the NM_INLINE_STYLE notification message.
  • szHrefText
    A null-terminated string that contains the contents of the HREF attribute of the LINK tag in the HTML text.

Return Value

If the application handles this message it should return a non-zero result. The HTML control will not load the specified stylesheet in that case. Returning a zero result to the HTML control will result in the default control handling to occur and the specified stylesheet to be loaded.

Code Example

The following code example demonstrates how to use NM_INLINE_STYLE.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

/******************************* example.html *********************************
<html>
    <head>
        <title>NM_INLINE_STYLE Test</title>
        <link rel="stylesheet" type="text/css" href="inline0.css" />
        <link rel="stylesheet" type="text/css" href="inline1.css" />
    </head>
    <body>
        <p id="p0">Ordinarily, this text would appear green. However ExampleWndProc can make it blue.</p>
        <p id="p1">This text should appear red, even when using ExampleWndProc.</p>
    </body>
</html>
*/
/******************************** inline0.css *********************************
p#p0 {color: green}
*/
/******************************** inline1.css *********************************
p#p1 {color: red}
*/
LRESULT CALLBACK ExampleWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    // For clarity, handling of other Windows messages has been omitted.
    // ...
    case WM_NOTIFY:
        {
            LPNMHDR pnmHdr = (LPNMHDR)lParam;
            switch (pnmHdr->code)
            {
            // For clarity, handling of other notification codes has been omitted.
            // ...
            case NM_INLINE_STYLE:
                {
                    NM_HTMLVIEW * pnmHTMLView = (NM_HTMLVIEW *)pnmHdr;
                    // Note the treatment of (pnmHTMLView->szTarget) as an ANSI string.
                    if (strstr((const char *)(pnmHTMLView->szTarget), "inline0.css"))
                    {
                        SendMessage(GetDlgItem(hwnd, IDC_HTML),
                                    DTM_ADDSTYLE, 
                                    0, 
                                    (LPARAM)TEXT("p#p0 {color:blue}"));
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
        }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

Requirements

Header htmlctrl.h
Library htmlctrl.lib
Windows Mobile Pocket PC 2002 and later, Smartphone 2002 and later

See Also

Reference

HTML Control API Notifications
NM_HTMLVIEWA
NM_HTMLVIEWW
HTML Control API Window Styles