• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 558
  • Last Modified:

Loading resources and LoadIconEx in visual c++

I need to be able to load a resource and use LoadIconEx
with DrawIconEx in visual c++, I know how to do this in
Borland C++ butnot in Visual C++. Help in being able to do
this would be appreciated.
0
Matlock
Asked:
Matlock
  • 5
  • 3
  • 3
1 Solution
 
Answers2000Commented:
There's no LoadIconEx function - you mean LoadIcon

The code is the same for these 2 functions as they are Windows API calls which are the same on both compiles.

Try Giving a more specific explanation of the problem (e.g. is the problem going from OWL to MFC ? or something else)
0
 
nietodCommented:
Code that uses these API functions will be identical between Borland and VC.  You should need no changes at all.  code that uses the OWL library and the MFC library will need extensive changes.  But in that case, you wouldin't be using these functions.
0
 
MatlockAuthor Commented:
Sorry, I guess first of all I need to completely rephrase the question. Again it is an issue of using API and not OWL/MFC/VCL etc.

What I am really looking for is a snippet of code that loads not just an icon but a bitmap and then displays at the most basic of API levels

I mentioned LoadIconEx as I thought it was a new call in WindowsCE that would also load other types of image - I'm probably mistaken

Again any help available as this is another one of my learning windows o/s programming question
Thanks
Matlock
0
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!

 
nietodCommented:
I would use LoadBitmap() for simple tasks.  It you need to load a bitmap image only and the image must be specified in the resources of your EXE or one of the DLLs it uses.

For more power use LoadImage().  It loads icons and cursors as well.  It can loads from a file on disk. (or from resources)  It has options for performing some usefull manipulations on the loaded image.
0
 
nietodCommented:
To display a bitmap, you can use BitBlt() to copy it to a DC in its current dimensions or StretchBlt() to copy it to a DC and scale it to a new size (which ussually looks pretty bad, but sometimes you have to do it.)

Why don't you look at these functions and then ask if you have questions.   (As you can see there are lots of posibilities, and I'm not sure exactly what you need.)
0
 
Answers2000Commented:
There may be a LoadIconEx in Windows CE (I don't have the CE help installed) but there isn't in normal windows

In API to display a bitmap

Say hDCtarget is the HDC or where you want to display

to display bitmap (forgive typos, I'm typing this right in)

HBITMAP hBitmap ;
HDC hDC ;
BITMAP bm ;

hBitmap = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP1) ) ; /* hInst is a parameter in WinMain, IDB_BITMAP1 is the resource id of the bitmap which should be included in your EXE */
GetObject( hBitmap, sizeof bm, &bm ) ;

hDC = CreateCompatibleDC( hDC ) ;
SelectObject( hDC, hBitmap ) ;
BitBlt( hDCtarget, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY ) ; /* an nietod says use StretchBlt if you want to scale the bitmap instead of BitBlt */
DeleteDC( hDC ) ;
DeleteObject( hBitmap ) ;


to display an icon (same assumptions)

HICON hIcon ;

hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_ICON) ) ;
DrawIcon( hDCtarget, 0, 0, hIcon ) ;
DeleteObject( hIcon ) ;

You can also use DrawIconEx instead of DrawIcon


You may also use LoadImage to load from a resource or file.  As this returns handle you need to cast the return value depending on what you're loading

hIcon = (HICON)LoadImage( ...etc... ) ;

or

hBitmap = (HBITMAP)LoadBitmap( ...etc... ) ;
0
 
Answers2000Commented:
There may be a LoadIconEx in Windows CE (I don't have the CE help installed) but there isn't in normal windows

In API to display a bitmap

Say hDCtarget is the HDC or where you want to display

to display bitmap (forgive typos, I'm typing this right in)

HBITMAP hBitmap ;
HDC hDC ;
BITMAP bm ;

hBitmap = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP1) ) ; /* hInst is a parameter in WinMain, IDB_BITMAP1 is the resource id of the bitmap which should be included in your EXE */
GetObject( hBitmap, sizeof bm, &bm ) ;

hDC = CreateCompatibleDC( hDC ) ;
SelectObject( hDC, hBitmap ) ;
BitBlt( hDCtarget, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY ) ; /* an nietod says use StretchBlt if you want to scale the bitmap instead of BitBlt */
DeleteDC( hDC ) ;
DeleteObject( hBitmap ) ;


to display an icon (same assumptions)

HICON hIcon ;

hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_ICON) ) ;
DrawIcon( hDCtarget, 0, 0, hIcon ) ;
DeleteObject( hIcon ) ;

You can also use DrawIconEx instead of DrawIcon


You may also use LoadImage to load from a resource or file.  As this returns handle you need to cast the return value depending on what you're loading

hIcon = (HICON)LoadImage( ...etc... ) ;

or

hBitmap = (HBITMAP)LoadBitmap( ...etc... ) ;
0
 
Answers2000Commented:
There may be a LoadIconEx in Windows CE (I don't have the CE help installed) but there isn't in normal windows

In API to display a bitmap

Say hDCtarget is the HDC or where you want to display

to display bitmap (forgive typos, I'm typing this right in)

HBITMAP hBitmap ;
HDC hDC ;
BITMAP bm ;

hBitmap = LoadBitmap( hInst, MAKEINTRESOURCE(IDB_BITMAP1) ) ; /* hInst is a parameter in WinMain, IDB_BITMAP1 is the resource id of the bitmap which should be included in your EXE */
GetObject( hBitmap, sizeof bm, &bm ) ;

hDC = CreateCompatibleDC( hDC ) ;
SelectObject( hDC, hBitmap ) ;
BitBlt( hDCtarget, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY ) ; /* an nietod says use StretchBlt if you want to scale the bitmap instead of BitBlt */
DeleteDC( hDC ) ;
DeleteObject( hBitmap ) ;


to display an icon (same assumptions)

HICON hIcon ;

hIcon = LoadIcon( hInst, MAKEINTRESOURCE(IDI_ICON) ) ;
DrawIcon( hDCtarget, 0, 0, hIcon ) ;
DeleteObject( hIcon ) ;

You can also use DrawIconEx instead of DrawIcon


You may also use LoadImage to load from a resource or file.  As this returns handle you need to cast the return value depending on what you're loading

hIcon = (HICON)LoadImage( ...etc... ) ;

or

hBitmap = (HBITMAP)LoadBitmap( ...etc... ) ;
0
 
Answers2000Commented:
Oops sorry about that - having mouse trouble

Now, you should reject it if that's not satisfactory answer
0
 
MatlockAuthor Commented:
Thanks
apart from the fact I used nietod's suggestion of LoadImage()
The code you gave me works perfectly and at least I now can
see how HBITMAP and BITMAP work together.
So  all's good except for one very strange anomaly
the Bitmap only appears in the window when I resize the window
over and back where the image should be.
I've accpeted the answer as being spot-on but any suggestions
on how to cure this anomaly would be good
Matlock
0
 
MatlockAuthor Commented:
Apologies
I've found a typo of my own that was causing the strange effect
NOW it works absolutely spot on
Thanks again
Matlock
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now