0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You follow the steps and see if the things works and in MFC take one step at a time as that will help you know what the prob is. You will not be able to make a very good app with the hello world but slowly you will be.

1. Take a Dialog based application.
2. Declare a varible in the Dialog header class as HANDLE m_hBmp.
3. Go to the OnInitDialog and add the following line at the last
Code:
m_hBmp = ::LoadImage(NULL,"E:\\flowers.bmp",IMAGE_BITMAP,NULL,NULL,LR_LOADFROMFILE|LR_DEFAULT  SIZE);
Remember to put the correct bmp file path.
4. Now put the following in the OnPaint method
Code:
CDC dcSrc;
dcSrc.CreateCompatibleDC(NULL);
dcSrc.SelectObject(m_hBmp);
dc.StretchBlt(0,0,100,100,&dcSrc,0,0,100,100,SRCCOPY);
above the CDialog::OnPaint() and comment out the CDialog::OnPaint. Also rememeber its in the else part of the IsIconic part.

See if it works.

Now substitute your code slowly into the working app and find where is the prob.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
Dude, I did all of the above. As I said, your example app still didn't work.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Then probably you need an error issue as the steps I wrote is done by me and its working.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
You're probably right. Thanks for your help anyway.
0
rcook's Avatar, Join Date: Jan 2007
Newbie Member
Look, I'm fairly new at this, but are you sure SelectObject is not supposed to be returning NULL? According to my docs, it returns the handle of whatever was selected before, and if that was nothing, then NULL might be reasonable. According to what I'm reading, it isn't supposed to be a valid handle, necessarily.

And whether or not that works, can you tell me where LR_LOADFROMFILE is defined? I can't find it anywhere.

rc
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
SlectObject should return the default bitmap initialized for the DC. If I'm wrong then I really don't know what's failing, because the bitmaps aren't getting displayed.

LR_LOADFROMFILE is defined in winuser.h, but including windows.h will include it too.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
OK!! After much frustration I found the real problem. The object containing the image is allocated like so:

Code:
menu_items.push_back (MenuItem (OLE2T (i_bmpsrc.bstrVal), OLE2T (i_mnustr.bstrVal), OLE2T (i_cmdstr1.bstrVal), OLE2T (i_cmdstr2.bstrVal)));
(where menu_items is a vector and the parameters are read in from an XML file).

MenuItem has a destructor lwith the following line:

Code:
DeleteObject (mnubmp);
The problem is that as soon as the anonymous MenuItem goes out of scope (at the right parens), although the object continues to exist (because of the copy in menu_items), the destructor is called. I know this because a MessageBox put into the destructor executes at that point.

However, now that I've found the problem I don't know what to do about it. The push_back is called in a function that returns as soon as the XML parser is cleaned up, so the argument to push_back will necessarily go out of scope.