Ivan
Ivan

Reputation: 31

Windows C++ GUI application

I am currently working on porting my C++ Qt5/CMake application from linux to windows. When start application in linux, i see UI and all ok. On windows first start black terminal and from terminal start my application. How start application without black console? It is not beautiful.

I am using MSVC cmake generator and visual studio 2013 express.

Thank you all!

Upvotes: 2

Views: 3168

Answers (1)

e.proydakov
e.proydakov

Reputation: 602

Edit CMakeLists.txt for create WIN32 application

IF(MSVC)
    SET(OPTIONS WIN32)
ENDIF(MSVC)

ADD_EXECUTABLE(${APP_NAME} ${OPTIONS}
    ${HEADER_FILES}
    ${SOURCE_FILES}
    }

Edit main.cpp for using wWinMain and convert input args to argc, argv

#ifdef _MSC_VER
#   include <windows.h>
#   include <shellapi.h>
#endif

/// ... some code

#ifdef _MSC_VER
INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPWSTR, INT)
{
    UNREFERENCED_PARAMETER(hInst);
    UNREFERENCED_PARAMETER(hPrevInstance);

    int argc;
    char** argv;
    {
        LPWSTR* lpArgv = CommandLineToArgvW( GetCommandLineW(), &argc );
        argv = (char**) malloc( argc*sizeof(char*) );
        int size, i = 0;
        for( ; i < argc; ++i )
        {
            size = wcslen( lpArgv[i] ) + 1;
            argv[i] = (char*) malloc( size );
            wcstombs( argv[i], lpArgv[i], size );
        }
        LocalFree( lpArgv );
    }

#else
int main(int argc, char *argv[])
{
#endif

    QGuiApplication a(argc, argv);

    /// ... some code

    int code = a.exec();

#ifdef _MSC_VER
    {
        int i = 0;
        for( ; i < argc; ++i ) {
            free( argv[i] );
        }
        free( argv );
    }
#endif

    return code;
}

Upvotes: 4

Related Questions