TechKnow

Author Topic: CodeBlocks C++ HowTo make a shortcut with icon (launcher) tutorial  (Read 1265 times)

0 Members and 1 Guest are viewing this topic.

Offline HcH

  • TechKnow Owner, Ethical Hacker
  • Administrator
  • Uber Member
  • *****
  • Posts: 9946
  • Karma: +2285/-111
Hey TechKnow members and visitors!

so I've been asked to perform a simple task:

* create a .exe file, no .bat or .lnk file is allowed
* it must contain a icon
* it must launch a website using Internet Explorer

I fired up Code::Blocks 13.12 and started:

main.cpp

//#include <iostream>
#include <stdio.h>      /* printf */
#include <stdlib.h>     /* system, NULL, EXIT_FAILURE */

using namespace std;

int main()
{
    printf("\nStarting application!\n\n");
    system ("\"\"%programfiles%\\internet explorer\\iexplore.exe\"\" www.mywebsite.com");
    return 0;
}

Easy enough! If you would like to learn more about this simple example please learn the basics. Not to be rude or funny or anything, you really learn better if you start from 0.

OK, so the code is done, but how do you link a resource file / icon for that code?

1. In "management" , click the "projects" tab (if required and not focussed already)
2. Click "File", "New", "Empty file"
3. Type in the name for this New Empty File: resources.rc. A new file will be added to your project and will be put under \Projects\Resources!
4. Paste something like this:

#ifndef RESOURCE_RC_INCLUDED
#define RESOURCE_RC_INCLUDED

MAINICON  ICON  "ico.ico"

#endif // RESOURCE_RC_INCLUDED

5. Now, add your icon file (ico.ico in this example), it will appear under "Others" in your project browser
6. Compile and enjoy!

NOTES:
- Even though this seems simple enough, as some pro's can see, I exclude a certain lib to gain a smaller compiled executable filesize and work around cout by using printf.
- It was surprisingly difficult to add a ico, at first I created my own empty file in windows and have added that as resource file, though Code::Blocks does recognize this file as being a resources file, it is not used as one!!! This will cause "MYICON does not name a type" errors.


Enjoy this fine and easy tutorial!

Remember to donate once in a while to support me and the rest of the team so we can keep bringing you TechKnow!!!

Cheers,

HcH
« Last Edit: October 11, 2016, 04:38:56 PM by HardcoreHacker »