Frequently Asked Questions > How do I handle Pictures in VSFlexGrid when using C++? |
If you are using MFC, the best way is to use MFC's CPictureHolder class. Here's an example that shows how you can set the VSFlexGrid's CellPicture property (or any other ActiveX Picture property) from C++:
Using the AppWizard, generate a new project with as a dialog-based app with the OLE controls option set to True.
Add a VSFlexGrid control to the form and connect it to the m_flex member variable.
Add a bitmap resource and set its ID to IDB_ARROWPIC.
Add the following handler for the m_flex Click event:
Example Title |
Copy Code
|
---|---|
// include MFC header that declares the CPictureHolder class, which // is the easiest way to deal with OLE-based pictures #include "afxctl.h" // this is the click event handler, and also the only custom function in this project void CTestCDlg::OnClickFlex() { // Create a CPictureHolder variable that will hold the picture. // (For details, see the ctlPict.cpp file in your MFC\SRC directory.) CPictureHolder pic; // Initialize the picture holder by giving it a picture to hold. // In this case, we're giving it the resource ID of a bitmap, but // CPictureHolder can also handle icons and metafiles. pic.CreateFromBitmap(IDB_ARROWPIC); // Tell the control to show the picture. Because we're handling // a click event, the row and column have already been selected. m_flex.SetCellPicture(pic.GetPictureDispatch()); } |
If you are not using MFC, refer to the Using VSFlexGrid in Visual C++ topic in the documentation. It shows how you can use pictures without MFC support and much more.