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
180 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 74
sum28 challenge 31 96
Fibonacci challenge 11 84
Problem to open Excel file 15 43
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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

20 Experts available now in Live!

Get 1:1 Help Now