VSFlexGrid Tutorials > Visual C++ MFC Demo > Step 8: Cell Pictures |
The final step shows how you can add cell pictures using C++.
First of all, you need to use the VC++ resource editor and add two bitmap resources to the project. Make the bitmaps approximately 15 by 15 pixels in size and name them IDB_FILE and IDB_SECTION.
Then, make the following changes to the AddNode routine (the changes are marked in boldface):
Example Title |
Copy Code
|
---|---|
#include void COutlineCDlg::AddNode(LPSTR inifile) { long row; // initialize pictures CPictureHolder picFile, picSection; picFile.CreateFromBitmap(IDB_FILE); picSection.CreateFromBitmap(IDB_SECTION); // initialize variant to use as optional parameter … // create file node … m_fg.SetCellFontBold(TRUE); LPDISPATCH pPic = picFile.GetPictureDispatch(); m_fg.SetCellPicture(pPic); pPic->Release(); // read ini file … // if this is a section, add section node … m_fg.SetCellFontBold(TRUE); m_fg.SetCellPicture(picSection.GetPictureDispatch()); // if this is regular data, add branch … } if (f) fclose(f); } |
The first line added includes the MFC header file afxctl.h. This file defines CPictureHolder, a handy class for manipulating OLE pictures. The next three lines added declare a CPictureHolder variable for each bitmap, and load the bitmaps using the CreateFromBitmap method.
Finally, the SetCellPicture method is used to assign the pictures to cells that are file and section nodes.
This concludes this demo. Run the project once again to see the final result.