Solved

How to use LoadBitmap API?

Posted on 1998-12-01
14
458 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 4

Expert Comment

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

Author Comment

by:rosetalk
Comment Utility
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
Comment Utility
>>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
Comment Utility
Are you getting anywhere on this?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:rosetalk
Comment Utility
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
Comment Utility
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
Comment Utility
I mean scrolling the window that contains the bitmap.It does not redisplay DURING scrolling and AFTER scrolling.
0
 

Author Comment

by:rosetalk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now