简体   繁体   English

从头开始创建Visual C ++ MFC项目时如何添加图像?

[英]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 所以

  1. How can I overcome this problem. 我该如何克服这个问题。
  2. How to add the file I needed when I creating the MFC projects form the scratch. 如何从头开始创建MFC项目时添加所需的文件。

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.

相关问题 如何在Visual C ++ 2008中将MFC应用程序项目添加到Win32应用程序项目 - How to add MFC application project to Win32 application project in Visual C++ 2008 如何从Visual Studio 2010中的Visual C ++项目链接到其他版本的MFC? - How can you link to a different version of MFC from a Visual C++ project in Visual Studio 2010? 如何在C ++中向MFC项目添加另一个GUI - How to add another gui to MFC project in C++ C ++ MFC:从Char *创建CString时内存泄漏 - C++ MFC: Memory Leak When Creating CString From Char* 在C ++中从头开始创建DirectDraw Surface - Creating DirectDraw Surface from scratch in c++ 将MFC中的大项目从Visual C ++ 6.0迁移到Visual Studio 2005 - Migrating a big project in MFC from Visual C++ 6.0 to Visual Studio 2005 如何在Visual Studio 2017中创建Visual c ++ MFC控制台项目 - How to create a Visual c++ MFC console project in visual studio 2017 MBCS使用Visual Studio构建MFC C ++项目时出错 - MBCS Error building MFC C++ project with Visual Studio Visual C ++中基于MFC的项目编译错误 - MFC-based project compilation error in Visual C++ 从Visual Studio中的原始C ++代码创建项目时保留原始文件夹结构 - preserving original folder structure when creating a project from original c++ code in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM