Solved

how to load a .jpg from a file name in an ODBC dialog Box connected to an Access database

Posted on 2002-05-11
10
183 Views
Last Modified: 2013-11-20
I have an ODBC dialog based app connected to Access database.Its an app to keep track of customer info and their photo. How can I load the .jpg photo from a seperate directory, say C:\Photos\1234.jpg ? Obviously I want to load the photo of the respective person every time I go to another record in the database...the photo's name is the same as the customers contract number, already stored in a field in the database, so no searching has to be done to find the correct photo...just check the contract number, and load the .jpg with same number.
0
Comment
Question by:pigeonbr
  • 5
  • 5
10 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 7003834
Is your question:  
     "How do I display a jpg file in a dialog box?"

If so, the easiest way might be to add and ActiveX objec that is a WebBrowser.  In OnInitDialog, call its' Navigate fn passing in the path and filename of the JPG file.

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7003854
Here's a link to a CPicture class that wraps IPicture.  You can use it to load and display the JPG file:

http://www.codeguru.com/bitmap/CPicture.html

Here's another one, with an accomanying article:

http://search.microsoft.com/gomsuri.asp?n=1&c=rp_Results&siteid=us/dev&target=http://msdn.microsoft.com/msdn-files/026/002/471/Search.asp

-- Dan
0
 

Author Comment

by:pigeonbr
ID: 7004327
Hi DanRollins;
I've studied these two examples you suggest before..the first one seems te be more what I need...If you have given it a try yourself, maybe you can give me a couple pointers. The code in this first example by Yovav seems to be stand alone...no need to add anything more. When I tried it, I can load the .jpg ok, but when it comes time to display it using the linesm_Picture.UpdateSizeOnDC(&dc);
and then I tried m_Picture.Show(&dc,CRect(0,0,100,100));, changing the coordinates but get nothing on the screen. I tried as well with the CPoint technique. As I said I'm using a Dialog based program, so that's why I need one of these two lines. Can you give me any clues? Is there some other code modification needed to make it work ? Thanks!
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 7004713
Heres' how I tested:

In a Dialog-based app, I added a CStatic control (it's palette tool in in the top right, it looks like a cactus).  I changed its ID from IDC_STATIC to IDST_PicBmp and I set its Type to Bitmaop.  I then used the ClassWizard to create a control-type variable for it named m_ctlPicBmp

These are in my CDialog-derived class def (MyDlg.h):

#include "Picture.h"
... etc ...

CPicture m_cpicCustomer;
HBITMAP  m_hbmpCustomer;

// Dialog Data
     //{{AFX_DATA(CD04Dlg)
     enum { IDD = IDD_MYDLG_DIALOG };
     CStatic     m_ctlPicBmp;
     //}}AFX_DATA

...etc...

This is in my CDialog-derived CPP file:


void CD04Dlg::OnButton1()
{
     m_cpicCustomer.FreePictureData();

     m_cpicCustomer.Load("c:\\temp\\test.jpg" );

     HRESULT hr=     m_cpicCustomer.m_IPicture->get_Handle( (OLE_HANDLE*)&m_hbmpCustomer );

     m_ctlPicBmp.SetBitmap( m_hbmpCustomer );
     m_ctlPicBmp.Invalidate();
}

=-=-=-=-=-=-=-
The technique of using CStatic::SetBitmap() is not well known, but its a great aid for debugging when you just gotta be able to look at a bitmap (otherwise its just a chunk of data that you hope is right).

-- Dan
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7004716
Incidentally, you might consider putting the image data into a BLOB in the database -- rather than saving it as a file.  Take a look at CPicture.Load(szfile).... all it does is load the raw bytes from the file and call LoadPictureData.  Thus, you could read the same data from the database.  That would make the database large, but at least all of the data -- customer info and image -- would all be together.  There would be no separate operation for saving and deleting JPG files.

-- Dan

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:pigeonbr
ID: 7004763
DanRollins:
Thaks for the feedback...I will get back to you in a couple days after I've some time to study and try....but I will get back soon...thanks again!
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7007796
hi pigeonbr,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 

Author Comment

by:pigeonbr
ID: 7009234
Dan;
I am awarding you the points right away...I am not sure when I will be able to get back to you this week...I will give your idea a try...thanks very much for the feedback.
0
 

Author Comment

by:pigeonbr
ID: 7009938
DanRollins;

Had a better look at your code...The CPicture Class in my project does not include FreePictureData() and Load()....
0
 

Author Comment

by:pigeonbr
ID: 7010702
Hi DanRollins;

Got the code working ok this morning...just figured out during the night when you refer to CPicture, you were referring to the the class in one of your comments, from Yovav, which I had already tried....so, It works , but the problem now is to get the piocture down from it's huge to the size I want it...I will play around with that tonight...some combination of using Yovav's class...CRect or CPoint...if you have any insight, please feel free...thanks again...big step forward for me.:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 65
Separate into files by filename 12 75
withoutTen challenge 14 99
Problem to event 3 78
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now