?
Solved

Icons and Cursors

Posted on 2006-04-29
23
Medium Priority
?
387 Views
Last Modified: 2012-08-13
Alright, I have a window all set up with CreateWindow using VC++ 6.  However, I can not get
LoadImage to load icons and cursors.  Can someone please tell me how I can get a type of walkthrough?
By this I mean not only code, but how to create the icons to work with the code as well?
0
Comment
Question by:List244
  • 11
  • 11
23 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 16569871
You'd do that like

HCURSOR hCur = LoadCursor(hMyInstance,MAKEINTRESOURCE(ID_MYCURSOR));

>>By this I mean not only code, but how to create the icons to work with the code as well?

That is done best in the resource editor. Go to 'Add Resource' and choose 'Cursor'.

0
 
LVL 8

Expert Comment

by:mrblue
ID: 16569947
To draw icon you can use:
DrawIcon(hDC, X, Y, hIcon);
0
 
LVL 8

Author Comment

by:List244
ID: 16569977
JKR, I do not know what you mean by "Go to 'Add Resource'"

But I have done the following:

File-> New -> Resource Script

Add Cursor...

RegW.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1)); //Undeclared Identifier IDC_CURSOR1

and IDC_CURSOR1 is its name.

MrBlue, I am looking for something around the lines of:

      RegW.hIcon = LoadIcon(NULL,IDI_APPLICATION); //Custom..
      RegW.hIconSm = LoadIcon(NULL,IDI_WINLOGO); //Custom..

Rather than the defaults.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:mrblue
ID: 16570084
"Undeclared Identifier IDC_CURSOR1"

Add

#include "resource.h"
0
 
LVL 8

Author Comment

by:List244
ID: 16570089
I don't have a resource.h.
0
 
LVL 8

Author Comment

by:List244
ID: 16570096
Okay, sorry that was the wrong project.  Okay, this works, but it still is not loading my cursor.
It is loading an uparrow (No matter what naming).
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570173
Is RegW in RegW.hCursor struct of type WNDCLASS passed to RegisterClass() function ?
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570205
If not you need handle WM_SETCURSOR message and call
SetCursor(RegW.hCursor);
0
 
LVL 8

Author Comment

by:List244
ID: 16570214
WNDCLASSEX RegisterClassEx
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570393
Check if "LoadCursor()" returns value != NULL
How did you get "hInstance" ? Is it NULL ?
0
 
LVL 8

Author Comment

by:List244
ID: 16570408
Ah, forgot to switch hInstance, that solved that.

What about the icons, how do I get those working? (Small and large)
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570417
Do you mean title bar or drawing on window ?
By the way use also MAKEINTRESOURCE() also in LoadIcon()
0
 
LVL 8

Author Comment

by:List244
ID: 16570419
I mean both for titlebar and for the application icon.
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570423
...when you pass your own icon ID.
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570428
    RegW.hIcon = LoadIcon(NULL,IDI_APPLICATION); //Custom..
     RegW.hIconSm = LoadIcon(NULL,IDI_WINLOGO); //Custom..

Doesn't it work ? Or you want your own icons ?
0
 
LVL 8

Author Comment

by:List244
ID: 16570432
Okay, I got this working, cursor and icon, one question though.. Is the title-bar icon not supposed to be 16X16?
I can only get the 32x32 to work for that.
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570449
You can add 16x16 icon to your 32x32 one.

In resource editor you have:

Device: [Standard (32x32)] [button]

Click on that button & add "Small (16x16)"
0
 
LVL 8

Author Comment

by:List244
ID: 16570455
I have done this, but when I can not get it to use the 16X16, it always uses the 32X32
0
 
LVL 8

Author Comment

by:List244
ID: 16570461
I would like hIconSm to use the 16
0
 
LVL 8

Accepted Solution

by:
mrblue earned 1600 total points
ID: 16570466
Try set
RegW.hIconSm = NULL;
&
RegW.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ID_NORM_SMALL_ICON /*your ID of course*/))
0
 
LVL 8

Author Comment

by:List244
ID: 16570475
Works great, thanks.
0
 
LVL 8

Expert Comment

by:mrblue
ID: 16570484
MSDN suggests LoadImage(). Maybe here's the problem (not sure).

LRegW.hIcon = oadImage(hInst, MAKEINTRESOURCE(ID_*), IMAGE_ICON, 16, 16, 0);
0
 
LVL 8

Author Comment

by:List244
ID: 16570520
Both methods work well.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

850 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