Load image using CVOImage class

CVOImage image;
RECT pic_rect;
     
// The display window RECT

m_pic.GetWindowRect(&pic_rect);

// The HDC of the display window

HDC picDC = ::GetDC(m_pic.m_hWnd );

CString path = _T("\\My Documents\\");
CString image_name = "ok.jpg";
   
CString path_fname = path + image_name;
image.Load (picDC ,path_fname );    
image.Draw (picDC ,0,0, pic_rect.bottom, pic_rect.right);//width, height
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I am using eVC to program.

I used CVOImage which is a free class which I get from here to load a image from file regardless of format.

http://www.voscorp.com/products/developer/winmobile/voimage/

What is wrong with my above code??? I have no error and the file path is right. Why do my picture cannot be display??? My m_pic is a group box which I map it to a CButton control in AppWaizrd. Please help me take a look please.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

If this cannot be solved, how do I load a image based on its file driectory to pocketPC regardless of its format. Because I need to load format like jpg, bmp, gif etc.
Kenji85Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nabehsCommented:
should pic_rect.bottom and pic_rect.right reversed?

image.Draw (picDC ,0,0, pic_rect.bottom, pic_rect.right);//width, height

It should be:

image.Draw(picDC, 0, 0, pic_rect.right, pic_rect.bottom);//width, height
nabehsCommented:
also, u r assuming that pic_rect.right is the width. this is correct if pic_rect.left is equal to zero. always use

image.Draw(picDC, 0, 0, pic_rect.right - pic_rect.left, pic_rect.bottom - pic_rect.top);

or another solution is to replace

m_pic.GetWindowRect(&pic_rect);

with

m_pic.GetClientRect(&pic_rect);
Kenji85Author Commented:
Oh yar is my fault...

But then after I changed it, it still look the same, it doesn't seem to draw the image.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Kenji85Author Commented:
tried ur code above, but still it doesn't seem to draw.... what actually is wrong??? or is it my m_pic problem????
nabehsCommented:
1. try to override the OnPaint method of the CButton groupbox and place this code inside it and see if it draws.

2. try to load a bitmap (.bmp) instead of (.jpg) and see if it draws


nabehsCommented:
to override the OnPaint of CButton class:

1. From the class wizard, add new class, MFC class, named CPicButton derived from CButton
2. Replace the data member declaration of CButton m_pic; with CPicButton m_pic; // include "picbutton.h"
3. From the class wizard, override WM_PAINT message for CPicButton
4. Inside the OnPaint

void CPicButton::OnPaint()
{
    CPaintDC dc(this);

      CVOImage image;
      RECT pic_rect;
     
      // The display window RECT

      GetClientRect(&pic_rect);

      // The HDC of the display window

      HDC picDC = dc.GetSafeHdc();

      CString path = _T("C:\\Windows\\");
      CString image_name = "Greenstone.bmp";
   
      CString path_fname = path + image_name;
      image.Load (picDC ,path_fname );    
      image.Draw (picDC ,0,0, pic_rect.right, pic_rect.bottom);//width, height
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kenji85Author Commented:
Yes, it worked very well ! ! !

How come it work in this manner??? It seem to be no much different, can kindly explain???
nabehsCommented:
it seems u r painting the groupbox at load time, when the form appears, it calls the paint handler of CButton class and repaints the groupbox. So OnPaint of CButton occurs after u paint the image.
Kenji85Author Commented:
So now I need to set the path of the image from database, where do I go in and search my database for the image path???
In CPicButton Class which handler should I use????
nabehsCommented:
1. Add a member variable m_strPath inside CPicButton class
2. Add a public member function SetImagePath inside CPicButton class
void CPicButton::SetImagePath(LPCTSTR szImagePath)
{
    m_strPath = szImagePath;
    Invalidate();
}

3. Modify OnPaint of CPicButton as follows:
void CPicButton::OnPaint()
{
    CPaintDC dc(this);

     CVOImage image;
     RECT pic_rect;
     
     // The display window RECT

     GetClientRect(&pic_rect);

     // The HDC of the display window

     HDC picDC = dc.GetSafeHdc();

     image.Load (picDC , m_strPath );    
     image.Draw (picDC ,0,0, pic_rect.right, pic_rect.bottom);//width, height
}

4. Inside the OnInitDialog of your dialog that contains the CPicButton find the image path and call SetImagePath:

m_pic.SetImagePath(the_found_path);


Kenji85Author Commented:
Ya, it work really well, thankx a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.