Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

// Code for the function ImageLoading()

void CECUSimulatorView::OnInitialUpdate()
    HDC hDC, hDCToDisplay = NULL;
    hDC = CreateCompatibleDC(hDCToDisplay);
    hDCToDisplay = ::GetDC(m_picture.m_hWnd);
    BitBlt(hDCToDisplay,0 , 0, (picRect.right - picRect.left), (picRect.bottom, hDC, 0 ,0 ,SRCCOPY);

// 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
Updated 15-Oct-13 3:45am
Richard MacCutchan 15-Oct-13 9:47am    
You should be using the class methods of CFormView to perform these actions. Where exactly are you trying to display this image?
Lekshmi KR 17-Oct-13 0:17am    
I tried using OnPaint(), OnInitialUpdate(), OnDraw() functions.Why it is not working?? What could be the reason.Is there any error in my code?? Please Help me.
Richard MacCutchan 17-Oct-13 2:41am    
Lekshmi KR 17-Oct-13 7:40am    
I dont know which methods are provided by the control..Could you please help me with the code portions??
Richard MacCutchan 17-Oct-13 9:48am    
Did you bother to follow the link I provided above, which even includes all the necessary code?

1 solution

I found the answer for my problem. I used CBitmap class as follows:

CBitmap m_bBitmap1;

In OnInitialUpdate() I wrote as follows :


In OnPaint() I wrote as follows:


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900