e9404732
asked on
Load file .BMP to my window
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
there is an flag setting to say to load from an external file.
try
image->Pictures->LoadFromF ile(".\\00 1.bmp");
if exist this
image->Pictures->LoadFromF
if exist this
that doesn't sound like MFC or API .. what is it?
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\\mypi c.bmp"
The second problem how do you show the file??????
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\\mypi
The second problem how do you show the file??????
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.
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.
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).
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).
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?
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?
I derive a class from CBitmap and do this...
bool CMyBitmap::LoadBitmapFromF ile(LPCTST R lpszName) {
HINSTANCE hinst = ::AfxGetResourceHandle();
HBITMAP hbitmap = (HBITMAP)::LoadImage(hinst ,lpszName, IMAGE_BITM AP,0,0,LR_ LOADFROMFI LE|LR_CREA TEDIBSECTI ON);
return Attach(hbitmap) != 0;
}
bool CMyBitmap::LoadBitmapFromF
HINSTANCE hinst = ::AfxGetResourceHandle();
HBITMAP hbitmap = (HBITMAP)::LoadImage(hinst
return Attach(hbitmap) != 0;
}
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.
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.