Use CListCtrl CImageList to display images in MFC ADO

Source: Internet
Author: User

The work of saving the ADO images under MFC to the database these days is indeed complicated, but there are many functions. This method should be applicable to most VC, unconfirmed!

1. How do I save images to the database?

Create an access database, design a table, and create a new one to store image data.

You must select an OLE object instead of a remark.

We can see that the stored image data is a binary-length data, and you cannot see it ~

What, you still cannot write image data into the database? According to my excerpt, the excerpt was not long ago. Note: Use the shortest method instead of dropping one pixel or one pixel. As for reading, the same reference is also made. Http://blog.csdn.net/guoming0000/article/details/7301517

2. I use VS2010 and advanced tools. Naturally, there is a simple way to display images.

The following two types of display effects are displayed through two controls. You need to have a few MFC basics for the following tutorial. (The control cannot be found? The Control ID is unknown? Do not understand control variables ?)

(1) Use the CPictureCtrl control of MFC to display the image. I have already written it. Here I will connect MFC_CImage.

(2) Use the CListCtrl and CImageList of MFC to display the results first (click the button in the upper left corner to see the results ):

The picture here is drawn by myself using code. That is to say, any picture can be displayed dynamically, instead of assuming resources when the project is created. The MFC project resource link will be provided later, and it is free of charge. In this way, we can display a person's portrait or other images to listctrl, and display as many images as possible. You can view all the images through the scroll bar. This effect is not very brilliant. Unfortunately, I found this method after Baidu for more than a day. Many articles have mentioned that it is a bit of a piece of cake, and the result of their installation cannot be displayed. The important parts are as follows:

First, the CBitmap creation code is similar to the following:

Unsigned char pData [100*100*4]; BITMAP BitMap; BitMap. bmType = 0; BitMap. bmHeight = 100; BitMap. bmWidth = 100; BitMap. bmWidthBytes = 100*4; // BitMap greater than or equal to bmWidth * bmBitsPixel/8. bmPlanes = 1; BitMap. bmBitsPixel = 32; BitMap. bmBits = pData; for (int I = 0; I <100; I ++) for (int j = 0; j <100; j ++) {pData [I * 100*4 + j * 4] = 100 + j * 3; pData [I * 100*4 + j * 4 + 1] = 130 + I; pData [I * 100*4 + j * 4 + 2] = I * 2 + j + 50;} CBitmap cb; cb. createBitmapIndirect (& BitMap );

We can see that all data is assigned by ourselves, so we can pass other images into the Cbitmap structure as well. Note that the BITMAP structure data here is 32-bit. When we use a realistic grayscale image, you know that the first three components are set to the same value. As for why 24bit and 8bit are not used, because I did not show them successfully. What we want is the effect, instead of saving memory. Such a small image cannot occupy much. I am also worried about whether it will involve complex issues such as the color palette, so the images are converted into 32-bit display! The most important thing is to load it to CImageList. The Code is as follows:

CImageList a;a.Create(100,100, ILC_COLOR32 |ILC_MASK , 8, 1);a.Add(&cb,RGB(0,0, 0));a.Add(&cb,RGB(255,255, 255));a.Add(&cb,RGB(255,255, 255));a.Add(&cb,RGB(255,255, 255));a.Add(&cb,RGB(255,255, 255));m_ListCtrl.SetImageList(&a,LVSIL_NORMAL);CString strTemp;for (int n = 0; n < 5; n++) {strTemp.Format(_T("pic:%d"),n);m_ListCtrl.InsertItem(n,strTemp, n);}a.Detach();

M_ListCtrl is the control variable of the list control CListCtrl, which should be created without reference.

The most important thing is the last line: a. Detach (). Once upon a while, I tried to find this statement and couldn't help it at night. Without this sentence, it cannot be displayed in the control, but most online tutorials lack this sentence, maybe it is different from vc6.0.

Today, we found that no Detach is required !!! , It seems that the operation with CImageList is really not familiar.

 

To be honest, MFC is hard to learn. I guess it won't take too long to transfer it to other C ++ guis.


I am a VS2010 Project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.