Advertisement

Resource problem

Started by July 03, 2000 02:13 PM
4 comments, last by Fender148 24 years, 5 months ago
I bought Andre LaMothe''s "Tricks of the Windows Game Programming Gurus", and Im on chapter 3 which is about using resources like cursors and icons. Ive been trying to use a cursor and icon in my program but I can''t get it to work for the life of me. I am using Visual C++ 6, and to put in a resource I select insert resource from the insert resource, I select the cursor and icon I want to use which are in the same directory as my project. It loads both fine, the icon is named "IDI_ICON1" and the cursor "IDC_CURSOR1". Now I have a resource file with both the icon and the cursor and it uses my resources.h file which has //resource.h #define IDI_ICON1 100 #define IDC_CURSOR1 200 in my main : winclass.hCursor = LoadCursor(hinstance,MAKEINTRESOURCE(IDC_CURSOR1)); winclass.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_ICON1)); winclass.hIconSm=LoadIcon(hinstance,MAKEINTRESOURCE(IDI_ICON1)); the program will run but the icon and cursor dont appear. Ive read and re-read the chapter but I can''t figure out what Im missing. Any help would be greatly appreciated. Thanks
What''s the MAKEINTRESOURCE for? I use assembler not C. But I believe it should be the same.

try:
winclass.hCursor = LoadCursor(hinstance,IDC_CURSOR1);
winclass.hIcon = LoadIcon(hinstance,IDI_ICON1);
winclass.hIconSm=LoadIcon(hinstance,IDI_ICON1);


Assuming you''ve defined the constants of course!
Good luck!
See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Advertisement
Cyberben: If you were using string constants to name your resources instead of integer IDs like Fender is using, you would just send the string as a parameter to LoadIcon() or LoadCursor(), so it would be something like

winclass.hIcon = LoadIcon(hinstance, "IDI_ICON1");

MAKEINTRESOURCE() is a macro that converts an integer ID to the appropriate data type for LoadIcon() or any other resource-loading function.

Fender: I learned basic Win32 and DirectX not too long ago from the same book, and I had some problems with getting resources to work properly in VC6 as well. For some reason, I never experienced any difficulty using strings instead of constants, so try that once and see what happens. Although if your .rc file is being generated by Visual C++ -- that''s what you said, isn''t it? -- I don''t see why you should be having any problems.

-Ironblayde
Aeon Software
"Your superior intellect is no match for our puny weapons!"
Just asking, did you add the resource file to you project? Since you''re using MSVC 6.0, you''ll have to add it to the resource files folder.

That may solve your problem (if you weren''t linking the resource file with your exe).




========================================================
If something sounds stupid but works, it's not stupid
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Thanks guys, I wrote my rc file as a text file instead of using vc 6 and it works fine now, I cant explain it, but Im happy
Hey, I wonder if anyone read Petzold?
VK

This topic is closed to new replies.

Advertisement