Loading icons

I'm trying simply to set a custom icon.

I've tried...

wc.hIcon = LoadIcon(hInstance, TEXT("C:/Documents and Settings/Richard/test.bmp"));

and

wc.hIcon = HICON(LoadImage(hInstance, TEXT("C:/Documents and Settings/Richard/test.bmp"), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));

...and a few other things that are simply minor edits to these two lines.

So far no errors, but I just can't get the icon to work. It just stays the default icon.

As you can probably tell from the numerous improper techniques used here, that I'm new to the Windows API and am just learning it. So any other pointers are appreciated.

OH! And I had another question and I might as well throw it here rather than use another post.

I have to typecast using TEXT() alot. I constantly receive the error that the compiler
cannot convert parameter 2 from 'const char [43]' to 'LPCWSTR'
. This is whenever I use a string in a function as a parameter (such as the LoadIcon function above). I think that simply storing every string of text I wish to use in a function in a LPCWSTR variable might work, but would take up a LOT of memory. Maybe new could work...Okay, now I'm just rambling off...

Any help?

Thanks,
SCP
You have to use ressources. E.g.
1
2
3
4
5
6
7
8
9
10
//file res.h
#define MyIcon 110

// file res.rc
#include "res.h"
MyIcon ICON "C:/Documents and Settings/Richard/test.bmp"

//file main.c
#include "res.h"
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MyIcon));

The same procedure with LoadImage, which maybe should be you favoured choice.
Last edited on
Thank you for the help jmc!

I did exactly as you said, but unfortunately, I came up with some errors.

For this line(line 33):
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MyIcon));
I'm getting multiple instances of these errors:
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2059: syntax error : ')'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2059: syntax error : ')'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2059: syntax error : ')'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2059: syntax error : ')'
c:\documents and settings\richard\my documents\visual studio 2008\projects\lesson 1\lesson 1\main.cpp(33) : error C2059: syntax error : ')'


Can you tell what went wrong?

Thanks,
SCP
It seems like you have too little )s in some places and too many in others...maybe you typoed it like this:

wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MyIcon);)
Topic archived. No new replies allowed.