Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Load file .BMP to my window

Posted on 1998-10-22
10
Medium Priority
?
275 Views
Last Modified: 2008-02-01
Can you show me how to load a file .BMP to my program(my window) because LoadBitmap() API function can not load a file .BMP, it is only load a resource file in VC 5.0 ?
0
Comment
Question by:e9404732
[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
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 0 total points
ID: 1175811
use LoadImage instead.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175812
there is an flag setting to say to load from an external file.

0
 

Expert Comment

by:hlava
ID: 1175813
try
  image->Pictures->LoadFromFile(".\\001.bmp");
if exist this
0
Independent Software Vendors: 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 10

Expert Comment

by:RONSLOW
ID: 1175814
that doesn't sound like MFC or API .. what is it?
0
 
LVL 1

Expert Comment

by:andla
ID: 1175815
HANDLE LoadImage(
    HINSTANCE hinst,       // handle of the instance that contains the image
    LPCTSTR lpszName,      // name or identifier of image
    UINT uType,      // type of image
    int cxDesired,      // desired width
    int cyDesired,      // desired height
    UINT fuLoad      // load flags
   );

hinst=0
uLoad=LR_LOADFROMFILE
Windows NT: LR_LOADFROMFILE is not supported.
lpszName="c:\\images\\mypic.bmp"

The second problem how do you show the file??????
0
 
LVL 1

Expert Comment

by:andla
ID: 1175816
uType
Specifies the type of image to be loaded. This parameter can be one of the following values:
Value      Meaning
IMAGE_BITMAP      Loads a bitmap.
IMAGE_CURSOR      Loads a cursor.
IMAGE_ICON      Loads an icon.
0
 
LVL 1

Expert Comment

by:payn
ID: 1175817
I'm not sure if andla's comment was an answer or another question. How do you show the file?

Well, once you've loaded the file, you have a CBitmap. There are many ways to show the file, depending on where you want to show it. In general terms, you're either going to want to select it into a DC, or use SetDIBits (or StretchDIBits if you want to scale it to fit the target window). Is this part of the question? If so, we need more details--unless you're completely lost and want help choosing an implementation (e.g., if you're using a dialog template, place a static control in your template, create a class derived from CStatic that uses LoadImage and calls SetDIBits on WM_PAINT, and attach an object of that class to the control).

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175818
Do you want to know how to display the bitmap as well?
once its into you CBitmap you can do what you want with it (BitBlt to windows etc)
Have you worked out how to load with LoadImage yet?
Or would you like some code?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1175819
I derive a class from CBitmap and do this...
bool CMyBitmap::LoadBitmapFromFile(LPCTSTR lpszName) {
 HINSTANCE hinst = ::AfxGetResourceHandle();
 HBITMAP hbitmap = (HBITMAP)::LoadImage(hinst,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
 return Attach(hbitmap) != 0;
}
0
 
LVL 1

Expert Comment

by:payn
ID: 1175820
I don't have the docs or VC in front of me, but are you sure you need to pass an HINSTANCE when you're loading from file?

But I like the idea of writing a class to wrap the loading code. It may only be a couple of lines, but I always find myself looking up help for LoadImage (or copying and pasting) whenever I need it. It'd be nice if MFC had this built in, of course.

0

Featured Post

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!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.
Suggested Courses

609 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