Hi

I was trying to figure out the way to put background images in list view controls. I was about to do it as an owner drawn control, but browsing throung the VCC include files I found there is a LVM_SETBKIMAGE message...

I wonder if anyone out there knows how to use it, I tried but it didn't seem to work :confused: .

Also the win32.hlp file doesn't say anything, so I'll appreciate any info you can give me... :)
Posted on 2003-06-10 12:52:21 by QvasiModo
LOCAL LVBKSTR	:LVBKIMAGE

mov LVBKSTR.ulFlags,LVBKIF_SOURCE_URL

mov LVBKSTR.pszImage,OFFSET ImageURL
mov LVBKSTR.xOffsetPercent,0
mov LVBKSTR.yOffsetPercent,0
invoke SendMessage,LVHANDLE,LVM_SETBKIMAGE,0,ADDR LVBKSTR
http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/messages/lvm_setbkimage.asp

The imageURL must be in the following format:

ImageURL db "file:///C:/Documents%20and%20Settings/hello.bmp",0
Posted on 2003-06-10 13:03:46 by donkey
Thanks! I'll try that...
Posted on 2003-06-10 13:19:16 by QvasiModo
Remeber to initialize ole with CoInitialize
Posted on 2003-06-10 14:29:23 by greenant
Yes, it's rare that I have an app that doesn't do that at startup now so I don't always think about it. Good catch greenant :alright:
Posted on 2003-06-10 14:54:27 by donkey
better search for it on the board. Cuz when you scroll your ListView your background is going to F**k.
Posted on 2003-06-10 16:09:45 by AceEmbler
Well, I've been trying this stuff, and I found out a couple of tricks:

1) you don't have to use an actual URL, just the full pathname should work fine.
2) you can use a resource as background image, with something of this form:

res://C:/Documents%20and%20Settings/Test.exe/Sample.jpg

or like this:

res://C:\Documents and Settings\Test.exe\Sample.jpg

assuming that your program is "Test.exe" and the background picture was defined in your resource script as resource type 2110 and ID name "Sample.jpg". Of course it is not mandatory for the ID to match the filename, but it is more intuitive that way.

I don't know how to do this with numeric IDs, though... Any help?
Posted on 2003-06-18 17:26:15 by QvasiModo
Try "#1234" for the resource name, it is a replacement for the actual number when loading resources. might work

ie

res://C:\Documents and Settings\Test.exe\#1234
Posted on 2003-06-18 17:51:57 by donkey

Remeber to initialize ole with CoInitialize


you dont have to do this in this example
Posted on 2003-06-18 17:58:55 by AceEmbler
You should have to AceEmbler:
Even if it is not required for the example above there may be changes later to common controls that make it necessary and it is better to do it now than have your code broken later.
From MSDN
Remarks

Because the list-view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before sending this message. It is best to call one of these functions when the application is initialized and call either CoUninitialize or OleUninitialize when the application is terminating.
Posted on 2003-06-18 18:01:25 by donkey
Hi AceEmbler,

Under Win2K at any rate you have to coinitialize, won't work without it.

Hi QvasiModo,

Couldn't get the RES: thing to work at all, must be only XP
Posted on 2003-06-18 18:35:31 by donkey
i have got XP
Posted on 2003-06-18 18:39:58 by AceEmbler
Hi AceEmbler,

Did you get the RES: thing to work in XP ? that would be nice to have since the image handle is not yet implemented. BTW he is right, the normal path will work. I remember when I played around with it I couldn't get it working so I put it off and later came back to it, in the mean time I added shortcut support so I initialized COM, thought that the URL syntax was the fix but it was the CoInitialize I guess. Never really ended up using them after all because of not being able to pass a handle or resource. I hate too many files with a program.
Posted on 2003-06-18 18:55:32 by donkey
I made a mistake in my previous post, the filename and the resource ID should be separated by a normal slash ("/"), NOT a back slash ("\"). So the URL would be something like this:

res://C:\Documents and settings\Test.exe/Image.jpg

donkey: I think my mistake above could have been the problem. I have Win98 and it works, so I suppose it should work for any Windows version.
Posted on 2003-06-20 11:16:20 by QvasiModo
Yeah, works fine I was using type IMAGE I just checked your original post. The #1001 thing works too for id number instead of name.
Posted on 2003-06-20 11:29:29 by donkey