?
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
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 49

Accepted Solution

by:
DanRollins earned 800 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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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