如何在对话框首次出现时使用SDI应用程序放置图像? [英] How to place image using SDI application when the dialog first appears?

查看:72
本文介绍了如何在对话框首次出现时使用SDI应用程序放置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用VC ++中的CFormView类开发基于MFC的SDI应用程序。我的问题是我需要在对话框最初出现时加载图像。如何在SDI应用程序中放置图像..我知道基于对话框的应用程序可以使用OnInitDialog应用程序完成。但对于SDI应用程序,没有这样的功能。我尝试使用OnInitialUpdate()和OnPaint()函数放置图像。但是它失败了......当我第一次出现时,我该怎么做才能将图像置于对话框中?请帮助







Hi all,

I am developing MFC based SDI application using CFormView class in VC++. My problem is that I need to load image when the dialog initially appears. How to place image in an SDI application..I know for dialog based applications it can be done using OnInitDialog application.But for SDI application there is no such function. I tried placing the image using OnInitialUpdate() and OnPaint() function. But it failed..What should I do to place the image to dialog when it first appears? Please Help



// Code as I placed in OnInitialUpdate()

void CECUSimulatorView::OnInitialUpdate()
{
    hBitmap = LoadImage(0,_T("F:/ECUSimulator/ECUSimulator_New/res/LedOff.bmp"), IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    	ImageLoading();
}

// Code for the function ImageLoading()

void CECUSimulatorView::OnInitialUpdate()
{
    HDC hDC, hDCToDisplay = NULL;
    hDC = CreateCompatibleDC(hDCToDisplay);
    SelectObject(hDC,hBitmap);
    hDCToDisplay = ::GetDC(m_picture.m_hWnd);
    m_picture.GetWindowRect(&picRect);
    BitBlt(hDCToDisplay,0 , 0, (picRect.right - picRect.left), (picRect.bottom -picRect.top), hDC, 0 ,0 ,SRCCOPY);
    DeleteDC(hDC);
    DeleteDC(hDCToDisplay);
}

// Here

HANDLE hBitmap; 
CStatic m_picture; //Picture Control 
CRect picRect; //Picture Control Rect



为什么启动时我无法在图片控件中加载图片。请帮助



提前致谢


Why am I not able to load image in picture control during startup.Please help

Thanks in advance

推荐答案

我找到了问题的答案。我使用CBitmap类如下:



CBitmap m_bBitmap1;



在OnInitialUpdate()中我写了如下:



m_bBitmap1.LoadBitmapW(IDB_BITMAP1);



在OnPaint()中我写了如下: br />


m_picture.SetBitmap(m_bBitmap1);



无论何时(其中所有功能)都需要加载图像在相应的函数中调用上面的代码行。
I found the answer for my problem. I used CBitmap class as follows:

CBitmap m_bBitmap1;

In OnInitialUpdate() I wrote as follows :

m_bBitmap1.LoadBitmapW(IDB_BITMAP1);

In OnPaint() I wrote as follows:

m_picture.SetBitmap(m_bBitmap1);

Wherever(In which all functions)need to load image just call the above line of code in corresponding functions..


这篇关于如何在对话框首次出现时使用SDI应用程序放置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆