Solved

Loading resources and LoadIconEx in visual c++

Posted on 1998-09-29
11
545 Views
Last Modified: 2013-12-14
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
Comment
Question by:Matlock
[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
  • 3
  • 3
11 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173988
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173989
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
 

Author Comment

by:Matlock
ID: 1173990
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
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!

 
LVL 22

Expert Comment

by:nietod
ID: 1173991
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173992
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
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173993
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
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
ID: 1173994
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
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173995
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
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173996
Oops sorry about that - having mouse trouble

Now, you should reject it if that's not satisfactory answer
0
 

Author Comment

by:Matlock
ID: 1173997
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
 

Author Comment

by:Matlock
ID: 1173998
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

737 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