How to place an image using the SDI application when the dialog box appears for the first time?

advertisements

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

Thanks in advance

Code as I placed in OnInitialUpdate()

void CECUSimulatorView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
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

I removed the code from OnInitialUpdate() and placed it in OnPaint() function as follows:

void CECUSimulatorView::OnPaint() { CPaintDC dc(this); // device context for painting

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

}


Calling LoadImage() in OnInitialUpdate() is ok, the actual painting needs to be done in one of the two following ways:

a) in CECUSimulatorView::OnDraw() -- easier, but may introduce flickering

b) override the OnPaint() function of the m_picture control using ClassWizard and draw the picture there