Console Project Icon

S

Steve N.

Hi,

How do I set the icon of the .exe file created by a Win32 Console project?

Thanks.
 
D

David Lowndes

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top