Take the 2-minute tour ×

How can I use the ListView_GetBkImage macro:


... from a C#/WinForms application? I think this macro just wraps the SendMessage method, but I'm not sure. I couldn't find any C#-based samples on this.

Basically I'm trying to get a LVBKIMAGE ( http://msdn.microsoft.com/en-us/library/bb774742(v=VS.85).aspx ) structure that references the Desktop's background bitmap.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You cannot. A macro is processed at compile time by the C/C++ compiler, but you want to access the binary library. You will just have to find the macro in the source, see what it does and do the same in your C# code. It shouldn't be anything too complex. Download the Platform SDK if you don't already have it and look in the .h file mentioned in the documentation.

Edit: OK, so the macro is defined as:

#define ListView_GetBkImage(hwnd, plvbki) \
    (BOOL)SNDMSG((hwnd), LVM_GETBKIMAGE, 0, (LPARAM)(plvbki))

SNDMSG is simply defined as SendMessage. LVM_GETBKIMAGE is an integer - it's 0x1045 for the ASCII version and 0x108B for the Unicode version. (You probably want the Unicode version if you're unsure.) So the entire thing resolves to:

(BOOL)SendMessage(hwnd, 0x108B, 0, plvbki)

There should be easy enough to map to C#. Look in System.Windows.Forms using Reflector to see how Microsoft have imported the SendMessage function. It will be marked internal, so you cannot call it, but you can copy it. plvbki is a pointer to a struct - you'll need to create a C# equivalent of LVBKIMAGE. Actually, MS have probably done that for you too, so look around for that.

share|improve this answer
It's too complex for someone without a C/C++ background, unfortunately. As far as I could deduce from what I looked at, it's ultimately some way of calling SendMessage with some flags and pointers and somehow coming back with a filled-out structure. –  MusiGenesis Apr 14 '10 at 1:41
OK, I've looked into it and updated the post. See how you go with that. –  EMP Apr 14 '10 at 4:00
add comment

Your Answer


