Console Project Icon

  • Thread starter Thread starter Steve N.
  • Start date Start date
How do I set the icon of the .exe file created by a Win32 Console project?

Steve,

Try something like this:

#include "stdafx.h"
#include <windows.h>
#include "resource.h"
#include <conio.h>

int main(int argc, char* argv[])
{
HWND hFocus = GetForegroundWindow();

if ( hFocus != NULL )
{
HICON ico = LoadIcon( GetModuleHandle( NULL ),
MAKEINTRESOURCE( IDI_ICON1 ) );

if ( ico != NULL )
{
SendMessage( hFocus, WM_SETICON,
ICON_BIG, (LPARAM) ico );
SendMessage( hFocus, WM_SETICON,
ICON_SMALL, (LPARAM) ico );
}
}

printf("Hello World!\n");
char ch = getch();
printf("Goodbye cruel world\n" );
return 0;
}

Dave
 
Back
Top