View previous topic :: View next topic |
Author |
Message |
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Fri Jul 16, 2004 9:50 pm Post subject: help: resource files |
|
|
First, I've never worked with resource files before.
My case is this: I took winsamp.d from the samples dir, and added these lines taken from Y Tomino's win32lib:
Code: | alias uint ULONG_PTR;
LPSTR MAKEINTRESOURCEA(WORD i){ return cast(LPSTR)(cast(ULONG_PTR)(cast(WORD)(i))); }
LPWSTR MAKEINTRESOURCEW(WORD i){ return cast(LPWSTR)(cast(ULONG_PTR)(cast(WORD)(i))); }
alias MAKEINTRESOURCEW MAKEINTRESOURCE;
extern(Windows) HICON LoadIconA(
HINSTANCE hInstance,
LPCSTR lpIconName);
extern(Windows) export HICON LoadIconW(
HINSTANCE hInstance,
LPCWSTR lpIconName);
alias LoadIconW LoadIcon;
|
I also changed this line in function doIt():
Code: | wc.hIcon = LoadIcon(null,MAKEINTRESOURCE(101)); |
Then I created a sample resource file, only containing this:
Code: | 101 ICON DISCARDABLE "d.ico" |
Where d.ico is some icon someone posted once. I compiled the resource file, using DM's rcc, like this:
Code: | rcc winsamp.rc -owinsamp.res -32 |
Then I compiled everything together like this:
Code: | dmd winsamp.d gdi32.lib winsamp.res -L/exet:nt/su:windows:4 |
Great! Now I know how to put icons in my exes! Also, the window now doesn't have that ugly default app icon, but instead it has the alert icon instead of the icon I told it!! (the alert icon is the yellow triangle with the exclamation mark, just in case).
I'm sure you've all guessed what's next... what am I doing wrong? |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sat Jul 17, 2004 12:10 am Post subject: |
|
|
When using one of the Load* functions to bring in an app-specific resource, you need to pass in the app's instance handle as the first argument. Passing NULL tells Windows to use a system icon (and in this case you are getting the warning icon). So try something like:
LoadIcon(GetModuleHandle(null), MAKEINTRESOURCE(101));
Alternatively, use the instance handle passed to WinMain. |
|
Back to top |
|
|
Carlos
Joined: 19 Mar 2004 Posts: 396 Location: Canyon, TX
|
Posted: Sat Jul 17, 2004 6:14 pm Post subject: |
|
|
That indeed worked! Thanks!! |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|