<img>

How to load image?

Method 1

Called by the framework to exchange and validate dialog data.

CString szUrl;

void CMyMultiPageDlg::DoDataExchange(CDataExchange* pDX){
    DDX_DHtml_Img_Src(pDX, _T("img_id"), szUrl);
    CMultiPageDHtmlDialog::DoDataExchange(pDX)
}

Method 2

IHTMLImgElement interface

This interface provides access to some of the properties and methods supported by the img element and the input element of the image type.

CComBSTR url("../images/myImage.png");
CComPtr<IHTMLImgElement> pImg;

// Retrieve the requested interface pointer from the HTML element identified by element id.
if(SUCCEEDED(GetElementInterface(_T("img_id"), __uuidof(IHTMLImgElement), (void**)&pImg))) 
    pImg->put_src(url);

How to refresh Image?

Adding random integer behind question mark , when you put the same image path with different content.

It'll refresh image on your browser.

CString  szUrl;
CComBSTR url;
CComPtr<IHTMLImgElement> pImg;

szUrl.Format("../images/myImage.png?%d", rand());
url = szUrl.AllocSysString();

if(SUCCEEDED(GetElementInterface(_T("img_id"), __uuidof(IHTMLImgElement), (void**)&pImg)))
    pImg->put_src(url);

How to change image size and offset?

Retrieve element property by IHTMLElement rather than IHTMLImgElement.

long left  = 150;
long width = 800;
long top   = 128;

long right, height;
CComPtr<IHTMLElement> pElem;
CComQIPtr<IHTMLStyle> pStyle;

if(SUCCEEDED(GetElementInterface(_T("img_id"), __uuidof(IHTMLElement), (void**)&pElem))) {

    // get offset
    pElem->get_offsetRight(&right);
    pElem->get_offsetHeight(&height);

    // put offset
    pElem->get_style(&pStyle);
    pStyle->put_top(CComVariant(top));
    pStyle->put_left(CComVariant(left));

    //put image size
    pStyle->put_height(CComVariant(height));
    pStyle->put_width(CComVariant(width));
}

Note

IHTMLImgElement Properties

Property Description
align Sets or retrieves how the object is aligned with adjacent text
alt Sets or retrieves a text alternative to the graphic.
border Sets or retrieves the width of the border to draw around the object.
complete Retrieves whether the object is fully loaded.
dynsrc This property is deprecated. Sets or retrieves the address of a video clip or VRML world to display in the window.
fileCreatedDate Retrieves the date the file was created.
fileModifiedDate Retrieves the date the file was last modified.
fileUpdatedDate Retrieves the date the file was last updated.
height Sets or retrieves the height of the object.
hspace Sets or retrieves the horizontal margin for the object.
isMap Sets or retrieves whether the image is a server-side image map.
loop Sets or retrieves the number of times a sound or video clip will loop when activated.
lowsrc Sets or retrieves a lower resolution image to display.
name Sets or retrieves the name of the object.
nameProp Retrieves the file name specified in the IHTMLLinkElement4::href or IHTMLEmbedElement2::src property of the object.
onload Sets or retrieves a pointer to the event handler function associated with the HTMLFrameSiteEvents::onload event. The HTMLFrameSiteEvents::onload event occurs immediately after the browser loads the object.
protocol Sets or retrieves the protocol portion of a URL.
readyState Retrieves a value that indicates the current state of the object.
src Sets or retrieves a URL to be loaded by the object.
start Sets or retrieves when a video clip file should begin playing.
useMap Sets or retrieves the URL, often with a bookmark extension (#name), to use as a client-side image map.
vrml Sets or retrieves the IHTMLDocument2::URL of the VRML world to be displayed in the window.
vspace Sets or retrieves the vertical margin for the object.
width Sets or retrieves the calculated width of the object.

results matching ""

    No results matching ""