Skip to content

Commit

Permalink
Set app icons on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSapps committed Jul 1, 2015
1 parent 2a1bdaf commit ced9b8f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,23 @@ git_shorttag(GIT_SHORT_REV)
set(ALIVE_VERSION "ALIVE v${ALIVE_VERSION_MAJOR}.${ALIVE_VERSION_MINOR}.${ALIVE_VERSION_PATCH} rev(${GIT_SHORT_REV})")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/packaging/alive_version.h.in ${CMAKE_CURRENT_BINARY_DIR}/packaging/alive_version.h)

if(WIN32)
SET(WIN32_ONLY_SRC
rsc/Resource.rc
rsc/resource.h
rsc/app.ico)
endif()

add_executable(Alive MACOSX_BUNDLE
${WIN32_ONLY_SRC}
include/core/audiobuffer.hpp
src/core/audiobuffer.cpp
src/main.cpp
)

set(CPACK_PACKAGE_EXECUTABLES Alive "A.L.I.V.E")
set(CPACK_WIX_PROGRAM_MENU_FOLDER "Alive")

set(CPACK_PACKAGE_VENDOR "PaulsApps.com")

#cotire(Alive)
TARGET_LINK_LIBRARIES(Alive jsonxx imgui oddlib ${OPENGL_LIBRARIES} ${SDL2_LIBRARY} liblua)
Expand Down
Binary file added rsc/Resource.rc
Binary file not shown.
Binary file added rsc/app.ico
Binary file not shown.
Binary file added rsc/resource.h
Binary file not shown.
42 changes: 42 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,41 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c
SDL_Renderer* ren = nullptr;
SDL_Texture *sdlTexture = nullptr;


#if defined(_WIN32) && defined(GCL_HICON)
#include <windows.h>
#include "../rsc/resource.h"
#include "SDL_syswm.h"
#include <functional>

void setWindowsIcon(SDL_Window *sdlWindow)
{
HINSTANCE handle = ::GetModuleHandle(nullptr);
HICON icon = ::LoadIcon(handle, MAKEINTRESOURCE(IDI_MAIN_ICON));
if (icon != nullptr)
{
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
if (SDL_GetWindowWMInfo(sdlWindow, &wminfo) == 1)
{
HWND hwnd = wminfo.info.win.window;
::SetClassLong(hwnd, GCL_HICON, reinterpret_cast<LONG>(icon));
}

HMODULE hKernel32 = ::GetModuleHandle("Kernel32.dll");
if (hKernel32)
{
typedef BOOL(WINAPI *pSetConsoleIcon)(HICON icon);
pSetConsoleIcon setConsoleIcon = (pSetConsoleIcon)::GetProcAddress(hKernel32, "SetConsoleIcon");
if (setConsoleIcon)
{
setConsoleIcon(icon);
}
}
}
}
#endif

void InitGL()
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
Expand All @@ -129,6 +164,12 @@ void InitGL()
window = SDL_CreateWindow(ALIVE_VERSION_NAME_STR,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720,
SDL_WINDOW_OPENGL);

#if defined(_WIN32)
// I'd like my icon back thanks
setWindowsIcon(window);
#endif

context = SDL_GL_CreateContext(window);
ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (ren == nullptr)
Expand Down Expand Up @@ -223,6 +264,7 @@ void UpdateImGui()
// Start the frame
ImGui::NewFrame();
}

// Application code
int main(int argc, char** argv)
{
Expand Down

0 comments on commit ced9b8f

Please sign in to comment.