Sending DTM_SETIMAGE message in compact framework

G

Guest

Hi
This is really a compact framework issue, but is posted here as there is no managed newsgroup for cf

I am trying to set an image in the html viewer control - i receive the NM_INLINE_IMAGE message, process the file and create a DTM_SETIMAGE message to pass back, but whatever i try i can't seem to get the html control to accept the image data
The code is included below, and makes extensive use of the OpenNETCF.WinAPI.Core class

protected virtual int OnNotifyMessage(ref Message m

int iRetval = 0
HtmlViewMessage hvm
NmHdr hdr = NmHdr.GetStruct(m.LParam)
switch (hdr.code

case NM_TITLE
hvm = HtmlViewMessage.GetStruct(m.LParam)
OnTitle(hvm.target)
break
case NM_BEFORENAVIGATE
hvm = HtmlViewMessage.GetStruct(m.LParam)
OnBeforeNavigate(hvm.target, hvm.data, hvm.exInfo, (int)hvm.dwCookieFlags)
break
case NM_CONTEXTMENU
HtmlContextMessage hcm = HtmlContextMessage.GetStruct(m.LParam)
string lnk = hcm.linkHREF
string tit = hcm.linkName
Point pt = hcm.pt
((EproMobile)_parent).showContext((pt.X+2), (pt.Y - 24))
//handle here only (dont show default ie context
iRetval = -1
break
case NM_HOTSPOT
hvm = HtmlViewMessage.GetStruct(m.LParam)
((EproMobile)_parent).hView_HotSpotClick(hvm.target)
break
case NM_INLINE_IMAGE
hvm = HtmlViewMessage.GetStruct(m.LParam)
string target = hvm.target.Substring(7, hvm.target.Length - 7);//strip "file://" from star
if(hvm.target.IndexOf("crypt") > 0)//image needs handlin

tr

//load image represented by hvm.targe
using( FileStream fsFileHandle = File.Open(target, System.IO.FileMode.Open)

byte[] baFileBytes = EncryptionUtils.rc4.decryptBinaryStream2ByteArray(fsFileHandle)
MemoryStream iStream = new MemoryStream(baFileBytes)
bmImage = new Bitmap(iStream)

if(bmImage==null

throw new Exception("Image failed to load.")

else //image successfully loade

if(imb==null

imb = new InMemoryBitmap()


// Get required Win32 callback
if ( m_ct == null

IntPtr hMod = Core.GetModuleHandle("mscoree1_0")
if ( hMod == IntPtr.Zero

throw new Exception("Failed to get at hBitmap object.");

IntPtr pfn = Core.GetProcAddress(hMod, "NSLHandle_Reference")
m_ct = new CallThunk(pfn, 2)


// Extract internal data into InMemoryBitmap object
IntPtr pObj = m_ct.Call(new int[] { 0x11, Image.GetHowFromImage(bmImage).ToInt32() } )
pObj = new IntPtr( Marshal.ReadInt32(pObj) )
Marshal.PtrToStructure(pObj, imb)

int size = Core.GetObject(imb.hBitmap, 0, (byte[])null)
if ( size != Marshal.SizeOf(typeof(DIBSECTION))

throw new Exception("Size of Dibsection incorrect")

byte[] buf = new byte[size]
if(ds==null

ds = new DIBSECTION()

size = Marshal.SizeOf(typeof(DIBSECTION))
size = Core.GetObject(imb.hBitmap, size, ds)

//need two data lots in memory, the BITMAP and the BIT

int iLengthHead = 20 + IntPtr.Size
int iLengthBits = ds.biSizeImage
IntPtr hBitmap = AllocCoTaskMem(size)
IntPtr bmBits = AllocCoTaskMem(iLengthBits)

BITMAP myBitmapStruct = new BITMAP();
myBitmapStruct.bmType = ds.bmType
myBitmapStruct.bmWidth = ds.bmWidth
myBitmapStruct.bmHeight = ds.bmHeight
myBitmapStruct.bmWidthBytes = ds.bmWidthBytes
myBitmapStruct.bmPlanes = ds.bmPlanesAndbmBitsPixel
myBitmapStruct.bmBits = bmBits

//bDeleteOld has to be fals
Marshal.StructureToPtr(myBitmapStruct, hBitmap, false)

for(int i=0; i<iLengthBits; i++

Marshal.WriteByte((IntPtr)((Int32)bmBits+i)
Marshal.ReadByte((IntPtr)((Int32)ds.bmBits+i)))


ds.bmBits = bmBits

for(int i=0; i<size; i++

Marshal.WriteByte((IntPtr)((Int32)hBitmap+i)
Marshal.ReadByte((IntPtr)((Int32)imb.hBitmap+i)))
}

imgInfo.dwCookie = hvm.dwCookieFlags;//cookie in this case
imgInfo.iOrigHeight = imb.cx;//width
imgInfo.iOrigWidth = imb.cy;//height

//NEXT LINE half works (i.e. gets image dimensions but not data)
//if you use imb.hBitmap?
imgInfo.hBitmap = hBitmap;
//instruct htmlview to try to delete bitmap when page unloads
imgInfo.bOwnBitmap = true;

SendMessage(_hwnd, (uint)DTM_SETIMAGE, (uint)0, ref imgInfo);

}
}
catch(Exception ex)
{

MessageBox.Show("10");
SendMessageLong(_hwnd, (IntPtr)DTM_IMAGEFAIL, (IntPtr)0, (IntPtr)(hvm.dwCookieFlags >> 8));
MessageBox.Show("11");
MessageBox.Show(ex.ToString() + " - " + target);
}
iRetval = -1;
}
else
{
iRetval = 0;
}
break;
default:
break;
}
return iRetval; //default: let control handle it
}

private class InMemoryBitmap
{
internal uint dword1;
public IntPtr hMemoryDC;
internal uint dword2;
internal uint dword3;
internal uint dword4;
internal uint dword5;
internal uint dword6;
public IntPtr hBitmap;
public int cx;
public int cy;
}
private struct BITMAP
{
public int bmType;
public int bmWidth;
public int bmHeight;
public int bmWidthBytes;
public uint bmPlanes; //and pixels
public IntPtr bmBits;
}

[DllImport("Ole32.dll", EntryPoint="CoTaskMemAlloc")]
private static extern IntPtr AllocCoTaskMem(Int32 cbSize);

[DllImport("coredll.dll")]
private static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, ref InlineImageInfo lParam);
 
Y

Yan-Hong Huang[MSFT]

Hello Adam,

Based on my understanding, the question is: how to set image to a HTML
Viewer Control in compact framework? Right?

Here is one sample from MSDN on this topic:
"Developing in C++ with the HTML Viewer Control"
http://msdn.microsoft.com/library/en-us/dnppc2k/html/ppc_viewer.asp?frame=tr
ue

It contains sample code on NM_INLINE_IMAGE part. Also, to avoid having the
(rather lengthy) code to handle the loading of GIF, JPG, BMP, and other
code using IMGDECMP, this code assumes you are using the free VOImage class
libraries from Virtual Office Systems, Inc.

By the way, you can also refer to a online sample at:
http://www.codeproject.com/ce/sthtmldialog.asp

It provides a STHtmlDialog library, which is an easy way to use a wrapper
that encapsulates most of work done with the HtmlView control.

Does that answer your question? Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

Yan-Hong Huang[MSFT]

Hi Adam,

Do you successfully set image in HTML View control already? If there is
anything I can do for you, please feel free to post here.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Top