- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试将图像添加到工具栏的图像列表中,它是 CMainFrame 的成员
startStopPicture.LoadBitmapW(IDB_STOP_PIC);
m_ToolBar.GetToolBarCtrl().GetImageList()->Add(&startStopPicture, reinterpret_cast<CBitmap*>(NULL));
startStopPicture.DeleteObject();
startStopPicture.LoadBitmapW(IDB_START_PIC);
m_ToolBar.GetToolBarCtrl().GetImageList()->Add(&startStopPicture, reinterpret_cast<CBitmap*>(NULL));
然后我需要从 subview 访问这个图像列表。我正在尝试这样做
CMainFrame* mainFrame = dynamic_cast<CMainFrame*>(GetParentFrame());
CImageList* imList = mainFrame->m_ToolBar.GetToolBarCtrl().GetImageList();
但是我在主机方法中添加的那些图像现在不存在了。如何解决这个问题?
最佳答案
我假设你的 CBitmap
startStopPicture
是一个局部变量,因为您既没有另外提及,也没有在变量名前面加上任何类标识符。之后您尝试通过 CImageList::Add
存储引用的局部变量。
您需要做的是分配 CBitmap
- new CBitmap
或添加 startStopPicture
作为成员添加到您的类(class)的变量。
如果您选择分配变量并且不必跟踪 CBitmap
, 你可以使用 std::vector<std::unique_ptr<CBitmap> >
作为类(class)成员。
如果你存储一个局部变量 CBitmap
在 CImageList
, 图像将不会显示。
例子:
//class declaration
private:
std::vector<std::unique_ptr<CBitmap> > m_vLoadedBitmaps;
};
void CMyCtrl::SetBitmaps(CImageList &imgList)
{
CBitmap *bmpDelete = new CBitmap();
bmpDelete->LoadBitmapW(IDB_DELETE);
m_vLoadedBitmaps.push_back(std::unique_ptr<CBitmap>(bmpDelete));
imgList.Add(bmpDelete, static_cast<CBitmap*>(NULL));
}
我还建议在变量的所有者类中加载图像。如果需要,还有 SendMessage
.
关于c++ - MFC : accessing CMainFrame's CImageList from ChildView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31950063/
如何检测“空”CMainFrame 鼠标点击?空我的意思是一个还没有任何文档/ View 的 MDI。 我试图用以下方法检测鼠标点击: afx_msg void OnLButtonDown(UI
此代码在 Visual C++ 6.0 下运行: BOOL CSplashWnd::PreTranslateAppMessage(MSG *pMsg) { if (c_pSplashWnd =
当使用 VS2008(加上功能包)的 AppWizard 创建具有“Visual Studio”风格的 MDI 应用程序时,CMainFrame 类获得一个方法 CreateDockingWindow
我有以下代码: CMainFrame* pFrame = new CMainFrame; if (!pFrame) return FALSE; m_pMainWnd = pFrame; //
我正在尝试将图像添加到工具栏的图像列表中,它是 CMainFrame 的成员 startStopPicture.LoadBitmapW(IDB_STOP_PIC); m_ToolBar.GetTool
我在 MFC 中有一个 MDI 应用程序要修改。我想检查一个标志的值,它是来自较低级别类的 MainFrm 的成员变量。但我不想使用它来访问它'((CMainFrame*) AfxGetMainWnd
我正在使用 MFC 并有一个主框架,它从工具栏接收 WM_PASTE、WM_COPY 消息等。我想要做的是将此消息传递给具有焦点的 CPaneDialog,因为这是我希望我粘贴的文本去的地方。 我已经
我有一个对话框资源,里面有一些控件,主要是用户和密码编辑控件,绑定(bind)到 CFormView。这样的对话框是一个 300 x 200 像素的小矩形。 当我运行应用程序时,CFrameWindo
我是一名优秀的程序员,十分优秀!