微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 C++ 在 MFC 对话框中显示位图图像

如何解决使用 C++ 在 MFC 对话框中显示位图图像

这是我的代码

void CChildView::OnPaint() 
{
    CBitmap BmpLady;
    // Load the bitmap from the resource
    BmpLady.LoadBitmap(IDB_BITMAP1);

    CPaintDC dc(this);
    CDC MemDCLady;

    // Create a memory device compatible with the above CPaintDC variable
    MemDCLady.CreateCompatibleDC(&dc);
    // Select the new bitmap
    //CBitmap *BmpPrevIoUs = MemDCLady.SelectObject(&BmpLady);
    MemDCLady.SelectObject(&BmpLady);
    // copy the bits from the memory DC into the current dc
    dc.BitBlt(0,426,640,&MemDCLady,SRCcopY);
}

当我按 F5 时,应用程序正在运行,但对话框中没有显示图像。我是 MFC 的新手,所以任何帮助将不胜感激。有谁知道我的代码有什么问题? 提前致谢。

注意:我在 Visual Studio 2019 中工作

SlidingPuzzleNWP.rc:

// remains consistent on all systems.
IDR_MAINFRAME           ICON                    "res\\SlidingPuzzleNWP.ico"


/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//

IDR_MAINFRAME           BITMAP                  "res\\Toolbar.bmp"

IDB_BITMAP1             BITMAP                  "res\\slika_za_rad.bmp"

IDB_BITMAP2             BITMAP                  "res\\tito.bmp"

资源.h:

// Microsoft Visual C++ generated include file.
// Used by SlidingPuzzleNWP.rc
//
#define IDD_ABOUTBox                    100
#define IDR_MAINFRAME                   128
#define IDR_SlidingPuzzleNWPTYPE        130
#define IDB_BITMAP1                     310
#define IDB_BITMAP2                     311

// Next default values for new objects
// 
#ifdef APSTUdio_INVOKED
#ifndef APSTUdio_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        312
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           310
#endif
#endif

Childview.cpp:

// ChildView.cpp : implementation of the CChildView class
//

#include "pch.h"
#include "framework.h"
#include "SlidingPuzzleNWP.h"
#include "ChildView.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。