Solved

How to use LoadBitmap API?

Posted on 1998-12-01
14
473 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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