How to get rid of console and set proper app icon

hi friends,
after trying for a while to disable the (ugly) console that pops out on windows I’d like to share what I have found to work. Not the hardest thing in the universe, of course, but it may be useful to someone else.

First of all you need to change visual studio linker setting to instruct it to generate a windows app instead of a console one:

  1. Right click on your app name in solution explorer, then choose Properties > Linker > System > Subsystem
    and set it to “Windows (/SUBSYSTEM:WINDOWS)”

  2. change the int main() entry point to

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

Now your app should start without console but the icon will not be set.

  1. Right click again on app name in solution explorer and choose Add -> Resource -> Icon and click on “import” (you should have a .ico file ready) or on “new” if you want to use the VS embedded icon editor

  2. in your main.cpp add a #include “…/resource.h” and after the ofSetupOpenGL() and before the ofRunApp() call add this code:

    HWND hwnd = ofGetWin32Window();
    HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hMyIcon);

IDI_ICON1 is a numerical value (usually 101) defined in resource.h (byVS, it is wise to leave it as it is)

6 Likes

Hi @davidemania,

thanks for the tip. The console thing work perfectly with Windows 10, Visual Studio 2015 and OF 0.

However the icon part didn’t work. It gave me the following erros:

1>icon.rc(8): error RC2144: PRIMARY LANGUAGE ID not a number
1>
1>
1>icon.rc(18): error RC2135: file not found: 101
1>
1>
1>icon.rc(20): error RC2135: file not found: 102
1>
1>
1>icon.rc(61): error RC2135: file not found: “ICON.ICO”

Do you know what could it be?

The error you are getting is from the step 3 above?

possible error and solution:

  1. error RC2144 : PRIMARY LANGUAGE ID not a number
    Just add “#include <windows.h>” in icon.rc. refer: https://stackoverflow.com/questions/18831761/vs-2008-resource-type-error-while-changing-language

  2. MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol _main referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ)
    Just repeat step 1 above to set “Windows (/SUBSYSTEM:WINDOWS)”. After the project is updated by projectGenerator.exe, project properties will be reset including Linker settings.

1 Like

Thanks @Jerwin_Chan. That worked out!

Adding “#include <windows.h>” in icon.rc worked for me too

Many thanks.
It works with of 0.10

I found that it’s better to add the ressource in the ressource viewer of vs. Right click on icon.rc, …

The include addition (#include <windows.h>) is in the beginning of resource.h , right ?

Cheers