Solved

Loading resources and LoadIconEx in visual c++

Posted on 1998-09-29
11
547 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
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 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

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!

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
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…

729 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