[英]How to add images when creating Visual C++ MFC project from scratch?
I am try to create very simple c++ MFC project. 我尝试创建一个非常简单的c ++ MFC项目。 Since it is very simple one I need to create it form scratch.
由于它非常简单,因此我需要从头开始创建它。
my code so far is shown below. 到目前为止,我的代码如下所示。 But now I need to add picture control and thus my Intent use CImage class.
但是现在我需要添加图片控件,因此我的Intent使用CImage类。 But to use CImage class I need to add altimage.h header to my project.
但是要使用CImage类,我需要向项目添加altimage.h标头。 But When I do so it gives a error that cannot open source file altimage.h.
但是,当我这样做时,它给出了无法打开源文件altimage.h的错误。 So
所以
please help me solvethis. 请帮我解决这个问题。
thanks 谢谢
#include <afxwin.h> //MFC core and standard components
//#include <altimage>
#include "resource.h" //main symbols
//-----------------------------------------------------------------------------------------
//Globals
//CEdit * TEST;
CEdit * RECOG_CHARS;
CButton * BTN_CONVERT;
CButton * BTN_QUIT;
CStatic * IMG_IMAGE;
class HWCR_FORM : public CDialog
{
public:
HWCR_FORM(CWnd* pParent = NULL) : CDialog(HWCR_FORM::IDD, pParent)
{ }
// Dialog Data, name of dialog form
enum{ IDD = ID_MAIN_INTERFACE };
protected:
virtual void DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); }
//Called right after constructor. Initialize things here.
virtual BOOL OnInitDialog()
{
CDialog::OnInitDialog();
RECOG_CHARS = (CEdit *)GetDlgItem(CE_ID_TEXT);
BTN_CONVERT = (CButton *)GetDlgItem(CB_ID_START);
BTN_QUIT = (CButton *)GetDlgItem(CB_ID_QUIT);
IMG_IMAGE = (CStatic *)GetDlgItem(CS_ID_IMAGE);
HBITMAP image = (HBITMAP)LoadImage(NULL,L"C:\\Users\\Kasun\\Desktop\\image.bmp",IMAGE_BITMAP,150,120,LR_LOADFROMFILE);
IMG_IMAGE->SetBitmap(image);
RECOG_CHARS->SetWindowTextW(L"Hi there");
return true;
}
public:
DECLARE_MESSAGE_MAP()
};
//-----------------------------------------------------------------------------------------
class HWCR : public CWinApp
{
public:
HWCR() { }
public:
virtual BOOL InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(_T("Hills Of Darkness"));
HWCR_FORM dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
return FALSE;
} //close function
};
//-----------------------------------------------------------------------------------------
//Need a Message Map Macro for both CDialog and CWinApp
BEGIN_MESSAGE_MAP(HWCR_FORM, CDialog)
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------------------
HWCR theApp;
First at all, in order to use CImage
, you need to include header file 首先,要使用
CImage
,您需要包含头文件
#include <atlimage.h>
instead of 代替
#include <altimage>
Secondly, be sure that this file's directory is included into MSVC paths... Normally it should be included as this header file is part of MFC / Win32 SDK....check the directories in VS properties. 其次,确保此文件的目录包含在MSVC路径中...通常应包含此文件,因为此头文件是MFC / Win32 SDK的一部分。...检查VS属性中的目录。
Z. Z.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.