YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


CListView Loading Images BMP, PNG, GIF, JPEG, WMF, ICO, and EMF Files

 
 
Most Win32 API developers use a static control (with style SS_ICON or SS_BITMAP)to load bitmap and icon files. To advance the support for more image formats, some use third-party libraries such as CXImage (as far I remember the name). Wouldn't it be better to use native control and routines to load BMP, PNG, GIF, JPEG, WMF, ICO, and EMF files in Windows programs? I hope you say yes!
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.

Assumptions

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.

LVBKIMAGE IBBkImg;
ZeroMemory(&IBBkImg,sizeof(LVBKIMAGE));

IBBkImg.ulFlags=LVBKIF_SOURCE_URL | LVBKIF_STYLE_TILE;

//if you want the image not to have a tile, remove the style
//LVBKIF_STYLE_TILE

IBBkImg.pszImage="C:\\my_image.bmp";
//you can replace C:\\my_image.bmp with any working image URL
//from the Internet.
//Try ucancode logo http://www.ucancode.net/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:

IBBkImg.pszImage="res://C:\\WINDOWS\\winhlp32.exe/#2/#1047";

That's all.

 

 

 

 

Copyright ?1998-2024 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net