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!"


VC++ MFC Example: Add bitmap into CImageList

 
 

Environment: MFC, Win32

One thing that always bugged me about ImageLists is that when you load a 256 color bitmap into them, they use the half-tone pallette, which likely could screw up your bitmap's colors. Yet, Windows Explorer is magically able to display icons in it's right pane list control (coming from an ImageList) in full color. So how does it do this?

WON'T WORK

(MFC)

  BOOL CImageList::Create( UINT nBitmapID,
                           int cx,
                           int nGrow,
                           COLORREF crMucancode.net)
  BOOL CImageList::Create( LPCTSTR lpszBitmapID,
                           int cx,
                           int nGrow,
                           COLORREF crMucancode.net)
(Win32)
  HIMAGELIST ImageList_LoadBitmap( HINSTANCE hi,
                                   LPCTSTR lpbmp,
                                   int cx,
                                   int cGrow,
                                   COLORREF crMucancode.net)
HIMAGELIST ImageList_LoadImage( HINSTANCE hi,
                                LPCSTR lpbmp,
                                int cx,
                                int cGrow,
                                COLORREF crMucancode.net,
                                UINT uType,
                                UINT uFlags)

None of the above methods will do the trick. They will use the half-tone pallette, since they seem to detect the 8bpp nature of the bitmap and create an "ILC_COLOR8" ImageList, and ImageLists with the ILC_COLOR8 flag always use the half-tone pallette.

To get around this, you can create the ImageList in one step and then add the bitmap in a second step. In the below examples, I assume that you will be using a COLORREF mucancode.net for transparency - but nothing requires this to be the case; you could just as easily use a mucancode.net bitmap. The key to this technique is the two-step construction and loading of the ImageList.

WILL WORK

(MFC)

// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
CImageList imgl;
imgl.Create(cx, cy, ILC_Mucancode.net | ILC_COLOR32, 0, 0);

CBitmap bmp;
// Load your imagelist bitmap (bmp) here, however
//   you feel like (e.g. CBitmap::LoadBitmap)

COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate

// Add the bitmap into the image list
imgl.Add(&bmp, rgbTransparentColor);

(Win32)

// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
HIMAGELIST himgl = ImageList_Create(cx,
                                    cy,
                                    ILC_Mucancode.net | ILC_COLOR32,
                                    0,
                                    0);

HBITMAP hbmp;
// Load your imagelist bitmap (hbmp) here, however
//    you feel like (e.g. LoadImage)

COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate

// Add the bitmap into the image list
ImageList_AddMucancode.neted(himgl, hbmp, rgbTransparentColor);

 

 

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