Solved

How to use LoadBitmap API?

Posted on 1998-12-01
14
484 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
[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
  • 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
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!

 
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

Industry Leaders: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

732 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