ImageList images won't draw if from VB

ImageList images won't draw if from VB

Page 1 of 1

3 Replies - 3150 Views - Last Post: 08 June 2006 - 09:30 PM Rate Topic: -----

#1 brettg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-June 06

ImageList images won't draw if from VB

Posted 08 June 2006 - 07:20 PM

Can anyone help with this VB/C++ problem?

I have written an ATL ActiveX control. It uses an ImageList to draw images on it, using the ImageList_Draw API. All is well and good except with classic VB. I created a test app, placing my component and a standard ImageList on the VB form and setting the ImageList into my component. The ImageList_Draw function fails for some reason. This only happens with VB projects, not C++, C#, etc.

I tried setting the images in at design time and also programmatically at runtime.

Has anyone seen this problem or know what could be causing it?

Thanks for any help.

cheers
-brett

Is This A Good Question/Topic? 0
  • +

Replies To: ImageList images won't draw if from VB

#2 Videege  Icon User is offline

  • rÍvant.toujours
  • member icon

Reputation: 6
  • View blog
  • Posts: 1,413
  • Joined: 25-March 03

Re: ImageList images won't draw if from VB

Posted 08 June 2006 - 07:22 PM

Can you please post the code for the ActiveX control as well as the VB test applet you used to try it out?
Was This Post Helpful? 0
  • +
  • -

#3 brettg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-June 06

Re: ImageList images won't draw if from VB

Posted 08 June 2006 - 07:39 PM

I can't post the ATL project code, but I can post the relevant code snippets. But let me check something first and get back to you. Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 brettg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-June 06

Re: ImageList images won't draw if from VB

Posted 08 June 2006 - 09:30 PM

OK, here is the code dealing with the ImageList. The component has an owner-drawn ListView on it, which I set the ImageList into. In the OnDraw function, I get the ImageList from the ListView and try to draw an image from it. Please see below. I know its not much to go on. This only fails with VB imagelists.

thx
-brett



VB Code
-------

Private Sub Form_Load()

	'Comment these lines if adding the images in the designer

		ImageList1.ListImages.Add , , LoadPicture(App.Path & "\cal.bmp")
		ImageList1.ListImages.Add , , LoadPicture(App.Path & "\delete.bmp")
		ImageList1.ListImages.Add , , LoadPicture(App.Path & "\edit.bmp")
		ImageList1.ListImages.Add , , LoadPicture(App.Path & "\extract.bmp")
		
		Set MyCtrl.ImageList = ImageList1

end sub


C++ Code
--------

BOOL MyCtrl::put_ImageList( IDispatch *pImgList )
{
	OLE_HANDLE ohImgList;
	getImageListPtr( pImgList, m_spImgList );
	spImgList->get_hImageList( &ohImgList );
	HIMAGELIST hImgList = ListView_SetImageList( m_hwListView, ohImgList, LVSIL_SMALL );
	return S_OK;
}


void MyCtrl::getImageListPtr( IDispatch* pImgList, CComPtr<IImageList>& spImgList )
{
	IID iid;

	// try v6 first
	IIDFromString( IID_IMAGELIST_V6, &iid );	// v6
	pImgList->QueryInterface( iid, (void**)&spImgList );

	if( !spImgList )
	{
		IIDFromString( IID_IMAGELIST_V5, &iid );	// v5
		pImgList->QueryInterface( iid, (void**)&spImgList );
	}
}


LRESULT MyCtrl::OnDraw( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
	// other code
	// ...


	HIMAGELIST hImageList = ListView_GetImageList( m_hwListView, LVSIL_SMALL );
	if( hImageList )
	{
		UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK; // ILD_OVERLAYMASK
		bOk = ImageList_Draw( hImageList, lvi.iImage, hdc,
			rcCol0Icon.left, rcCol0Icon.top,
			//ILD_NORMAL );
			(bHighlight? ILD_BLEND:0) | ILD_TRANSPARENT | nOvlImageMask );

		*** !!! bOk is FALSE here and nothing was drawn !!! ***
	}

}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1