Solved

Loading resources and LoadIconEx in visual c++

Posted on 1998-09-29
11
532 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embarcadero C++ Builder XE2 TDateTime 8 61
NOTEPAD++ Meaning of (+) and (-) Icons 6 101
Arduino EDI - Programming language 3 79
Syntax Error 2 42
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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
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…
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now