Getting a .exe icon On Window, NO EXTERNAL FILES!
BlitzMax Forums/BlitzMax Tutorials/Getting a .exe icon On Window, NO EXTERNAL FILES!
| ||
=====>>> THIS IS FOR WINDOWS <<<===== I asked how to do this, and a few people helped out and this is their Idea's/help mixed together in a working method. this small tutorial will show you how to get a .exe icon for your exe file and on the window WITHOUT using external files with the finished product. Step 1---------------------------------- make a folder: "IconMaker" i like to keep this near my project folders, so i can easely grab the produced .o file and drop it in the project folder. Step 2---------------------------------- now get these 3 files in this "IconMaker" folder: 1: "icon.ico" ;your icon (32x32 .ico) this will be the icon on the exe file. 2: "resfile.rc" ; create this with notepad with the following line: 101 ICON icon.ico 3: "windres.exe" ; from your MinGW/bin Step 3----------------------------------- Now, open notepad and add the following line: windres -i resfile.rc -o icon_import.o save this as build.bat in the same "IconMaker" folder Step 4----------------------------------- Now simply double click the .bat file to produce your icon .o file. this was hard to set up, but now making a new icon res file is as easy as dropping a new icon into that folder, and deleting the other one, then re double clicking the .bat file. Step 5------------------------------------ Now to get it on the window call the following function right after Graphics. ' ----------------------------------------------------------------------------- ' SetIcon ' ----------------------------------------------------------------------------- Function SetIcon(iconname$, TheWindow%) ?Win32 Local icon=ExtractIconA(TheWindow,iconname,0) Local WM_SETICON = $80 Local ICON_SMALL = 0 Local ICON_BIG = 1 sendmessage(TheWindow, WM_SETICON, ICON_BIG, icon) ? End Function 'call it like this SetIcon(AppFile, GetActiveWindow()) you'll also need the following win32 externs: 'Needed externs ?win32 Extern "win32" Function ExtractIconA%(hWnd%,File$z,Index%) Function GetActiveWindow%() Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16" End Extern ? (Credits to grey alien for that function, this will extract the icon out of your exe file and display it on the window.) now the result is a completely independant compiled exe that needs no external files to display its icon. heres an example: Import "icon_import.o" 'Needed externs ?win32 Extern "win32" Function ExtractIconA%(hWnd%,File$z,Index%) Function GetActiveWindow%() Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16" End Extern ? Graphics 800,600 SetIcon(AppFile,GetActiveWindow()) While Not AppTerminate() = True Cls Flip Wend End Function SetIcon(iconname$, TheWindow%) ?Win32 Local icon=ExtractIconA(TheWindow,iconname,0) Local WM_SETICON = $80 Local ICON_SMALL = 0 Local ICON_BIG = 1 sendmessage(TheWindow, WM_SETICON, ICON_BIG, icon) ? End Function |
| ||
I've not tried this method yet.. but i did try Grey Aliens method. The problem that I have is that it displays the icon in runtime only. But not when your exe is sitting on the desktop or any shortcuts to your exe. Whats the method for ataching the icon to the exe so that Windows sees it? (I've tried the old skool resource hacker method with no luck) cheers |
| ||
The problem that I have is that it displays the icon in runtime only. But not when your exe is sitting on the desktop or any shortcuts to your exe. Linking to the compiled resource object with the icon should do it, at least it works for me. |
| ||
i'm going to play dumb here... ;-) Linking to the compiled resource object with the icon should do it, at least it works for me. what? is that part of the above steps? |
| ||
Its in step 2 to 4 |
| ||
nice one... all sorted now. cheers |
| ||
For me I just have to double click the bat file and it works dine. |
| ||
How do I do this with a non windowed application that doesn't use maxgui |
| ||
this is for a std. blitzmax window. not sure how it works on maxgui. |
| ||
Hi, I have used ?Win32 Import "etchicon_import.o" ? with successs. The above given code also does the same. But I still am not able to change the Icon which appears in the left top of the application window. Regards, Ramesh |
| ||
Hey, maybe a bit late for responce, but... Importing the object file embedds the icon into the compiled exe file... to place it on the window, you do step 5.. a function that calls out that embedded icon and places on the window. Mind you, you need some windows external functions... external win32 functions: 'Needed externs ?win32 Extern "win32" Function ExtractIconA%(hWnd%,File$z,Index%) Function GetActiveWindow%() Function SendMessage:Int(hWnd:Int,MSG:Int,wParam:Int,lParam:Int) = "SendMessageA@16" End Extern ? function that calls out the exe icon and places it on the window. ' ----------------------------------------------------------------------------- ' SetIcon ' ----------------------------------------------------------------------------- Function SetIcon(iconname$, TheWindow%) ?Win32 Local icon=ExtractIconA(TheWindow,iconname,0) Local WM_SETICON = $80 Local ICON_SMALL = 0 Local ICON_BIG = 1 sendmessage(TheWindow, WM_SETICON, ICON_BIG, icon) ? End Function 'call it like this SetIcon(AppFile, GetActiveWindow()) |
| ||
Is there a way to use the smaller icon? (The .iso had a 16x16 and a 32x32) Even if I replaced ICON_BIG (1) to ICON_SMALL (0), the icon still shows the 32x32 one squished to 16x16. |
| ||
I don't know why you guys are going to such lengths. I just use a downloaded program that looks inside the .exe, allows you to select any icon replace rebuild exactly the same executable but with a jazzy icon. |
| ||
Because this method sets the window icon, exe icon, icon when you alt-tab, task bar icon - everything. Plus i only have to do this once, not every time I build a new exe. Last edited 2012 |
| ||
I don't know why you guys are going to such lengths. I just use a downloaded program that looks inside the .exe, allows you to select any icon replace rebuild exactly the same executable but with a jazzy icon. There is a right way to do things and a half-assed way to do things. |
| ||
Ah ok. I just find it the easiest route. I used to use Dark Basic and you couldn't change the internal icons for love nor money. If you did it wouldn't run. Anyone own a copy of the Grey Alien Framework? I'll give anyone £70 for it. Their licence that is. Not a copy. |
| ||
Anyone own a copy of the Grey Alien Framework? I'll give anyone £70 for it. Their licence that is. Not a copy. I hate to derail this thread (there's no email on Vin78's profile) but I did this after I missed out on Greys... http://www.blitzbasic.com/Community/posts.php?topic=92656#1057028 and there are others. Please post elsewhere for any further info. /derailment |
| ||
Ah that's great. Unfortunately I can't get it working. I have emailed you. I will have to post in the appropriate places in future :O! Thanks Mati |
| ||
Does anyone know how to do this (with Resource Hacker) for Biltz Basic? Also, is this possible to do with JUST a program like Resource Hacker, and not have to write extra code in your program to set the icon? I'm just wondering here because so far I have gotten ZERO CLEAR ANSWERS. So all real help for me is greatly appreciated! |
| ||
Code modified for working in SuperStrict mode, and for multi-platform compilation.' ----------------------------------------------------------------------------- ' SetIcon ' ----------------------------------------------------------------------------- Function SetIcon(iconname$, TheWindow%) ?Win32 Local icon:Int=ExtractIconA(TheWindow,iconname,0) Local WM_SETICON:Int = $80 Local ICON_SMALL:Int = 0 Local ICON_BIG:Int = 1 sendmessage(TheWindow, WM_SETICON, ICON_BIG, icon) ? End Function 'call it like this ?Win32 SetIcon(AppFile, GetActiveWindow()) ? Everything else is the same as before. Because the call to SetIcon used a Win32 dependent function, it really should have been enclosed in the ?Win32 / ?. |