How could I insert a bitmap or other image objects in a CListCtrl in MFC? - mfc

I want to list the thumbnails of a set of photos in a listctrl. But the only way to achieve this is to use the setImageList method to bind a image list to the CListCtrl object and insert items like this: InsertItem (int nItem, LPCTSTR lpszitem, int nImage). I also must modify the listctrl's style by ModifyStyle(LVS_TYPEMASK, LVS_ICON) to force it to display the icon of each item.
I don't think this approach a good way to achieve my goal. Can I add items of bitmap or other image objects directly in a CListCtrl?
Thank you very much!

Why do you think it's not a good approach? Your other options are to make it an owner-drawn control and render the images yourself, or use a callback for the images via CListCtrl::SetCallbackMask.
List controls use image lists for a reason; the bitmaps are stored in a way that is most efficient for rendering the list control. You would be pretty hard pressed to do it any better.

Given that you need these sorts of extended features, sounds like you must use owner-draw. A good example is here. It doesn't show how to draw the image, but once you've got the owner-draw procedure set up you should be able to use typical BitBlts to paint the images.

Related

Ownerdraw CListCtrl checkboxes

I want to add checkboxes to my CListCtrl-derived class, that has LVS_OWNERDRAWFIXED-style for drawing them in any subitems. I can draw them simple inside DrawItem member function, but it look a little bit bad. How can I retreive the images of checkboxes, which are used for this control, if the LVS_EX_CHECKBOXES-style is set? It is important, because in each Windows version those checkboxes have its own unique look.
Is it possible?
You call OpenThemeData() to get the current theme's handle and then GetThemeBitmap() to get the images for the checkboxes.
Also have a look at the other GetThemeXXXX() functions to get the correct background
color, text color, font etc.
I also recommend you to play around with ThemeExplorer, it should give you
a great overview how visual styles work. The best thing is, the tools actually uses
OpenThemeData() & co. to render a preview of the controls, so check out its source code (main.cpp, Line 142+) as well!

MFC ribbon large images resource on multiple rows

I'm working on a ribbon application and I need lots of icons for each category. If I put all the images for the category on the same row it becomes too wide, i.e. difficult for maintainance when I need to add/edit something. So my question is: is there a way to put the images on several rows? Thanks!
There is no way to put images on several rows.
The toolbar mode to manipulate tiles of the bitmaps isn't available on demand.
I use a different tool to manage such bitmaps (i.E. Axialis)
Axialis Icon Workshop is a good choice. Try to get the free version somewhere: It has everything you need for ribbon icons, including good alpha channel handling.
If you really insist on using smaller bitmaps, you could use an alternative constructor to associate icons to your UI elements:
CMFCToolBarImages smallerIconGroup; // load some bitmap ressource into this object
...
CMFCRibbonButtonEx myButton = new CMFCRibbonButtonEx(ID_MYCOMMAND, _T("My Button"), smallerIconGroup.ExtractIcon(0));
OK, I saw Axialis. It looks good, but for now I'm sticking to Gimp :D If I see the icons are too much, I'll check the portable version.

what's the best way to display images in qt? also I would like to zoom in to particular areas as well

I've been using label to display images. I'd like to be able to click and create a bounding box then be able to drag the cursor to move around in the image. What would I need to do this? Thanks.
I'm not 100% sure I understand what you are trying to do, but I think the QGraphicsScene is what you are looking for. You can (among many other things):
Render images (QGraphicsPixmapItem, for example)
Change the zoom level when rendering the scene on a QGraphicsView.
Select things using a "rubber band"
Move items around with the mouse (see QGraphicsItem::ItemIsMovable)
etc.
You may need to get familiar with Qt's graphics view framework.

How to display different size images in CListCtrl

In my MFC program,I want to display different size images in a list!
I use CListCtrl and CImageList!
But the CImageList only can load fixed images!
Variable row heights in CListCtrl is not supported. You could take a look at this article that describes a control based on CWnd that handles drawing of variable row heights.
I would consider to use the so called "owner drawn" mode to draw these myself. I don't know about another option (there is no built-in mode)... Maybe you can also take the biggest size and fit the smaller images into the bigger frames but I think it will be the same effort and be less efficient...
I mean use the
CListCtrl::DrawItem()
method
Create a "grid," a non-symmetrical grid most likely, on a dialog or Form. Then populate it with irregular shaped images as you choose. If you need more space look into a Scrollable “whatever,” view, dialog, etc.
Irregular or non rectangular shaped bitmaps seems a good place to start.

Simplest way to change listview and treeview colours

I'm trying to find a simple way to change the colour of the text and background in listview and treeview controls in WTL or plain Win32 code.
I really don't want to have to implement full owner drawing for these controls, simply change the colours used.
I want to make sure that the images are still drawn with proper transparency.
Any suggestions?
Have a look at the following macros:
ListView_SetBkColor
ListView_SetTextColor
TreeView_SetBkColor
TreeView_SetTextColor
There are also appropriate methods of the CListViewCtrl and CTreeViewCtrl wrapper classes:
GetBkColor
SetBkColor
You may also want to take a look at WTL's CCustomDraw::OnItemPrePaint (that's if you need to control the drawing of individual items)
A good article that describes this process is here
It's been a while since I've use the win32 API directly, but I believe that if you handle the WM_ERASEBACKGROUND message for your control, you can use FillRect() in your handler to paint the background using whatever color you like.