C language > Expert questions

Would like to change default icon in Console Window. Only lead I have is C++ !

<< < (2/3) > >>

EdPellesC99:

   Timo


   Demonstrating my appreciation for your help (by my quick get-back). Here is the project and source files I can contribute to the forum.
A working example project with a custom icon resource.


--- Quote ---
// // ~ •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •


#include <windows.h>
#include <stdio.h>
#include <tchar.h> //using in SetConsoleIcon external function
#include "resource.h"
// // ~  Compiles w/ ZE option
#pragma lib "user32.lib" // needed for LoadIcon in SetConsoleIcon function

// // ~ •  •  •  •  •  •  •  •  •  •  •  •
BOOL WINAPI SetConsoleIcon(HICON hIcon);  //prototype
// // ~ •  •  •  •  •  •  •  •  •  •  •  •


int main(int argc, char **argv)
{
//SetConsoleIcon(LoadIcon(0, IDI_EXCLAMATION));

HMODULE hMainMod = GetModuleHandle( 0 );
SetConsoleIcon(LoadIcon( hMainMod, MAKEINTRESOURCE( EdsIcon1)));
printf("Cool Work Timo. Best Icon loaded !\n\n");
system("pause");
return 0;
}



BOOL WINAPI SetConsoleIcon(HICON hIcon)
{
typedef BOOL (WINAPI *PSetConsoleIcon)(HICON);
static PSetConsoleIcon pSetConsoleIcon = NULL;
if(pSetConsoleIcon == NULL)
pSetConsoleIcon = (PSetConsoleIcon)GetProcAddress(GetModuleHandle(_T("kernel32")), "SetConsoleIcon");
if(pSetConsoleIcon == NULL)
return FALSE;
return pSetConsoleIcon(hIcon);
}

// // ~ •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •  •


--- End quote ---





   Thanks again,

   Ed

Source files attached.

Juni:
Nice Demo ty  :)

( I had to change the icon in the .ppj to Pelle_Orinius.ico )

Vortex:
Here is another version :


--- Code: ---#include <windows.h>

/* Check BuildLib.lib and kernel32.def to build kernel32v2.lib exporting the SetConsoleIcon function */

BOOL WINAPI SetConsoleIcon(HICON hIcon);

int main( int argc, char **argv )
{
HICON hIcon=LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(200));

  MessageBox(0,"Click the message box to change the console icon","Test",MB_OK);
 
    SetConsoleIcon(hIcon);
 
    MessageBox(0,"Console icon changed","Test",MB_OK);

return 0;
}

--- End code ---

EdPellesC99:

  Thanks Vortex,

  I will check it out and get back in a day.

  ....... Ed

dbareis:

--- Quote from: EdPellesC99 on August 17, 2010, 01:08:59 AM ---Demonstrating my appreciation for your help (by my quick get-back). Here is the project and source files I can contribute to the forum.
A working example project with a custom icon resource.

--- End quote ---

I'm trying to get this to work in Visual Studio 2017. The generated EXE runs and says "Cool Work Timo. Best Icon loaded", but doesn't change the console icon.  Is it possible it doesn't work in 64 bit WIN10?


--- Quote ---// // ~  Compiles w/ ZE option

--- End quote ---
I'm new to VS (and very rusty in C), am I supposed to set these options somewhere?


--- Quote ---#pragma lib "user32.lib" // needed for LoadIcon in SetConsoleIcon function

--- End quote ---
This #pragma is unknown

I'm going to keep hammering at it but with any luck someone will take pity and point me to the solution.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version