Solved

How to use LoadBitmap API?

Posted on 1998-12-01
14
469 Views
Last Modified: 2008-02-01

I have downloaded a file from "www.codeguru.com/dialog "under the section list of Image Preview by luis Otega. This file only opens a dialog with a bitmap preview without loading a bitmap. My question is how to implement the LoadBitmap API into the file. What are the parameters to pass to the LoadBitmap function based on his code? Is the LoadBitmap API enough to load the bitmap file that is selected? If not, what else do I need to include?

I would also like to get the filepath of the file selected. I know I need to use the GetPathName function. But how to use it in his file. I have post my questions to the author and yet to hear from him.

Please help me, if you have time to look at his code. It is quite a short one.

From: A Beginner
0
Comment
Question by:rosetalk
  • 7
  • 5
  • 2
14 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 1178942
Are you using Visual C++ with MFC or just SDK.
With loadbitmap, you load a bitmap resource. You are returned a bitmap handle. The next step is to create a compatible device context with the client device context with the CreateCompatibleDC function. Next is to select the bitmap handle into this device context. After this use the BitBlt() or related functions to draw the bitmap on the display.
Hope this helps.
Thanks
pagladasu
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1178943
LoadBitMap() is not the function you want.  It only loads bitmaps that are in your program or DLL's resources.  You want to use LoadImage().
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178944
Like LoadBitmap(), LoadImage() can load from the resources, but it can also load from a file on disk.  It also can load cursors and icons as well as bitmaps.  So there are lots of options to use it.  But to load a bitmap from a file on disk, specify:

NULL for the hinst parameter.
Specify the file name for the 2nd parameter
Specify IMAGE_BITMAP for the 3rd parameter
Specify the desired width or 0 for the actuall width of the image in the 4th parameter.
Specify the desired height or 0 for the actual height of the image in the 5th parameter.
Specify LR_LOADFROMFILE in the 6th parameter.

Now this creates a device dependant bitmap that is compatible with the display (screen).  (Which is what LoadBitmap() always does)  If you want to create a device independant bitmap you can use the LR_CREATEDIBSECTION flag as well in the last parameter.

Let me know if you have questions.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 4

Expert Comment

by:pagladasu
ID: 1178945
Neitod is right. For loading files, you need LoadImage(0
0
 

Author Comment

by:rosetalk
ID: 1178946
Neitod,
         I have tried your method to use LoadImage(). However, I there is nothing loaded on the client area.I have noticed that the author uses CBmpDialog::hpreview = (HBITMAP)LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); with these parameters as well to load the image on the preview screen and it works. I uses his parameters and nothing is loaded on the client area as well. I am using MFC with SDK. What could be wrong? The arthor uses hook function in his implementation. Please try out his dialog box if you have time.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178947
>>I would also like to get the filepath of the file selected. I know
>> I need to use the GetPathName function

GetPathName() retirns the name of the file selected by the user.  If you want to load that file, you specify that name to LoadImage().

>> I have tried your method to use LoadImage(). However, I there is
>>nothing loaded on the client area
An image can't be "loaded on the client area".  It is just loaded into memory.  From there it can be copied to a a device context to display the image on the screen or on a printer or other hardware device.  Take a look at codeguru's examples about displaying bitmaps.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178948
Are you getting anywhere on this?
0
 

Author Comment

by:rosetalk
ID: 1178949
Yes, I manage to contact the author and I am glad that the problem is solved. Anyway, thank for your help. Nietod... But when the picture is loaded, its seems like the screen doest not refresh when I am scrolling. What should I do if let say execute the OnDraw() function to draw the image while scrolling? If the methed is not right, can you give me suggestions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178950
Do you mean it does not redisplay DURING scrolling or AFTER scrolling?  (I.e after scrolling ends (after the user releases the mouse) does it then look okay?)  

What is scrolling?  Are you scrolling the window that contains the bitmap, or are you scrolling a window that contains a window that has the bitmap.



0
 

Author Comment

by:rosetalk
ID: 1178951
I mean scrolling the window that contains the bitmap.It does not redisplay DURING scrolling and AFTER scrolling.
0
 

Author Comment

by:rosetalk
ID: 1178952
Inaddition, I have to add a refresh button on the toolbar inorder to execute the OnDraw function under View class. This will refresh the distorted image after scrolling.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178953
Since you are using MFC, I'm not exactly sure what you should be doing to handle scrolling.  In the Non-MFC world, during the WM_xSCROLL message you would use ScrollWindowEx() to scroll part of the window that is displayed into its new position.  This will invalidate the part of the window that should contain the part that is scrolled into view (the part that wasn't vissible before).  Then a call to UpdateWindow() will redisplay that part.  In MFC, I suspect most of that is taking care of for you.  I would bet that MFC handles the ScrollWindowEx call and that all you would have to do is to repaint your window in onDraw.  but I'm not sure.  However, when you draw in the OnDraw function, your probably have to take the scroll bar position into account and draw the image at the right location.  Are you doing that?
0
 

Author Comment

by:rosetalk
ID: 1178954
Yes, I taken care of that but it doesn't seems to work either. Are you free to have a look at my program?  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1178955
You can e-mail it to me at nietod@theshop.net.  But as I don't use MFC (I know a little) I may not be able to help.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

776 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