Note: The progrm must be linked with OLE32 and comctl32 library files.
Okay, I am not in favor of putting in huge amounts of theory, so I'll get started.
It is assumed that you already know some about the CreateWindow and CreateWindowEx WinAPI functions. I used the d_hwnd variable in code; it is the dialog's handle of our (the main window listview control is created at). Also, I used the l_hwnd variable in code; it is the handle of your listview control.
Core of the Article
1. First, create a listview:
HWND l_hwnd = CreateWindowEx(WS_EX_STATICEDGE, WC_LISTVIEW,"", WS_CHILD, 0,0,200,300, d_hwnd,(HMENU)200, GetModuleHandle(NULL), NULL ); //to turn the listview transparent, remove the // from the //following two lines //ListView_SetTextBkColor(l_hwnd,CLR_NONE); //ListView_SetBkColor(l_hwnd,CLR_NONE); assert(l_hwnd != NULL);Once the listview window has been created, you can load image in it. Alternatively, you may have a dialog in resources that already has a listview on it. If so, skip this step.
2. Load the external Image file from the Internet by its URL.
IBBkImg.ulFlags=LVBKIF_SOURCE_URL | LVBKIF_STYLE_TILE;
//if you want the image not to have a tile, remove the style
//you can replace C:\\my_image.bmp with any working image URL
//from the Internet.
//Try ucancode logo http://www.ucancode.com/img/logo.gif
OleInitialize(NULL); //Initialize the OLE libraries
//now load image
SendMessage (l_hwnd,LVM_SETBKIMAGE,0,(LPARAM)(LPLVBKIMAGE) &IBBkImg);
Load image from resources:
A res:// protocol will be used here to load the image from your resources. You will have to format a string for the pszImage field of the LVBKIMAGE structure, so that it loads from the resources of your EXE file.
First,you need the ID of the resource (an integer); then, you must know either that it is an icon file or an image. The format of the string that will be assigned to pszImage looks like this:
//...... same as above IBBkImg.pszImage="res://C:\\myprog.exe/#2/#101"; //...... same as above
where C:\\myprog.exe is the current program filename, #2 is type of resource (you are loading a image, so you will use #2). To load and icon, you will have to use #3. #101 is the ID of our image resource to load.
To obtain the current application name, look into MSDN for GetModuleFileName.
Load the image from an external EXE or DLL file:
For this purpose, either you will have to format a string to load from resources of an external executable, DLL, or OCX file. Simply change C:\\myprog.exe to the absolute path of another EXE or DLL file, and all is done.
I tried loading a bitmap (ID 1047) from the resources of an external EXE file, winhlp32.exe, that is found in the Windows folder (in Windows XP; I'm am not sure about others). So, my formated string became "res://C:\\WINDOWS\\winhlp32.exe/#2/#1047" and code became: